C# 动态控件如何建立和区分对应的控件事件

本文介绍了一个使用Windows Forms创建的应用程序实例,重点展示了如何进行窗体布局设计及事件处理过程。其中包括如何设置窗体的位置、尺寸,以及如何为PictureBox控件添加点击事件,并响应这些事件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

            /*MessageBox .Show ( Convert.ToString(10, 16));进制转换*/
            Size pin = System.Windows.Forms.SystemInformation.WorkingArea.Size;
            this.Location = new Point(pin.Width - this.Width - 45, pin.Height - this.Height);
            foreach (char kj in "12345678ABCDEFGH")
            {
                PictureBox xin = new PictureBox();
                xin.Parent = this;
                xin.Name = kj.ToString();
                xin.BorderStyle = BorderStyle.Fixed3D;
                xin.Size = new System.Drawing.Size(50, 100);
                //xin.Click += new EventHandler(图片单击);
                if (xin.Name == "8") xin.Click += new EventHandler(图片单击);
                if ("12345678".Contains(kj))
                {
                    xin.Image = 选图区域(@System.Environment.CurrentDirectory + "\\数字\\数字0.jpg", 图0坐标[++循环][0], 图0坐标[循环][1], 图0坐标[0][0], 图0坐标[0][1], xin.Width, xin.Height);
                    xin.Location = new Point(xin.Width * (int.Parse(kj.ToString()) - 1) + 5 * int.Parse(kj.ToString()), 5);
                }
                if ("ABCDEFGH".Contains(kj))
                {
                    xin.Image = 选图区域(@System.Environment.CurrentDirectory + "\\数字\\数字0.jpg", 图0坐标[++循环 - 8][0], 图0坐标[循环 - 8][1], 图0坐标[0][0], 图0坐标[0][1], xin.Width, xin.Height);
                    xin.Location = new Point((xin.Right * (循环 - 9)) + 5 * (循环 - 8), xin.Bottom  + 15);
                }
            }
            this.AllowDrop = true; //this.Opacity = .9;
            this.DoubleClick += new EventHandler(窗体双击);
            this.Resize += new EventHandler(窗体大小);
            this.FormClosed += new FormClosedEventHandler(关闭后);
            this.DragDrop += new DragEventHandler(窗体拖放);
            this.DragEnter += new DragEventHandler(拖入窗体);

        private void 图片单击(object sender, EventArgs e)
        {
            MessageBox.Show(((PictureBox)sender).Name + "\r\n" + ((MouseEventArgs )e).Button .ToString());
        }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值