Hi,

I discovered the following problem on windows forms:

DESCRIPTION
===========
1. A form (MainForm) calls another form (OtherForm) via a button.

2. OtherForm properties I have changed:
- FormBorderStyle = FixedDialog
- ControlBox = false

3. The calling form (MainForm) sets the location of the "OtherForm"
just before calling ShowDialog() method.

OtherForm f = new OtherForm();
f.Location = new Point(100,200);
f.ShowDialog();

RESULT
======
The "OtherForm" form is displayed with a wrong Size - other than the one
choosen by the designer.


Is this a BUG or what ?

Thanks
Emmanuel

Re: Form is not displayed at the correct (designer) size. by Stoitcho

Stoitcho
Fri May 20 10:00:32 CDT 2005

Emmanuel,

did you set OtherForm's StartPosition to Manual?


--

Stoitcho Goutsev (100) [C# MVP]

"Emmanuel" <Emmanuel@newsgroup.nospam> wrote in message
news:%23bNzg0RXFHA.3572@TK2MSFTNGP12.phx.gbl...
> Hi,
>
> I discovered the following problem on windows forms:
>
> DESCRIPTION
> ===========
> 1. A form (MainForm) calls another form (OtherForm) via a button.
>
> 2. OtherForm properties I have changed:
> - FormBorderStyle = FixedDialog
> - ControlBox = false
>
> 3. The calling form (MainForm) sets the location of the "OtherForm"
> just before calling ShowDialog() method.
>
> OtherForm f = new OtherForm();
> f.Location = new Point(100,200);
> f.ShowDialog();
>
> RESULT
> ======
> The "OtherForm" form is displayed with a wrong Size - other than the one
> choosen by the designer.
>
>
> Is this a BUG or what ?
>
> Thanks
> Emmanuel
>
>
>



Re: Form is not displayed at the correct (designer) size. by Emmanuel

Emmanuel
Tue May 24 03:28:46 CDT 2005

Hi Stoitcho,

It doesn't have to do with the StartPosition property. Whether I set it to
Manual or WindowsDefaultLocation it does not work !

Try it and you will see.

Emmanuel

"Stoitcho Goutsev (100) [C# MVP]" <100@100.com> wrote in message
news:uWRIXvUXFHA.2520@TK2MSFTNGP09.phx.gbl...
> Emmanuel,
>
> did you set OtherForm's StartPosition to Manual?
>
>
> --
>
> Stoitcho Goutsev (100) [C# MVP]
>
> "Emmanuel" <Emmanuel@newsgroup.nospam> wrote in message
> news:%23bNzg0RXFHA.3572@TK2MSFTNGP12.phx.gbl...
>> Hi,
>>
>> I discovered the following problem on windows forms:
>>
>> DESCRIPTION
>> ===========
>> 1. A form (MainForm) calls another form (OtherForm) via a button.
>>
>> 2. OtherForm properties I have changed:
>> - FormBorderStyle = FixedDialog
>> - ControlBox = false
>>
>> 3. The calling form (MainForm) sets the location of the "OtherForm"
>> just before calling ShowDialog() method.
>>
>> OtherForm f = new OtherForm();
>> f.Location = new Point(100,200);
>> f.ShowDialog();
>>
>> RESULT
>> ======
>> The "OtherForm" form is displayed with a wrong Size - other than the one
>> choosen by the designer.
>>
>>
>> Is this a BUG or what ?
>>
>> Thanks
>> Emmanuel
>>
>>
>>
>
>



Re: Form is not displayed at the correct (designer) size. by v-jetan

v-jetan
Tue May 24 04:26:56 CDT 2005

Hi Emmanuel,

Thanks for your feedback.

I have tried your steps with StartPosition set to FormStartPosition.Manual,
however, it works well on my side, sample code snippet lists below:

private void button1_Click(object sender, System.EventArgs e)
{
OtherForm f = new OtherForm();
f.StartPosition=FormStartPosition.Manual;
f.FormBorderStyle=FormBorderStyle.FixedDialog;
f.ControlBox=false;
f.Location = new Point(100,200);
f.ShowDialog();
}
So I suspect that this problem maybe in your OtherForm code. I suggest you
try a empty form without any specific controls or code snippet to see if
the problem still existed. Also, you may move your project to another
machine, then we can determine if this problem is machine-specific.
========================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Re: Form is not displayed at the correct (designer) size. by v-jetan

v-jetan
Wed May 25 22:16:11 CDT 2005

Hi Emmanuel,

Does my reply make sense to you? Is your problem resolved? Please feel free
to feedback, thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Re: Form is not displayed at the correct (designer) size. by Emmanuel

Emmanuel
Thu May 26 15:45:59 CDT 2005

Dear Jeffrey,

Thank you for your reply and sorry for the delay.

Yes. If I write the code the way you did, the problem does not appear. But
this was not the way I did it.
I have set all the properties on the "OtherForm" using the designer and left
only

OtherForm f = new OtherForm();
f.Location = new Point(100,200);
f.ShowDialog();

to the Click event of the "MainForm", because I only want to display the
form at a specified position. I do not want to set all the form attributes
on the click event of "MainForm".

Because your sample code worked on my system, I did a small research and
discovered that if I add the line
f.FormBorderStyle=FormBorderStyle.FixedDialog;
before setting f.Location property (NOT AFTER otherwise it does not work),
it works OK - although I have already set the FormBorderStyle using the
designer in the "OtherForm".

I think that this should be a bug on Windows.Forms classes.

What do you think ?

Thanks
Emmanuel

""Jeffrey Tan[MSFT]"" <v-jetan@online.microsoft.com> wrote in message
news:fLMpCLEYFHA.2184@TK2MSFTNGXA01.phx.gbl...
> Hi Emmanuel,
>
> Thanks for your feedback.
>
> I have tried your steps with StartPosition set to
> FormStartPosition.Manual,
> however, it works well on my side, sample code snippet lists below:
>
> private void button1_Click(object sender, System.EventArgs e)
> {
> OtherForm f = new OtherForm();
> f.StartPosition=FormStartPosition.Manual;
> f.FormBorderStyle=FormBorderStyle.FixedDialog;
> f.ControlBox=false;
> f.Location = new Point(100,200);
> f.ShowDialog();
> }
> So I suspect that this problem maybe in your OtherForm code. I suggest you
> try a empty form without any specific controls or code snippet to see if
> the problem still existed. Also, you may move your project to another
> machine, then we can determine if this problem is machine-specific.
> ========================================================
> Thank you for your patience and cooperation. If you have any questions or
> concerns, please feel free to post it in the group. I am standing by to be
> of assistance.
>
> Best regards,
> Jeffrey Tan
> Microsoft Online Partner Support
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
>



Re: Form is not displayed at the correct (designer) size. by Emmanuel

Emmanuel
Mon May 30 09:16:15 CDT 2005

Hi Jeffrey,

The form you have attached DOES have the problem.

Create a label inside the "OtherForm" and on the Load method add the
following code:

private void OtherForm_Load(object sender, System.EventArgs e)
{
lbl.Text = "Width: " + this.Size.Width.ToString() + " "
+ "Height: " + this.Size.Height.ToString();
}

You will immediately notice that the form SIZE is not the one specified in
"OtherForm"'s properties in Design mode.

Thanks
Emmanuel

""Jeffrey Tan[MSFT]"" <v-jetan@online.microsoft.com> wrote in message
news:8xpMvuoYFHA.3052@TK2MSFTNGXA01.phx.gbl...
> Hi Emmanuel,
>
> Thanks for your feedback.
>
> Yes, I have tried to set OtherForm's StartPosition, FormBorderStyle and
> ControlBox 3 properties in VS.net designer, and just use the statement
> below to invoke OtherForm:
> OtherForm f = new OtherForm();
> f.Location = new Point(100,200);
> f.ShowDialog();
>
> However, the OtherForm always shows in the correct position without any
> problem on my side.
>
> I have attached the sample project in this reply for your test. You may
> get
> this attachment through Outlook Express.
> ============================================
> Thank you for your patience and cooperation. If you have any questions or
> concerns, please feel free to post it in the group. I am standing by to be
> of assistance.
>
> Best regards,
> Jeffrey Tan
> Microsoft Online Partner Support
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.



Re: Form is not displayed at the correct (designer) size. by v-jetan

v-jetan
Tue May 31 03:00:00 CDT 2005

Hi Emmanuel,

Thanks for your feedback!

Sorry, it seems that I mis-looked your word "Size" as "Location". Oh, yes,
in my sample project, I can reproduce the "Size" changing problem.

First, it seems that this problem only occurs when we uses VS.net designer
to set OtherForm's properties. Based on my research, I found that in VS.net
designer, the setting for Form.Size property will not generate code for
Form.Size property, instead, it will generate code for Form.ClientSize
property. For example, if I set Form.Size to "500,300" in propetybrowser,
the code generated in InitializeComponent() will be like this:
this.ClientSize = new System.Drawing.Size(494, 275);

If we change this statement to this.Size=new Size(500, 300), then
everything will work well. So I think this should be the problem of VS.net
designer code generator.

The reason for this issue is that when we set
f.FormBorderStyle=FormBorderStyle.FixedDialog, it internally will set
form's border style to a width value which is different from(actually less
than) the default FormBorderStyle.Sizable(which should be 500-494=6 and
300-275=25). Then, when the form shows out, the result total size will be
less than (500, 300).

Anyway, the workaround for this issue is very simple, just use an explicit
Form.Size calling in place of Form.ClientSize code statement.

Hope this helps

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Re: Form is not displayed at the correct (designer) size. by Emmanuel

Emmanuel
Wed Jun 01 05:05:33 CDT 2005

Hi Jeffrey,

I understand the ClientSize and Size stuff. I new all this from the
beginning. I new that if I specify the Size of the form in code then
everything would work fine.

The workaround is not so "very simple" because the workaround you are
suggesting cancels the usage of the designer in building windows forms.

The workaround you suggest works as follows:

1. The programmer designs a form using the designer.
2. After finishing the design process, the programmer reads the values held
at the Size property of the form.
3. The programmer includes a line in his code that programmatically sets the
Size of the Form.

..4. If the programmer changes the size of the form, later, he should
complete all steps from 1 to 3 in order for the form to work correctly.

I consider this a serious Microsoft VS.NET 2003 bug.

Anyway thanks for the help.

Emmanuel


""Jeffrey Tan[MSFT]"" <v-jetan@online.microsoft.com> wrote in message
news:9EAnGbbZFHA.3928@TK2MSFTNGXA01.phx.gbl...
> Hi Emmanuel,
>
> Thanks for your feedback!
>
> Sorry, it seems that I mis-looked your word "Size" as "Location". Oh, yes,
> in my sample project, I can reproduce the "Size" changing problem.
>
> First, it seems that this problem only occurs when we uses VS.net designer
> to set OtherForm's properties. Based on my research, I found that in
> VS.net
> designer, the setting for Form.Size property will not generate code for
> Form.Size property, instead, it will generate code for Form.ClientSize
> property. For example, if I set Form.Size to "500,300" in propetybrowser,
> the code generated in InitializeComponent() will be like this:
> this.ClientSize = new System.Drawing.Size(494, 275);
>
> If we change this statement to this.Size=new Size(500, 300), then
> everything will work well. So I think this should be the problem of VS.net
> designer code generator.
>
> The reason for this issue is that when we set
> f.FormBorderStyle=FormBorderStyle.FixedDialog, it internally will set
> form's border style to a width value which is different from(actually less
> than) the default FormBorderStyle.Sizable(which should be 500-494=6 and
> 300-275=25). Then, when the form shows out, the result total size will be
> less than (500, 300).
>
> Anyway, the workaround for this issue is very simple, just use an explicit
> Form.Size calling in place of Form.ClientSize code statement.
>
> Hope this helps
>
> Best regards,
> Jeffrey Tan
> Microsoft Online Partner Support
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
>



Re: Form is not displayed at the correct (designer) size. by v-jetan

v-jetan
Wed Jun 01 21:03:30 CDT 2005

Hi Emmanuel,

Thanks for your feedback.

Yes, after doing some research in our internal product database, I found
several issues stated that our VS.net designer will by design serialize
Size property setting in PropertyBrowser as ClientSize statement in code
file.

I also found that there is a known issue report similiar to you, which is
also caused by Size property seraization, the product team has promised to
fix that issue in VS.net 2005. However, currently, I am not sure if it is
the same as your issue.

For this issue, I will contact our product team to get a confirmation on
it, I will update you ASAP. Thanks for your understanding.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Re: Form is not displayed at the correct (designer) size. by Emmanuel

Emmanuel
Fri Jun 03 03:03:15 CDT 2005

Thanks Jeffrey.

Emmanuel
""Jeffrey Tan[MSFT]"" <v-jetan@online.microsoft.com> wrote in message
news:JxQEPdxZFHA.3412@TK2MSFTNGXA01.phx.gbl...
> Hi Emmanuel,
>
> Thanks for your feedback.
>
> Yes, after doing some research in our internal product database, I found
> several issues stated that our VS.net designer will by design serialize
> Size property setting in PropertyBrowser as ClientSize statement in code
> file.
>
> I also found that there is a known issue report similiar to you, which is
> also caused by Size property seraization, the product team has promised to
> fix that issue in VS.net 2005. However, currently, I am not sure if it is
> the same as your issue.
>
> For this issue, I will contact our product team to get a confirmation on
> it, I will update you ASAP. Thanks for your understanding.
>
> Best regards,
> Jeffrey Tan
> Microsoft Online Partner Support
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
>



Re: Form is not displayed at the correct (designer) size. by v-jetan

v-jetan
Sun Jun 12 21:48:15 CDT 2005

Hi Emmanuel,

Sorry for letting you wait for so long.

For why we serialize CientSize property for Size property setting in
Designer, here is the Winform team's feedback:

"Control::ClientSize and Control::Size have different semantics. Setting
the ClientSize will use User32!AdjustWindowRectEx method. Setting the
Control::Size will use User32!SetWindowPos.

AdjustWindowRectEx takes into account the fact that the window may or may
not have menus.
SetWindowPos does not.

So, for the Form ( which can have menus ) we have to use
AdjustWindowRectEx. Hence, the designer needs to use the ClientSize
property. And so the designer serializes Form::ClientSize instead of
serializes

The other types of controls ( buttons, labels, etc ) don't have menus, so
we use SetWindowPos. Hence, the designer serializes the Size property."

Currently, for our issue, it is hard for us to find a way to leverage the
Designer to workaround the problem, it seems that the simplest workaround
is setting the Size in the form::Load event.

Hope this information helps you. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.