在Panel C#Windows窗体上绘图 [英] Drawing on Panel C# windows forms

查看:587
本文介绍了在Panel C#Windows窗体上绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如果我在设计上有误,请纠正或建议我采用正确的方法..

我创建了一个小作业.我需要您的建议才能运行该应用程序.

由于我之前的mfc代码是不受管理的,并且以相同的方式思考,因此
所以我对使用托管C#代码感到困惑.


内容是

Mainform类:-贯穿包含2个面板的主应用程序.

全局类:-

Hi,

Please correct if I am wrong in Design or suggest me to go through right way..

I have created one small assignment. and i need your suggestions to work that application.

As my previous mfc code was unmanaged and thinking the same way,
so I m getting little confused to work with managed c# code.


Contents are

Mainform class:- which runs through main application which contains 2 panels.

Global class:-

DrawShape(Line object, Graphics gObject)
{
  object.Draw(gObject);
}



线路类别:-



Line class:-

public void Draw(Graphics object);



Form1类:-其独立形式.包含一个按钮



Form1 class:- Its independent form. contains one button

On button Click()
	{
	Line object = new Line();
			
  	          //TODO:
		
		  //I want to draw the line on mainform''s panel for
                  //that i need Graphics object of Mainform.panel.
			
		  // Global.DrawShape(object, GraphicsObject);
		}

推荐答案

您应该处理面板的Paint事件并在那里执行绘图. PainEventArgs提供图形对象作为其属性之一.这将具有在其上绘制线条的方法.

在按钮单击事件中,可以设置所需的值,然后创建该行.
You should handle the panel''s Paint event and perform your drawing there. PainEventArgs offers graphics object as one of its property. That will have method for drawing lines on it.

In the button click event, you can set the values which you need and then create the line.


谢谢,

我已经使用了事件处理,并且可以正常工作.但是它会引发跨线程操作无效错误.
我使用invoke方法解决了这个问题,但我不明白什么是跨线程操作.
Thanks,

I have used Event handling and it worked. but It throws Cross thread operation invalid error.
I solved it using invoke method but i didn''t understand what is Cross thread operation.


这篇关于在Panel C#Windows窗体上绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆