Re: Designer doesn't update the window/form region based on subclassing

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi Liviu,

Thank you for your prompt response and sample project. I understand your
question exactly now.

You may add the following statement before the code 'this.Region = new
Region(Drawing.GetRoundedRectangle(new Rectangle(0, 0, this.Size.Width,
this.Size.Height), 0.3f));' in the Form1's Load event handler:

MessageBox.Show(this.Size.ToString());

Build the project and re-open Form2 in the designer. You should see a
message box pops up showing the size of Form1, not the size of Form2.

As I have explained in my first reply, when we open a derived form in the
designer, an instance of the base form is created. Thus the constructor of
the base form is called and then the Load event handler. It's after the
instance of the base form finishes the construction and load that the
IntializeComponent method of the derived form is called.

That's to say, in your sample project, when the Form1's Load event handler
is called, the size of the Form2 is equal to that of the Form1. So the
region is set based on the size of the Form1.

As I have mentioned, this behavior is by design. I think there're two
options for you to solve this problem.

One option is what I have provided in my first reply, i.e. add a condition
of "!this.DesignMode" to prevent the code of setting region from being
called at design time. This option will cause the Form2 to loose the
'region' behavior at design time(but the Form2 still has the 'region'
bebavior at run time).

The other option is to move the code of setting region to the Resize event
handler of the Form1. The Resize event of the base form will ocurr no
matter at design time or run time, as long as the size of the derived form
is changed. This option enables the Form2 to have the 'region' behavior at
design time.

I perfer the second option.

Hope this helps.
If you have anything unclear, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

.



Relevant Pages

  • Re: Designer doesnt update the window/form region based on subclassing
    ... the amount of designer specific code as much as possible. ... Build the project and re-open Form2 in the designer. ... the base form is called and then the Load event handler. ... matter at design time or run time, as long as the size of the derived form ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Re: Forms Inheritance and its baggage!
    ... operation for comboBoxes are not compatible. ... runtime attributes need to be forced-in at the design time. ... Controls, including Forms. ... Firstly one has to presume that some controls on the base Form will be ...
    (microsoft.public.vsnet.general)
  • Skip some code in Design Time.
    ... I want to prevent some code to run in design time. ... I have a base form that have some code in its Load event. ... As far as I know below code can prevent code to run in debug mode. ...
    (microsoft.public.dotnet.framework)
  • Re: One ImageList, Multiple Forms (DESIGN TIME)
    ... but you may try to create a base form including the ... theory it should work at design time as well as at run time. ... > Since MS decided to seal the ImageList class, ... > shared amongst many forms in my project? ...
    (microsoft.public.dotnet.languages.csharp)
  • Form Load Event In Design Time
    ... but when i open an inherited form in the design time ... the form load event of the base form is executed ...
    (microsoft.public.dotnet.framework.windowsforms.designtime)