如何手动的WinForms得到Graphics对象的实例? [英] How to manually get instance of Graphics object in WinForms?

查看:131
本文介绍了如何手动的WinForms得到Graphics对象的实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何与类型图形(至少我能够渲染图像)的目标工作,但我总是这样通过将图形对象从OnPaint方法检索。

I know how to work with object of type Graphics (at least I am able to render images) but I always do that by passing graphics object retrieved from OnPaint method.

我想,当应用程序被打开(的Form_Load方法IE)来显示图像,但不知道如何获取Graphics对象,我可以使用的实例?
谢谢

I would like to display an image when the app is opened (ie in Form_Load method) but have no clue how to obtain the instance of Graphics object I could use? Thanks

推荐答案

使用e.Graphics对象,它的OnPaint()供应给您的是这样做的正确方法。它将在onload()方法之后运行。形式是不可见但在的OnLoad。

Using the e.Graphics object that OnPaint() supplies to you is the correct way of doing it. It will run right after the OnLoad() method. The form isn't visible yet in OnLoad.

充分利用Control.CreateGraphics一个Graphics对象()的支持。但是,不管你绘制这将是尽快重新绘制表格本身一扫而光。当用户移动跨越你(预航空),或当她最小化和还原或以其它方式调整大小的窗口中的另一个窗口,它发生。以高速率动画时使用的createGraphics只有永远。

Getting a Graphics object from Control.CreateGraphics() is supported. However, whatever you draw with this will be wiped out as soon as the form repaints itself. Which happens when the user moves another window across yours (pre-Aero) or when she minimizes and restores or otherwise resizes the window. Use CreateGraphics only ever when animating at a high rate.

这篇关于如何手动的WinForms得到Graphics对象的实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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