ImageBox绘画 [英] ImageBox Paint

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

问题描述



我有一个小问题,无法解决.我希望那里的人可以教我如何.这是问题所在:

我有一个硬件和一个键盘,并为此编写了一个测试应用程序.测试按钮是否被按下.当按下按钮时,我正在其上绘制一个矩形.但是问题是当我释放按钮矩形时消失了.我想和所有按下的按钮呆在一起.就像我按下按钮1和按钮2时一样,我希望它们都显示矩形​​并将它们保留在窗体上.

这是我的代码:

Hi,

I have a small problem which I can''t fix. I hope someone out there can teach me how. Here is the problem:

I have a hardware a keyboard and writing a test application for it. To test if the buttons are pressed. When a button pressed I am drawing a rectangle on it. but the problem is when i release the button rectangle disappears. I want to stay there with all the pressed buttons. like when i hit button 1 and button 2 I want them both display rectangles and keep them on the form.

Here is my code:

private void ImageBox_Paint_1(object sender, PaintEventArgs e)
        {
            if (buttcorrs != null && buttcorrs.Count() == 4)   
            {
                e.Graphics.FillRectangle(Brushes.Green, buttcorrs[0], buttcorrs[1], buttcorrs[3] - buttcorrs[1], buttcorrs[2] - buttcorrs[0]);
                ImageBox.Invalidate(); 
                //Array.Clear(buttcorrs, 0, buttcorrs.Length);
            }


buttcorrs是一个数组,在该数组中,我从设备以unicode的形式发送坐标.如我所说,当我按下另一个键时,它将删除矩形并在新按钮上显示一个新矩形.


buttcorrs is an array where i send the coordinates as a unicode from the device. as I said when i hit another key it deletes the rectangle and displays a new one on the new button.

推荐答案

这就是重写ImageBox_Paint方法的方式应该是.

图形不绘制在内存中,而只是在屏幕上.调用Paint时,它将清除图形并重新开始.

如果要绘制所有矩形,则必须将它们全部存储在List或其他集合中,然后在Paint中,每次都绘制它们.
That''s the way that overridding the ImageBox_Paint method is supposed to be.

The graphics are not drawn in memory, just on the screen. When Paint is called, it clears the graphics and starts over.

If you want to draw all of the rectangles, you''ll have to store them all in a List or some other collection and then in the Paint, draw them all each time.


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

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