C#中动态创建控件及事件处理程序
来源:互联网 发布:风云武功排名 知乎 编辑:程序博客网 时间:2024/05/16 13:44
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Miner
{
/// <summary>
/// Summary des cription for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Panel panel1;
/// <summary>
/// Required designer variable.
/// </summary>
///
private Button[] n =new Button[100];
private int[] kn=new int[100];
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// panel1
//
this.panel1.Location = new System.Drawing.Point(8, 8);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(400, 400);
this.panel1.TabIndex = 0;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(416, 413);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.panel1});
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
int a=0;
int x=0,y=0;
for (a=0;a<=99;a++)
{
n[a] = new Button();
n[a].BackColor =Color.White;
n[a].FlatStyle = FlatStyle.Flat;
n[a].Width = panel1.Width / 10;
n[a].Left = x * n[a].Width;
n[a].Height = panel1.Height / 10;
n[a].Top = y * n[a].Height;
n[a].Name = "b" + a;
panel1.Controls.Add(n[a]);
panel1.Controls[a].MouseDown += new MouseEventHandler(this.ButtonArray_OnClick);
x += 1;
if (x == 10)
{
x = 0;
y += 1;
}
}
}
private void ButtonArray_OnClick(object sender, MouseEventArgs e)
{
MouseEventArgs arg=(MouseEventArgs)e;
Button b1=(Button)sender;
if (arg.Button==MouseButtons.Right )
b1.BackColor=Color.White ;
else
{
//b1.BackColor =Color.White ;
b1.Image=Image.FromFile(@"C:/Documents and Settings/Administrator/桌面/我.jpg");
}
}
}
}
- C#中动态创建控件及事件处理程序
- C#中动态创建控件及事件处理程序
- C#中动态创建控件及事件处理程序
- C#中动态创建控件及事件处理程序、置于顶层
- 在C# WinForm程序中创建控件数组及相应的事件处理
- 动态创建控件及控件的事件处理
- c#自定义控件中事件的处理
- C# WinForm 控件在窗体中动态居中 创建、删除控件及对其赋值
- c# TableLayoutPanel控件应用 动态添加控件及事件
- c# TableLayoutPanel控件应用 动态添加控件及事件
- C#动态创建窗口和创建事件,在新窗口添加控件和控件事件
- Android 动态创建Android控件、绑定事件处理的新方法
- IOS动态创建控件通过tag处理单击事件
- C#中共享事件处理程序
- 在C#程序中创建控件数组
- C# 动态创建控件
- c#动态创建控件...
- asp.net C#动态添加创建生成button按钮控件没有触发执行响应click绑定事件处理
- 如何获取当前程序文件的路径 Current Path
- 不确定性算法在C++中的表达:一个简化模型
- 自己写一个strcpy(char*dest,char*src),如何在函数内部实现防御性溢出?
- 星星帮忙:2个sql(1)、(2)为何不能等价?
- 后台动态设置前台标签内容和属性
- C#中动态创建控件及事件处理程序
- ASP.NET中的TabStrip
- 父亲
- 用Photoshop两步制作Google Logo
- ASP.NET中的数据绑定:哪个更快
- ASP.NET中给上传图像加水印(版权信息)
- 用python写的一个对象池类
- 人际关系的55个绝招
- 关于C#中timer类