Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / March 2006

Tip: Looking for answers? Try searching our database.

Layout event and designer

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Grafix - 04 Mar 2006 14:54 GMT
All -
I have a custom control - in which when a property value changes, i call
"PerformLayout" method (becoz my internal layout calculations have changed).
I also override "OnLayout" to do the actual layout calculations.

When the control is used from "VS Designer", form.designer.cs generates
following code:
customControl.SuspendLayout();
customControl.SomeProperty = someValue;
      // < the above propertychange will call PerformLayout internally>
customControl.ResumeLayout(false); // Note the "false"

The problem is that since SuspendLayout was called, PerformLayout does a
"NoOP" i guess and the overridden OnLayout is *never* called (confirmed thro'
debugger).

Albeit changing ResumeLayout(false) to ResumeLayout(true) makes everything
work fine.

My question is -
(a) Why z ResumeLayout(false) called by the designer instead of true- not
allowing pending layout events to be processed?

(b) Is my technique of overriding "OnLayout" event to perform layout
calculations and using PerformLayout to force new layout incorrect?
If so what is the correct way to do this?

I am using VS 2005 - C#.

Regardz
Grafix.
Sericinus hunter - 04 Mar 2006 17:46 GMT
...
> My question is -
> (a) Why z ResumeLayout(false) called by the designer instead of true- not
> allowing pending layout events to be processed?

   My guess is, this is to overcome C# somewhat questionable approach
to inheritance. If you are in the constructor of the base class, you are
already of the type of the inheritor, not the base. This means that
if layout is allowed, and the inheritor overrides the OnLayout method,
the method will be called on the inheritor, who obviously does not exist
at this point yet.

> (b) Is my technique of overriding "OnLayout" event to perform layout
> calculations and using PerformLayout to force new layout incorrect?
> If so what is the correct way to do this?

   I would simply set that property outside the generated code, by hand,
e.g. in OnCreateControl.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.