如何以编程方式添加面板? [英] How to programmatically add panels?

查看:116
本文介绍了如何以编程方式添加面板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何在运行时在Winform上添加面板,但是如果在运行时确定要添加的面板数,如何在运行时访问每个面板的Paint方法? ="h2_lin">解决方案

您还可以以编程方式添加事件挂钩.您可以编写事件处理程序,因此在这种情况下,外壳程序是

 私有 无效 panel_Paint(对象发​​件人,PaintEventArgs e)
{

} 



然后,每当您向表单添加一个新面板时,便向该面板添加一个事件处理程序,如下所示:

面板newPanel =  Panel();

// 设置面板位置和其他属性

// 添加事件处理程序
newPanel.Paint + =  PaintEventHandler( this  .panel_Paint);

// 将其添加到表单
 .Controls.Add(newPanel); 



然后,每当您绘制新面板时,它将转到您的处理程序.
此处有一个示例 [ 解决方案

You can also programmatically add event hooks. You can write your event handler, so in this case the shell is

private void panel_Paint(object sender, PaintEventArgs e)
{

}



Then, whenever you add a new panel to the form, you add an event handler to that panel like so:

Panel newPanel = new Panel();

//set panel position and other properties

//Add the event handler
newPanel.Paint += new PaintEventHandler(this.panel_Paint);

//Add it to the form
this.Controls.Add(newPanel);



Then, whenever your new panel is painted, it will go to your handler.
There''s an example
here[^]


这篇关于如何以编程方式添加面板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发语言最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆