多自定义用户空间之间事件如何响应?

leebuilder 2008-05-19 08:48:01
我定义了多个用户控件,在住程序中动态加载,想要实现的状态:通过一个菜单用户控件调用另一个用户控件,使其显示在主窗体程序中。
该怎么做呀?

解决立即给分
...全文
57 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
leebuilder 2008-05-20
  • 打赏
  • 举报
回复
测试通过,结贴
virusswb 2008-05-19
  • 打赏
  • 举报
回复
System.Windows.Forms.Button aButton = new System.Windows.Forms.Button(); //为Button类建立新的实例
this.Dictionary.Add(name, aButton);//将该按钮添加到按钮集合
HostForm.Controls.Add(aButton);//把控件集合中的按钮添加到被HostForm字段引用的面板
//设置该按钮对象的初始属性
aButton.Top = 13;
aButton.Left = 100 * (number-1)+15;
aButton.Size = new Size(80, 40);
aButton.Name = name;
aButton.Tag = number;
aButton.Text = AllActions[number-1];
aButton.Click += new System.EventHandler(ClickHandler);
return aButton;
new一个控件出来,然后定位就可以了
hsoft2006 2008-05-19
  • 打赏
  • 举报
回复
可以直接在菜单控件中设置另一个控件的Visible属性,或者
可以写一个控件管理类,定义添加和删除按钮这两个方法,对类初始化时向它传递要显示按钮的窗口的引用即可,大概如下:

public class ButtonArray
: System.Collections.DictionaryBase
{
private readonly System.Windows.Forms HostForm;
public ButtonArray(System.Windows.Forms host)
{
HostForm = host;
}
public System.Windows.Forms.Button AddNewButton(int number, string name)
{
System.Windows.Forms.Button aButton = new System.Windows.Forms.Button(); //为Button类建立新的实例
this.Dictionary.Add(name, aButton);//将该按钮添加到按钮集合
HostForm.Controls.Add(aButton);//把控件集合中的按钮添加到被HostForm字段引用的面板
//设置该按钮对象的初始属性
aButton.Top = 13;
aButton.Left = 100 * (number-1)+15;
aButton.Size = new Size(80, 40);
aButton.Name = name;
aButton.Tag = number;
aButton.Text = AllActions[number-1];
aButton.Click += new System.EventHandler(ClickHandler);
return aButton;
}
/// <summary>
/// 通过按钮的名字进行删除
/// </summary>
/// <param name="name"></param>
public void Remove(string name)
{
if (this.Count > 0)//检查以确保有按钮可以删除
{
HostForm.Controls.RemoveByKey(name);// 从面板的控件集合中删除对应名字的按钮
this.Dictionary.Remove(name);
}
}
}

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧