"Disable" form to repaint it

B

BMermuys

Hi,

While you are inside an event handler and change controls no paint can
happen, because the message loop is blocked until the event handler returns.

If controls are invalidated because of change then the WM_PAINT message will
be processed _after_ the function returns and the message loop resumes it's
dispatching.

Direct (synchronous) repainting only happens when you call Update after you
invalidate the control.


HTH,
greetings
 
B

BMermuys

Hi,
inline

Stoitcho Goutsev (100) said:
Hi BMermuys,


That is correct as long as you are talking about Win32. In WindowsForms
They maybe are a little more then just wrappers...
there is not such a thing as "direct (synchronous)" repainting.

Why do you think that ?

According to Net SDK documentation Update causes the control the redraw it's
invalidated region.

And if you make a loop like this in a event handler

for (int i = 0; i<5; ++i)
{
textBox1.Text = i.ToString();
textBox1.Update();
System.Threading.Thread.Sleep(1000);
}

Then you can clearly see the textbox repaints itself every second.
With the Update the textbox repaints it's invalidated region immediatly,
without the Update it waits until the function quits.
With the spy tool, you can also see the WM_PAINT message sent to the textbox
each time Update is called.

And if you would replace the textbox with a user control, call Invalidate
instead of changing text with Update, then the usercontrol's OnPaint method
will be called 5 times with a 1 second interval. The loop won't continue
until the OnPaint is done. This seems synchronous to me.
Refresh and
Update methods both triger rapainting after leaving the processing of the
current event.

You can easily test this isn't true.


greetings
 
B

Boniek

Hi

I have one question. How I can "disable" my form ? I want to change
controls' setting on my form but I don't want repaint my form while I'm
changing controls. Can I set off my repainting for form when I'm
changing my controls ?
Next I repaint my form when my controls' setting was updated.

Thank's for all
Boniek
 
U

Uri Dor

have you tried SuspendLayout, ResumeLayout ?
look at InitializeComponent() generated by the designer.
 
N

Nicholas Paldino [.NET/C# MVP]

Boniek,

I'm not quite sure what you are trying to do. If you don't want the new
controls to be shown, then why not just add the new controls, but make them
hidden. You can give the existing controls a greyed-out look by setting the
Enabled property of the control to false.

Hope this helps.
 
B

Boniek

I'm trying to do that because I want load a setting of toolBar from
file. The ToolBar has setting in xml and when it loaded this file my
form is repaing for any changes for that control. I want to disable my
form while toolbar is loading from file and set up my repainting for
that form. Setting of ToolBar was loaded by user and my toolbar change
setting for his bars. It don't looks good when my form flickes.


U¿ytkownik "Nicholas Paldino [.NET/C# MVP]"
Boniek,

I'm not quite sure what you are trying to do. If you don't want the new
controls to be shown, then why not just add the new controls, but make them
hidden. You can give the existing controls a greyed-out look by setting the
Enabled property of the control to false.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Boniek said:
Hi

I have one question. How I can "disable" my form ? I want to change
controls' setting on my form but I don't want repaint my form while I'm
changing controls. Can I set off my repainting for form when I'm
changing my controls ?
Next I repaint my form when my controls' setting was updated.

Thank's for all
Boniek
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Hi Boniek,

Generally speeking Windows form doesn't support suspending and resuming
repainting. Some of the controls ComboBox, ListBox, ListView and TreeView
provide BeginUpdate/EndUpdate method pairm which stops the repaint of the
control. For other controls there is no managed solution unless you inherit
form the control and implement it yourself.
Other solution could be to use PInvoke and SendMessage API to send
WM_SETREDRAW message to the control.
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Hi BMermuys,
Direct (synchronous) repainting only happens when you call Update after you
invalidate the control.

That is correct as long as you are talking about Win32. In WindowsForms
there is not such a thing as "direct (synchronous)" repainting. Refresh and
Update methods both triger rapainting after leaving the processing of the
current event. Direct repainting can be done only by creating Graphics
object via Control.CreateGraphics.
 
S

Stoitcho Goutsev \(100\) [C# MVP]

BMermuys,

Yes, my mistake :(
I've gotten wrong impression about Update and Refresh. Even looking in the
Control.Update's IL code is clearly visible that it calls UpdateWindows API.

Sorry about that.
 
N

Nurchi BECHED

Hello, Boniek!

In the first place, why do you need to load settings from an XML file?
You might have a reason, but if there is nothing specific, I would recommend
using Windows Registry.
It is a lot faster and way more convenient...
And you don't need to worry about all those nodes and crap...

Here is an example of using Registry Keys:
Microsoft.Win32.RegistryKey hkcu=
Microsoft.Win32.Registry.CurrentUser;
Microsoft.Win32.RegistryKey regKey=
hkcu.CreateSubKey("Software\\Whatever your company name
is\\PortAccess");
//This will open a key if it exists or create one for you...

int x=
(int)regKey.GetValue(
"Value name goes here",
optional_default_value_is_here_if_VALUENAME_does_not_exist);

regKey.SetValue(
"Value name goes here",
data_goes_here_not_necessarily_a_string);


Here is my example:
private void MyForm_Load(object sender, System.EventArgs e)
{
Microsoft.Win32.RegistryKey hkcu=
Microsoft.Win32.Registry.CurrentUser;

Microsoft.Win32.RegistryKey regKey=
hkcu.CreateSubKey("Software\\Maple Leaf Software\\PortAccess");

this.Left=(int)regKey.GetValue("My Window X", 10);
this.Top=(int)regKey.GetValue("My Window Y", 10);
}
private void MyForm_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
Microsoft.Win32.RegistryKey hkcu=
Microsoft.Win32.Registry.CurrentUser;

Microsoft.Win32.RegistryKey regKey=
hkcu.CreateSubKey("Software\\Maple Leaf Software\\PortAccess");

regKey.SetValue("My Window X", this.Left);
regKey.SetValue("My Window Y", this.Top);
}

A better practice would actually be to create a private variable
hkcu or even regKey within a class and just use it when needed...
Also a very good thing to do would be create constant strings
containing messages like "My Window X", "My Window Y", etc.
To avoid errors, you know like when you set value for "Today"
and then somewhere in the program try to access "Tody" and
wonder why it is not working (believe me, it happens...)

Well, hope this helps.
Good luck.

You wrote on Mon, 29 Mar 2004 15:53:29 +0200:

B> I'm trying to do that because I want load a setting of toolBar from
B> file. The ToolBar has setting in xml and when it loaded this file my
B> form is repaing for any changes for that control. I want to disable my
B> form while toolbar is loading from file and set up my repainting for
B> that form. Setting of ToolBar was loaded by user and my toolbar change
B> setting for his bars. It don't looks good when my form flickes.

With best regards, Nurchi BECHED.
 
R

Ravichandran J.V.

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top