C#Windows表单 [英] C# windows forms

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

问题描述

我对Windows编程还很陌生.

我有一个使用DrawRectangle在其上绘制平方图的表格.
当显示DropDownMenu时,选择的选项消失并且菜单消失,下一次使用FillRectangle进行绘制的尝试将忽略菜单先前与正方形图表重叠的区域.
这仅在第一次尝试绘制时发生,随后尝试OK.

请提供指导

I am fairly new to windows programming.

I have a form on which is drawn a squared chart using DrawRectangle.
When DropDownMenu displayed, option selected and menu disappears, next attempt at drawing using FillRectangle ignores area where menu had previously overlapped squared chart.

This only occurs on first attempt at drawing, subsequent attempst OK.

Guidance please

推荐答案

是的.什么都不会被忽略.您的控件无效,它触发Paint事件,但是它没有任何图形地被处理.您需要在Paint事件中进行绘制.这是进行渲染的地方.

像这样:

Yes of course. Nothing is ignored. Your control gets invalidated, it fires Paint event, but it is processed without any drawing. You need to draw inside Paint event. This is where rendering takes place.

Like this:

myPanel.Paint += (sender, evenArgs) => {
    evenArgs.Graphics.FillRectangle(
       System.Drawing.Brushes.Red,
       new System.Drawing.Rectangle(0, 0, 200, 120));
};



你看? Graphics已经在您的事件参数中为您提供了.
如果每次面板的某些部分失效都会发生.

若要进行图片更改,您需要将有关图片的一些数据传递给事件处理程序,并在需要更改时更改此数据(星期六,在Form的成员中). Paint事件将在每个myPanel.Invalidate上发送.您可以将Invalidate与参数一起使用,以仅使场景的一部分无效(仅修改的场景);



You see? Graphics is already there for you, in your event arguments.
If happens every time some part of panel is invalidated.

To make a picture changing, you need to pass some data about picture to the event handler and change this data (sat, in you Form''s members) when you need a change. The Paint event will be sent on each myPanel.Invalidate. You can use Invalidate with parameters to invalidate only a part of the scene (only what was modified); this improves performance.


尝试在控件上调用FillRectangle之前将焦点设置到控件上.
我不知道这是否行得通,但是您可以尝试...

您也可以在调用FillRectange().
Try setting focus to the control before calling FillRectangle on it.

I don''t know if that''s gonna work, but it''s something you can try...

You might also try calling Invalidate() after calling FillRectange().


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

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