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



Hi Liviu,

I am sorry that I may not understand your question exactly.

Now if a new form(Form2) is created that subclasses Form1 the designer
will restrict the viewable portion to the default size of Form1.

What do you mean by "the default size"?

Below is my test and comments.

I set the Region property of Form1in its Load event handler as follows:
private void Form1_Load(object sender, EventArgs e)
{
System.Drawing.Drawing2D.GraphicsPath path = new
System.Drawing.Drawing2D.GraphicsPath();
Rectangle newrect = this.ClientRectangle;
path.AddEllipse(newrect);

this.Region = new Region(path);
}

Build the project and add an inherited form called Form2 into the project.
When I open Form2 in the designer, I see a circular form in the designer.

I should say that this behavior is by design. 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.
This is the reason why I see a circular form when I open Form2 in the
designer.

If you don't like the code to set the Region property of the base form to
be called at design time, you may add a condition "!this.DesignMode" on the
code.

The following is a sample.

private void Form1_Load(object sender, EventArgs e)
{
if (!this.DesignMode)
{
System.Drawing.Drawing2D.GraphicsPath path = new
System.Drawing.Drawing2D.GraphicsPath();
Rectangle newrect = this.ClientRectangle;
path.AddEllipse(newrect);

this.Region = new Region(path);
}
}

Build the project and re-open Form2, you should see a rectangle form in the
designer.

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

.



Relevant Pages

  • RE: winform designer (2005) error: duplicate component name
    ... any, is created first(thus, the base form's default constructor is called). ... Open the form in the designer to see if it can be opened properly. ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.framework.windowsforms.designtime)
  • Re: 2005 vs. 2003
    ... VS05 introduces the definition of Partial class, and places the Windows ... Forms Designer generated code in a seperate file, ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.languages.vb)
  • RE: Form design view with Fatal Execution Engine Error (7A2B45A2) (0)
    ... When a form is opened in the form designer, ... InitializeComponent method will be executed. ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.framework)
  • Re: Resize control with Verbs
    ... we should fire OnComponentChanging before the component is ... Net BCL designer classes also obey this rule. ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.framework.windowsforms.designtime)
  • Re: Delphi Product Manager questioned
    ... designer thing) are currently quite unstable. ... Also, WinFX (aka .NET 3) ... compiler and debugger support etc. for 2.0 should all work. ...
    (borland.public.delphi.non-technical)

Quantcast