开发者

Paint a method from another class

I have made a draw method in a separate class to that of the form.

public class Object : Form1
 {   
    public void Draw()
    {
            SolidBrush brush = new SolidBrush(Color.Yellow);
            Graphics mapGraphics = this.CreateGraphics();
            mapGraphics.FillEllipse(brush, new Rectangle(0, 0, 12, 12));
            pacBrush.Dispose();
           开发者_如何学Python mapGraphics.Dispose();
    }
}

There are no exceptions thrown, nor errors. I have tried to call the Draw method from the Form_Paint method, but nothing happens at all. How can I fix this?

Thanks


To draw into a window, you need to use the Graphics object for that window. Your method creates a new Graphics object, so it draws "somewhere else".

Pass the e.Graphics object that you have in your Form_Paint handler into the method as a parameter, and draw using that instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜