グラフィックパスでユーザーコントロールを作成します。メインの winform クラスでクリック イベントを割り当てると、ユーザー コントロールがクリックされたときに発生しません。これはユーザーコントロールの領域と関係があると思ったので、図形のグラフィックパスで新しい領域を作成しました。発砲しない理由は他にありません。私は何が欠けていますか?
public abstract class BaseShape : UserControl
{
protected void DrawFill(PaintEventArgs e)
{
GraphicsPath path = CreatePath();
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
using (SolidBrush brush = new SolidBrush(Fill.Color))
{
e.Graphics.FillPath(brush, path);
}
this.Region = new Region(path);
}
}
public partial class Circle : BaseShape
{
protected override GraphicsPath CreatePath()
{
GraphicsPath path = new GraphicsPath();
path.StartFigure();
path.AddEllipse(Contour.Weight, Contour.Weight, this.Width - 2 * Contour.Weight, this.Height - 2 * Contour.Weight);
this.Region = new Region(path);
return path;
}
}
public partial class Main : Form
{
private void Circle1_Click(object sender, EventArgs e)
{
MessageBox.Show("tnjek");
}
}