Form1_Paint事件 [英] Form1_Paint event

查看:175
本文介绍了Form1_Paint事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道它是如何工作的。

i wonder how it works..

我有这个代码。它应该在表单上绘制图片(位图图像​​)。但我不知道多久被触发。我需要它经常触发(至少每1-2秒)。我需要它将参数发送给我拥有的另一个对象(游戏游戏)..所以游戏对象将绘制一切

i have this code. it should paint pictures (Bitmap images ) on the form..constantly. but i dont know how often it is triggered. i need it to be triggered very often (at least every 1-2 seconds). i need it to send the parameters to another object that i have (Game game).. so game object will draw everything

   public void Form1_Paint(object sender, EventArgs e)
{

        //the animation has 4 cell to draw, so the arguments are passed to the game objects instructing it to which cells to draw.
        using (Graphics g = this.CreateGraphics())
        {
            game.Draw(g, animationTimerCounter);
        }
}

事件何时触发?

推荐答案

当表单(或其一部分)必须重绘时,调用paint事件,例如表单被移动,或者另一个窗口隐藏了其中的一部分等。

A paint event is called when the form (or part of it) has to be redrawn, e.g. the form is moved, or another window has hidden a part of it etc.

您可以通过调用 yourControl.Invalidate() 方法。

You can force a Paint event by calling yourControl.Invalidate() method.

在您的情况下,您可以使用例如一个Timer来强制绘制所需频率(例如每1-2秒)。

In your case you could use for example a Timer to force a Paint with the desired frequency (e.g. every 1-2 seconds).

这篇关于Form1_Paint事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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