从另一个类涂料的方法 [英] 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();
mapGraphics.Dispose();
}
}
有没有异常抛出,也没有错误。我试图调用从Form_Paint方法绘制方法,但没有任何反应都没有。我该如何解决这个问题?
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?
感谢
推荐答案
要画成一个窗口,你需要使用Graphics对象,该窗口。你的方法创建一个新的Graphics对象,所以它吸引别的地方。
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".
通过 e.Graphics
对象你有你的Form_Paint处理程序进入方法作为参数,并使用替代。
Pass the e.Graphics
object that you have in your Form_Paint handler into the method as a parameter, and draw using that instead.
这篇关于从另一个类涂料的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文