1

我用图形路径创建了一个用户控件。当我在我的主 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");
    }
}
4

0 回答 0