C#刷新/重绘时的形式在对话框中设置更新 [英] C# Reload/Redraw form upon settings update in dialog box

查看:312
本文介绍了C#刷新/重绘时的形式在对话框中设置更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#赢窗体应用程序,我画动态按钮基于类2的属性面板。行和列。

I have a C# Win Forms application where I dynamically draw buttons in a panel based on 2 properties in the class. Rows and Columns.

我也有打开,这台使用2个文本框的属性对话框。

I also have a dialog box that opens, which sets those properties using 2 textboxes.

我对所谓的拯救的对话框,在按下,更新到任何的值设置主类的属性(行,列)按钮。

I have a button on that dialog box called "save" which upon pressing, updates the properties (rows, columns) in the main class to whatever values are set.

我想主要形式重绘动态绘制按钮的基础上,应用(行和列)新的设置。我怎样才能做到这一点。

I want the main form to redraw the dynamically drawn buttons, based on the new settings applied (rows and columns). How can I do this?

编辑:

刷新不工作。

另一个可能的重要说明:我的按钮的动态绘制在Form1_Load的方法时发生

Another possibly important note: my dynamic drawing of buttons occurs in the "Form1_Load" method.

推荐答案

您已经基本三种方式来强制控制重绘本身,刷新(),更新()并失去()。正如亚当·罗宾逊指出的,使风俗画最简单的方法是重写Paint事件。把所有的绘画逻辑在这里。使用由PaintEventArgs的参数提供的Graphics对象。

You have basically three ways to force the control to redraw itself, Refresh(), Update() and Invalidate(). As Adam Robinson points out, the easiest way to enable custom painting is to override the Paint event. Put all painting logic here. Use the Graphics object provided by the PaintEventArgs parameter.

那么,什么是上面的电话有什么区别?

So what's the difference between the above calls?

<强>的Invalidate 标记控制(区域,或矩形)为需要重画的,但不会立即重新绘制(重绘被触发时一切已经照顾和应用程序变得空闲)。

Invalidate marks the control (region, or rect) as in need of repainting, but doesn't immediately repaint (the repaint is triggered when everything else has been taken care of and the app becomes idle).

更新使控制如有部分已经失效立即重绘。

Update causes the control to immediately repaint if any portions have been invalidated.

刷新导致无效,然后更新(即立即重绘自己)控制。

Refresh causes the control to invalidate, and then update (i.e. immediately repaint itself).

我会说这是一个好习惯使用的Invalidate(),除非你有特定的需求,以应付。在大多数情况下,它会使你的程序更有效。如果你这样做,你甚至不会需要有油漆的逻辑在你的加载事件。很可能这是被覆盖和无效之前,你甚至让你的窗体可见,这取决于你在Load事件做什么。

I'd say it's a good habit to use Invalidate() unless you have specific needs to cater for. In most cases it will make your program more efficient. If you do this, you won't even need to have paint logic in your load event. Quite possibly this is being overwritten and invalidated before you even get your form visible, depending on what else you do in the Load event.

这篇关于C#刷新/重绘时的形式在对话框中设置更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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