Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何实施';单击';c#图形对象的方法 inty=20; 对于(int row=0;row_C#_Drawing - Fatal编程技术网

如何实施';单击';c#图形对象的方法 inty=20; 对于(int row=0;row

如何实施';单击';c#图形对象的方法 inty=20; 对于(int row=0;row,c#,drawing,C#,Drawing,使用图片框: int Y = 20; for (int row = 0; row <= 19; row++) { int X = 25; for (int col = 0; col <= 29; col++) { Graphics graphicsObj; graphicsObj = this.CreateGraphics(); graphicsObj.FillEllipse(Brushes.Blue, X, Y

使用图片框:

int Y = 20;
for (int row = 0; row <= 19; row++)
{
    int X = 25;
    for (int col = 0; col <= 29; col++)
    {
        Graphics graphicsObj;
        graphicsObj = this.CreateGraphics();
        graphicsObj.FillEllipse(Brushes.Blue, X, Y, 5, 5);
        X += 25;
    }
    Y += 20;
}
使用系统;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用System.Linq;
使用系统文本;
使用System.Windows.Forms;
命名空间Windows窗体应用程序1
{
公共部分类Form1:Form
{
公共表格1()
{
初始化组件();
int Y=20;

对于(int row=0;row当您直接在画布上绘制时,除了画布外,没有可单击的“对象”,因此任何单击处理都必须由您自己(或您找到的其他库)处理。您可以为绘制的每个形状创建UserControl对象,但查找单击的位置将由您自己决定。您在方法
私有无效框中写了什么\u单击(对象发送者,事件参数e)
?您需要将框添加到主窗体。此.Controls.add(框);
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            int Y = 20;
            for (int row = 0; row <= 19; row++)
            {
                int X = 25;
                for (int col = 0; col <= 29; col++)
                {
                    PictureBox box = new PictureBox();

                    Graphics graphicsObj = box.CreateGraphics();
                    graphicsObj.FillEllipse(Brushes.Blue, X, Y, 5, 5);
                    X += 25;

                    box.Click += new EventHandler(Box_Click);


                }
                Y += 20;
            }

        }
        private void Box_Click(object sender, EventArgs e)
        {
        }
    }
}