我使用的 API dosnt 响应 Form_Load 事件。所以我想用按钮中包含的代码填充 CheckedListBox1,我用来调用包含 CheckedlistBox1 的对话框。这是我的第一次尝试。
private void button3_Click(object sender, EventArgs e)
{
TextSelectorForm textSelectionForm = new TextSelectorForm();
CheckedListBox checkedListBox1;
string line;
StreamReader file = new StreamReader("test.txt");
while ((line = file.ReadLine()) != null)
{
TextSelectorForm.checkedListBox1.Items.Add(line);
}
file.Close();
textSelectionForm.Show();
}
想法,想法,例子?谢谢!
我收到错误“对象引用未设置为对象的实例”。我正在学习,慢慢来。这是我的代码。
public partial class Form1 : System.Windows.Forms.Form
{
public Form1(ExternalCommandData commandData)
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
CheckedListBox.ObjectCollection data = null;
string line;
StreamReader file = new StreamReader(@"C:\test.txt");
while ((line = file.ReadLine()) != null)
{
data.Add(line);
}
file.Close();
Form2 form2 = new Form2(data);
form2.Show();
}
}
public partial class Form2 : System.Windows.Forms.Form
{
public Form2(CheckedListBox.ObjectCollection formdata)
{
InitializeComponent();
if (formdata != null)
{
this.checkedListBox1.Items.AddRange(formdata);
}
}
}
(PS。如果我想补充我的问题怎么办?)