111,128
社区成员
发帖
与我相关
我的任务
分享
namespace WindowsFormsApplication6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
List<string> a = new List<string>() { "1", "2", "3" };
private void codeAll1_userComboboxList(object sender, EventArgs e)
{
//??????????????????????????????????????
}
}
}
namespace MyControl
{
public partial class codeAll : UserControl
{
public codeAll()
{
InitializeComponent();
}
public delegate void comboboxListHandle(object sender, EventArgs e); //定义委托
public event comboboxListHandle userComboboxList; //定义事件
private void codeAll_Load(object sender, EventArgs e)
{
//userComboboxList(this, new eventArgsParameter(m));
//??????????????????????????????????????????????????
}
public void aaa(ComboBoxEdit a, List<string> b)
{
a.Properties.Items.Clear();
for (int i = 0; i < b.Count; i++)
{
a.Properties.Items.Add(b[i]);
}
}
}
public class eventArgsParameter : EventArgs
{
public eventArgsParameter(List<string> b)
{
a = b;
}
private List<string> a;
public List<string> parameter
{
set { a = value; }
}
}
}
codeAll code = new codeAll();// 模拟窗体上的自定义控件
List<string> a = new List<string>() { "1", "2", "3" };
private void Form1_Load(object sender, EventArgs e)
{
// 直接在Form的Load事件里面做这个方法的调用即可。因为这个方法的public
code.aaa(a);
}
public partial class codeAll : UserControl
{
// 模拟自定义控件上的ComboBoxEdit控件,你们也是用Dev,哈
ComboBoxEdit a = new ComboBoxEdit();
public void aaa(List<string> b)
{
a.Properties.Items.Clear();
for (int i = 0; i < b.Count; i++)
{
a.Properties.Items.Add(b[i]);
}
}
}List<string> a = new List<string>() { "1", "2", "3" };
private void codeAll1_userComboboxList(object sender, eventArgsParameter e)
{
e.parameter = a;
}
自定义控件代码
public partial class codeAll : UserControl
{
public delegate void comboboxListHandle(object sender, eventArgsParameter e); //定义委托
public event comboboxListHandle userComboboxList; //定义事件
private void codeAll_Load(object sender, EventArgs e)
{
if (userComboboxList != null)
{
var args = new eventArgsParameter();
userComboboxList(this, args);
aaa(a, args.parameter);
}
}
public void aaa(ComboBoxEdit a, List<string> b)
{
a.Properties.Items.Clear();
for (int i = 0; i < b.Count; i++)
{
a.Properties.Items.Add(b[i]);
}
}
}
public class eventArgsParameter : EventArgs
{
public eventArgsParameter()
{
a = new List<string>();
}
private List<string> a;
public List<string> parameter
{
get { return a; }
set { a = value; }
}
}
感谢,不介意的话,还真的是以后想多麻烦你一下。现在就有个小问题再请教一下,是上午这个问题的延伸:
我在窗体上有个panel,根据不同的条件panel加载不同的自定义控件:
当我加载上午生成的这个自定义控件时候,无法传值进去到自定义控件。我想是不是自定义控件中不应该写在load中?那应该卸载哪里比较合适?[/quote]呵呵,不好意思,我知道哪里错了。
感谢,不介意的话,还真的是以后想多麻烦你一下。现在就有个小问题再请教一下,是上午这个问题的延伸:
我在窗体上有个panel,根据不同的条件panel加载不同的自定义控件:
当我加载上午生成的这个自定义控件时候,无法传值进去到自定义控件。我想是不是自定义控件中不应该写在load中?那应该卸载哪里比较合适?