int counter; CheckBox [] _cbs;Как добавить checkbox рядом с каждой строкой?
ScrollLabel._lines содержит 151l ines. counter is int
Я хочу, чтобы в строке 0, а затем каждые 3 строки добавили флажок в начале строки с одним пространством вправо, чтобы между текстом в строке и CheckBox.
Теперь им получать исключение в петлю на линии:
private void button1_Click(object sender, EventArgs e)
{
if (this.button1.Text == "stop")
{
this.button1.Text = "start";
this.scrollLabel1.StopTimer();
for (int i = 0; i < ScrollLabel._lines.Length; i++)
{
counter += 3;
_cbs[i] = new CheckBox();
_cbs[i].Location = new Point(0, counter);
this.scrollLabel1.Controls.Add(_cbs[i]);
}
}
else
{
this.button1.Text = "stop";
this.scrollLabel1.MilliSecsSpeed = (int)this.numericUpDown1.Value;
this.scrollLabel1.StartTimer();
}
}
_cbs[i] = new CheckBox();
_cbs равна нулю.
Это конструктор:
counter = 0;
this.scrollLabel1.MouseWheel += new MouseEventHandler(ScrollLabel1_MouseWheel);
this.scrollLabel1.MouseEnter += ScrollLabel1_MouseEnter;
readableRss = RssReader.covertRss("http://rotter.net/rss/rotternews.xml");
RssReader.CnnRss();
this.DoubleBuffered = true;
this.scrollLabel1.Text = readableRss;//File.ReadAllText(@"Demo.txt");
this.scrollLabel1.MilliSecsSpeed = (int)this.numericUpDown1.Value;
this.scrollLabel1.YStep = (float)this.numericUpDown2.Value;
this.scrollLabel1.Words = new List<WordColor>();
this.scrollLabel1.Words.Add(new WordColor() { WordOrText = "scrollLabel1", ForeColor = Color.Red, ColorOnlyThisWord = true, BackColor = Color.LightBlue });
this.scrollLabel1.Words.Add(new WordColor() { WordOrText = "using", ForeColor = Color.Blue, DrawRect = true, RectColor = Color.Black, BackColor = Color.Wheat });
this.scrollLabel1.PopLinesOnNonBmpMode = this.checkBox6.Checked;
this.scrollLabel1.BitmapModus = this.checkBox4.Checked;
this.scrollLabel1.TextLayoutCentered = this.checkBox5.Checked;
this.scrollLabel1.AdditionalLinesAtEnd = (int)this.numericUpDown3.Value;
for (int i = 0; i < ScrollLabel._lines.Length; i++)
{
_cbs = new CheckBox[i];
}
Это, как петля на кнопку мыши выглядеть как сейчас:
for (int i = 0; i < ScrollLabel._lines.Length; i++)
{
counter += 3;
_cbs[i].Location = new Point(0, counter);
this.scrollLabel1.Controls.Add(_cbs[i]);
}
Но все _cbs равны нулю внутри.
EDIT **
for (int i = 0; i < ScrollLabel._lines.Length; i++)
{
_cbs[i] = new CheckBox();
counter += 3;
_cbs[i].Location = new Point(0, counter);
this.scrollLabel1.Controls.Add(_cbs[i]);
}
Не получаю нулевой, но я не вижу CheckBox возле/в начале каждого 3-х линий почему?
Где вы инициализируете 'CheckBox [] _cbs'? –
Тим я добавил теперь к моему вопросу код конструктора, в конце я добавил цикл, который инициализирует флажки. Но я вижу только 150 флажков и _lines есть 151. – user3200169
Обновлен мой вопрос после инициализации флажков в конструкторе im, который получает null в коде цикла щелчка кнопки на _cbs [i] .Location = new Point (0, counter); я вижу внутри _cbs 150 индексов, все они равны нулю. – user3200169