| 首页 | 技术文章 | 软件下载 | 博客 | 论坛 | 精品教程 | 黑客动画 | 视频资源 | 在线服务 | 黑客游戏 | 

您现在的位置: 中国X黑客小组 >> 技术文章 >> 编程技术 >> 程序设计 >> 文章正文 用户登录 新用户注册
  C#中动态创建控件及事件处理程序          【字体:
C#中动态创建控件及事件处理程序
作者:不详    文章来源:CnXHacker.Net    点击数:    更新时间:2007-4-25    
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Miner
{
/// 
/// Summary des cription for Form1.
/// 
public class Form1 : System.Windows.Forms.Form
{
 private System.Windows.Forms.Panel panel1;
 /// 
 /// Required designer variable.
 /// 
 /// 

 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
  //
 }

 /// 
 /// Clean up any resources being used.
 /// 
 protected override void Dispose( bool disposing )
 {
  if( disposing )
  {
  if (components != null) 
  {
   components.Dispose();
  }
  }
  base.Dispose( disposing );
 }

 #region Windows Form Designer generated code
 /// 
 /// Required method for Designer support - do not modify
 /// the contents of this method with the code editor.
 /// 
 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

 /// 
 /// The main entry point for the application.
 /// 
 [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("f:\\my documents\\my pictures\\elements\\regular_smile.gif");
  }
  
 }
}
}  

文章录入:IceRiver    责任编辑:IceRiver 
  • 上一篇文章:

  • 下一篇文章:
  • 发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    最新热点 最新推荐 相关文章
    利用C#设计制作端口扫描器
    Visual C# 诠释常用排序算法
    用C#和ADO.NET建立一个数据绑
    利用C#设计端口扫描器
    用VC#2005解析含有多种格式的
    Visual C#.Net 网络程序开发
    C#实现WEB服务器
    雅虎公司C#笔试题,看看你能
    一个C#写的防SQL注射脚本
    C#实现Web文件上传的两种方法
      网友评论:(只显示最新5条。评论内容只代表网友观点,与本站立场无关!)
    Powered by ICE RIVER - STUDIO
    » CnXHacker.CoM   © CopyRight 2002-2006, CnXHacker.CoM™, Inc. All Rights Reserved.