Bug: System.Windows.Forms.Form.Show()

Bug: System.Windows.Forms.Form.Show()

Post by Christian Rodemeye » Tue, 05 Mar 2002 19:18:50



How to reproduce:

Create a new form. Set FormBorderStyle to 'None' and StartPosition to
'Manual'. Resize the form to width = 200 and height = 16. Now show the form
somewhere from your main form, e.g. in the OnClick event.

Form1 test = new Form1();

private void SoftTerminal_Click(object sender, System.EventArgs e)
{
  test.Size = test.ClientSize; // borderless form, should be the same anyway
  Debug.WriteLine(test.Size);
  test.Show();
  Debug.WriteLine(test.Size);

Quote:}

This is the output:

{Width=200, Height=16}
{Width=200, Height=27}

The method Show() enlarges the form! Strangely, if the form is big enought,
say 200x80 no enlargment takes place.
The only workaround I have found, is to resize the form after it has been
shown, but this gaves a flickering effect.

  System.Drawing.Size mySize = test.ClientSize;
  test.Show();
  test.ClientSize = mySize;
  test.Size = mySize;

Why does Show() change the size of a Form? I would call this a bug.

Depressed

  Christian

 
 
 

Bug: System.Windows.Forms.Form.Show()

Post by Dusti » Tue, 05 Mar 2002 23:13:51


I've noticed the same thing, and having the height greater
than 80 doesn't seem to stop it from enlarging on my
end....

Quote:>-----Original Message-----
>How to reproduce:

>Create a new form. Set FormBorderStyle to 'None' and
StartPosition to
>'Manual'. Resize the form to width = 200 and height = 16.
Now show the form
>somewhere from your main form, e.g. in the OnClick event.

>Form1 test = new Form1();

>private void SoftTerminal_Click(object sender,
System.EventArgs e)
>{
>  test.Size = test.ClientSize; // borderless form, should
be the same anyway
>  Debug.WriteLine(test.Size);
>  test.Show();
>  Debug.WriteLine(test.Size);
>}

>This is the output:

>{Width=200, Height=16}
>{Width=200, Height=27}

>The method Show() enlarges the form! Strangely, if the

form is big enought,

- Show quoted text -

Quote:>say 200x80 no enlargment takes place.
>The only workaround I have found, is to resize the form
after it has been
>shown, but this gaves a flickering effect.

>  System.Drawing.Size mySize = test.ClientSize;
>  test.Show();
>  test.ClientSize = mySize;
>  test.Size = mySize;

>Why does Show() change the size of a Form? I would call
this a bug.

>Depressed

>  Christian

>.


 
 
 

Bug: System.Windows.Forms.Form.Show()

Post by M. Veurma » Wed, 06 Mar 2002 01:08:00


It might be related to the menu bar. If have the same problem. Upon closing
the application I save the current width/height of my main window. When the
application is started again and the size is set to the previous size, the
main window is 19 pixels higher.

So as a workaround I always substract 19 pixels from the height.

I think it somehow has to do with the presence of a menu bar. When I
completely disable the menu bar in my main window everything works as
expected.

So my guess is that the Show first displays the form using the given sizes
and after that finds out it also has to add a menu bar...

Mathieu Veurman


Quote:> I've noticed the same thing, and having the height greater
> than 80 doesn't seem to stop it from enlarging on my
> end....

> >-----Original Message-----
> >How to reproduce:

> >Create a new form. Set FormBorderStyle to 'None' and
> StartPosition to
> >'Manual'. Resize the form to width = 200 and height = 16.
> Now show the form
> >somewhere from your main form, e.g. in the OnClick event.

> >Form1 test = new Form1();

> >private void SoftTerminal_Click(object sender,
> System.EventArgs e)
> >{
> >  test.Size = test.ClientSize; // borderless form, should
> be the same anyway
> >  Debug.WriteLine(test.Size);
> >  test.Show();
> >  Debug.WriteLine(test.Size);
> >}

> >This is the output:

> >{Width=200, Height=16}
> >{Width=200, Height=27}

> >The method Show() enlarges the form! Strangely, if the
> form is big enought,
> >say 200x80 no enlargment takes place.
> >The only workaround I have found, is to resize the form
> after it has been
> >shown, but this gaves a flickering effect.

> >  System.Drawing.Size mySize = test.ClientSize;
> >  test.Show();
> >  test.ClientSize = mySize;
> >  test.Size = mySize;

> >Why does Show() change the size of a Form? I would call
> this a bug.

> >Depressed

> >  Christian

> >.

 
 
 

Bug: System.Windows.Forms.Form.Show()

Post by Avi Nah » Fri, 08 Mar 2002 00:26:00


Similar here. Maybe instead of resizing after show which causes
flicker, try to initially set it to transparent, show, change size and
make non-transparent.

Avi

 
 
 

1. Windows.System.Forms.MessageBox.Show call and AfxOleInit

I have a .NET assembly with a COM wrapper.  My MFC
application calls it using smart pointers generated by
#importing the typelib generated from the assembly.  I
have a function in my assembly that calls
Windows.System.Forms.MessageBox.Show().  If I initialize
COM in my MFC application by using AfxOleInit and call the
function containing the MessageBox call, when I close the
app I get a debug assertion in the cmdtarg.cpp in the
destructor:
CCmdTarget::~CCmdTarget()
{
#ifndef _AFX_NO_OLE_SUPPORT
        if (m_xDispatch.m_vtbl != 0)
                ((COleDispatchImpl*)&m_xDispatch)-
        ASSERT(m_dwRef <= 1);
#endif
#ifdef _AFXDLL
        m_pModuleState = NULL;
#endif

on the "ASSERT(m_dwRef <= 1)" because m_dwRef = 2.

If however, I do not call AfxOleInit, and instead use
CoInitializeEx and CoUninitialize everything is fine.

Or, if I call other functions in my assembly that do not
create a message box things are fine too.

Also, AfxOleInit works fine if instead of calling the .NET
framework's MessageBox.Show I do a DllImport of the
Windows SDK MessageBox() function as follows and call that
MessageBox function:

    [DllImport("user32.dll")]
    public static extern int MessageBox(int hWnd, string
lpText, string lpCaption, int uType);

The problem seems to be the combination of AfxOleInit and
the call to the .NET MessageBox function.  Since this
assembly may be used by a number of existing applications
that are initialized with AfxOleInit, I need to be able to
have this work.  Does anyone have any idea what the
problem is and how to fix it?  Thanks in advance...

2. Active Directory Hangs

3. MISSING: System.Windows.Forms.dll, System.Data.DLL,system.drawing.dll

4. Max Tempo

5. BUG in System.Windows.Form.ComboBox.Text

6. IBM MQseries 2.1 character set conversion problem.

7. Bug in System.Windows.Forms.PageSetupDialog

8. Evaluation key!! *URGENT*

9. Is there no System.Windows.Forms.Form.Invoke?

10. System.Windows.Forms.Form.Handle

11. System.Windows.Forms.Form.MinimumSize has no effect

12. Datagrid generates System.NullReferenceException in System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW

13. Inheriting from Forms other than System.Windows.Forms.Form