Click事件未从使用graphicsPath绘制的用户控件触发

时间:2019-05-18 14:24:37

标签: c# winforms user-controls graphicspath

我使用图形路径创建一个用户控件。当我在我的主要winform类中分配一个click事件时,单击usercontrol时不会触发。我认为这与用户控件的区域有关,所以我用形状的图形路径创建了一个新区域。我看不出它没有触发的任何其他原因。我想念什么?

Assign event

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");
    }
}

0 个答案:

没有答案