如何实施';单击';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)
{
}
}
}