虚心请教! 这样吧:在form类中定义:public static ListBox listBox; listBox = new ListBox();......在A中:Form。listBox。Item。Add("看到我了吗?"); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 lbywyj(沙漠上建筑)你写面向过程的代码呢?你用的是C?如果在其他地方用From 也还是那个样子?//in form1protected ListBox listBox;//添加字符串public AddListData(string sNew){ this.listBox.Add(sNew);}//添加ListItempublic AddListData(ListItem item){ this.listBox.Add(item);}public class A{ public bool InitData(Form1 form) { SqlDataReader read = DbFactory.GetDb().Query("SELECT * FROM MyTable"); if(read == null) return false; while(read.Read()) { form.AddListData(read.GetString(0)); } read.Close();}} to:gujianxin(木头象) 如果有多处用到:form中的listBox的话,我会把listBox作为参数传递给相应的类的,难道我上面的代码有错吗?而对于你的代码:拿到你每次都会把你的Form都作为参数传递吗? 你不觉的开销太大了吧?? C# 如何通过Timer让一个函数执行一分钟? SQL 关于checkBox 事件怎么不刷新dropdownlist的值 textbox内文字长度增加如何向左改变宽度! 请问下findControl方法的使用 编译文件出错?????? 请问如何将DataView中的内容清空? C# private修饰符的问题,求助 求 js xml调用 存储过程 的思路。。。。。。。。。。。。。。10分 ★★★求助高手关于DataView的RowFilter的过滤问题!!★★★ 监听问题,不难,大家近来说说 网络编程的困惑??
你写面向过程的代码呢?你用的是C?如果在其他地方用From 也还是那个样子?//in form1
protected ListBox listBox;
//添加字符串
public AddListData(string sNew)
{
this.listBox.Add(sNew);
}
//添加ListItem
public AddListData(ListItem item)
{
this.listBox.Add(item);
}
public class A
{
public bool InitData(Form1 form)
{
SqlDataReader read = DbFactory.GetDb().Query("SELECT * FROM MyTable");
if(read == null)
return false;
while(read.Read())
{
form.AddListData(read.GetString(0));
} read.Close();
}
}
如果有多处用到:form中的listBox的话,我会把listBox作为参数传递给相应的类的,
难道我上面的代码有错吗?
而对于你的代码:拿到你每次都会把你的Form都作为参数传递吗? 你不觉的开销太大了吧?
?