Sizing form...

Discussion in 'Microsoft Dot NET Framework' started by Me, Dec 4, 2003.

  1. Me

    Me Guest

    Why won't my form shrink down to a smaller size?

    Here is the code:

    private void InitializeComponent()
    {
    //
    // Form1
    //
    this.AutoScaleBaseSize = new
    System.Drawing.Size(200, 200);
    this.ClientSize = new
    System.Drawing.Size(200, 200);
    this.ControlBox = false;
    this.FormBorderStyle =
    System.Windows.Forms.FormBorderStyle.FixedSingle;
    this.Location = new
    System.Drawing.Point(10, 10);
    this.MaximizeBox = false;
    this.MinimizeBox = false;
    this.Name = "Form1";
    this.StartPosition =
    System.Windows.Forms.FormStartPosition.Manual;

    }





    protected override void OnMouseDown
    (MouseEventArgs e)
    {
    System.Drawing.Size x;
    x = this.ClientSize;
    x = this.Size;

    this.Height = 5;
    this.Width = 300;

    x = this.ClientSize;
    x = this.Size;

    base.OnMouseDown (e);
    }

    ..
     
    Me, Dec 4, 2003
    #1
    1. Advertisements

  2. Gabriele G. Ponti, Dec 4, 2003
    #2
  3. Me

    Me Guest

    Isn't there a C# method for doing this?

    Thanks


    >-----Original Message-----
    >Hi,
    >
    >Windows sends the WM_GETMINMAXINFO message to your

    window when the size is
    >about to change. By implementing your own window

    procedure and handling this
    >message you can change the minimum dimensions allowed.
    >
    >For more information please see the following document:
    >
    >WM_GETMINMAXINFO Notification
    >http://msdn.microsoft.com/library/en-

    us/winui/WinUI/WindowsUserInterface/Windowing/Windows/Wind
    owReference/WindowMessages/WM_GETMINMAXINFO.asp
    >
    >Regards,
    >
    > Gabriele
    >
    >
    >.
    >
     
    Me, Dec 4, 2003
    #3
  4. Not that I know.
     
    Gabriele G. Ponti, Dec 4, 2003
    #4
  5. Me

    Tom Clement Guest

    Your code works fine for me. When I click on the form, it resizes as
    expected.

    This thread is a bit confusing to me, since one responder seemed to think
    you were asking about setting the minimum size for a form. You do not need
    to handle the window message to do this. As you might expect, you can just
    set the MinimumSize and MaximumSize properties on the form.

    Tom Clement
    Apptero, Inc.


    "Me" <> wrote in message
    news:098f01c3ba72$089c3980$...
    > Why won't my form shrink down to a smaller size?
    >
    > Here is the code:
    >
    > private void InitializeComponent()
    > {
    > //
    > // Form1
    > //
    > this.AutoScaleBaseSize = new
    > System.Drawing.Size(200, 200);
    > this.ClientSize = new
    > System.Drawing.Size(200, 200);
    > this.ControlBox = false;
    > this.FormBorderStyle =
    > System.Windows.Forms.FormBorderStyle.FixedSingle;
    > this.Location = new
    > System.Drawing.Point(10, 10);
    > this.MaximizeBox = false;
    > this.MinimizeBox = false;
    > this.Name = "Form1";
    > this.StartPosition =
    > System.Windows.Forms.FormStartPosition.Manual;
    >
    > }
    >
    >
    >
    >
    >
    > protected override void OnMouseDown
    > (MouseEventArgs e)
    > {
    > System.Drawing.Size x;
    > x = this.ClientSize;
    > x = this.Size;
    >
    > this.Height = 5;
    > this.Width = 300;
    >
    > x = this.ClientSize;
    > x = this.Size;
    >
    > base.OnMouseDown (e);
    > }
    >
    > .
    >
    >
     
    Tom Clement, Dec 4, 2003
    #5
  6. Tom,

    MinimumSize and MaximumSize work fine, but they don't allow you to shrink
    the window less than the size of the caption. I believe this is what he was
    looking for.

    Gabriele
     
    Gabriele G. Ponti, Dec 4, 2003
    #6
  7. Me

    Tom Clement Guest

    Gabriele,
    Ah, I see. That's good to know.

    From the code he provided, it appears that the form is
    BorderStyle.FixedSingle, which does not have a caption, so I'm not sure what
    the problem is. I did run his code and it changed the form size as he
    seemed to expect.

    Tom


    "Gabriele G. Ponti" <ggponti.at.hotmail.com> wrote in message
    news:OO$...
    > Tom,
    >
    > MinimumSize and MaximumSize work fine, but they don't allow you to shrink
    > the window less than the size of the caption. I believe this is what he

    was
    > looking for.
    >
    > Gabriele
    >
    >
     
    Tom Clement, Dec 5, 2003
    #7
  8. Me

    Me Guest

    So... if you cannot size the form smaller than
    the size of the caption... is there a form that I can use
    that does not have this restriction?

    I have done the WM_GETMINMAXINFO "work around" and wierd
    stuff starts happening to the form when you shrink it
    really small for example: you can only size "up" some
    times and other times you can only size "down".

    With a Win32 window you can make it any size you desire,
    without restrictions... is a form an analogous entity as
    a window ?

    Thanks
    Me

    >-----Original Message-----
    >Gabriele,
    >Ah, I see. That's good to know.
    >
    >From the code he provided, it appears that the form is
    >BorderStyle.FixedSingle, which does not have a caption,

    so I'm not sure what
    >the problem is. I did run his code and it changed the

    form size as he
    >seemed to expect.
    >
    >Tom
    >
    >
    >"Gabriele G. Ponti" <ggponti.at.hotmail.com> wrote in

    message
    >news:OO$...
    >> Tom,
    >>
    >> MinimumSize and MaximumSize work fine, but they don't

    allow you to shrink
    >> the window less than the size of the caption. I

    believe this is what he
    >was
    >> looking for.
    >>
    >> Gabriele
    >>
    >>

    >
    >
    >.
    >
     
    Me, Dec 5, 2003
    #8
  9. Me

    Me Guest

    The form shrunk down to 5 pixels in size ?

    Me

    >-----Original Message-----
    >Gabriele,
    >Ah, I see. That's good to know.
    >
    >From the code he provided, it appears that the form is
    >BorderStyle.FixedSingle, which does not have a caption,

    so I'm not sure what
    >the problem is. I did run his code and it changed the

    form size as he
    >seemed to expect.
    >
    >Tom
    >
    >
    >"Gabriele G. Ponti" <ggponti.at.hotmail.com> wrote in

    message
    >news:OO$...
    >> Tom,
    >>
    >> MinimumSize and MaximumSize work fine, but they don't

    allow you to shrink
    >> the window less than the size of the caption. I

    believe this is what he
    >was
    >> looking for.
    >>
    >> Gabriele
    >>
    >>

    >
    >
    >.
    >
     
    Me, Dec 5, 2003
    #9
  10. Me

    Me Guest

    Ok... here is what I have done....


    Near the top of my Form:

    using System.Runtime.InteropServices; // Marshal

    //Declare wrapper managed POINT class.
    [ StructLayout (LayoutKind.Sequential) ]
    public class POINT
    {
    public int x;
    public int y;
    }


    //Declare wrapper managed MouseHookStruct
    class.
    [ StructLayout(LayoutKind.Sequential)]
    public class MinMaxInfoStruct
    {
    public POINT ptReserved;
    public POINT ptMaxSize;
    public POINT ptMaxPosition;
    public POINT ptMinTrackSize;
    public POINT ptMaxTrackSize;
    }








    Inside the form class:


    const int WM_GETMINMAXINFO = 0x0024;

    protected override void WndProc(ref Message m)
    {
    if( m.Msg == WM_GETMINMAXINFO )
    {
    MinMaxInfoStruct info = (MinMaxInfoStruct)
    Marshal.PtrToStructure(m.LParam,
    typeof(MinMaxInfoStruct));

    info.ptMinTrackSize.y = 2;
    Trace.WriteLine( "Y after assignment ",
    info.ptMinTrackSize.y.ToString() );

    int y = info.ptMinTrackSize.y;
    Trace.WriteLine( "Y from 'struct' ", y.ToString() );

    Marshal.StructureToPtr( info, m.LParam, false );
    }

    base.WndProc (ref m);
    }



    Again the mouse routine:

    protected override void OnMouseDown(MouseEventArgs e)
    {
    Trace.WriteLine( "mouse down" );
    System.Drawing.Size x;
    x = this.ClientSize;
    x = this.Size;

    this.Size = new System.Drawing.Size( 400, 1 );

    x = this.ClientSize;
    x = this.Size;
    Trace.WriteLine( "size ", this.Size.ToString() );

    base.OnMouseDown (e);
    }


    Trace output:

    2: Y after assignment
    2: Y from 'struct'
    mouse down
    2: Y after assignment
    2: Y from 'struct'
    {Width=318, Height=38}: size



    What gives?????

    Thanks
    Me
     
    Me, Dec 5, 2003
    #10
  11. Me

    Gregg Walker Guest

    FYI FormBorderStyle.FixedSingle still has a caption. If you want to go
    smaller try FormBorderStyle.None, FormBorderStyle.FixedToolWindow or
    FormBorderStyle.SizableToolWindow.

    Gregg

    "Tom Clement" <> wrote in message
    news:...
    > Gabriele,
    > Ah, I see. That's good to know.
    >
    > From the code he provided, it appears that the form is
    > BorderStyle.FixedSingle, which does not have a caption, so I'm not sure

    what
    > the problem is. I did run his code and it changed the form size as he
    > seemed to expect.
    >
    > Tom
    >
    >
    > "Gabriele G. Ponti" <ggponti.at.hotmail.com> wrote in message
    > news:OO$...
    > > Tom,
    > >
    > > MinimumSize and MaximumSize work fine, but they don't allow you to

    shrink
    > > the window less than the size of the caption. I believe this is what he

    > was
    > > looking for.
    > >
    > > Gabriele
    > >
    > >

    >
    >
     
    Gregg Walker, Dec 5, 2003
    #11
  12. Your code works as long as I set the ControlBox property to false and the
    the Text is empty. Here's my code:

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.Runtime.InteropServices;

    namespace WMGetMinMaxInfoTest
    {
    public class Form1 : System.Windows.Forms.Form
    {
    const int WM_GETMINMAXINFO = 0x24;

    [StructLayout(LayoutKind.Sequential)]
    public class POINT
    {
    public int x;
    public int y;
    }

    [StructLayout(LayoutKind.Sequential)]
    public class MINMAXINFO
    {
    public POINT ptReserved;
    public POINT ptMaxSize;
    public POINT ptMaxPosition;
    public POINT ptMinTrackSize;
    public POINT ptMaxTrackSize;
    }

    private System.ComponentModel.Container components = null;

    public Form1()
    {
    InitializeComponent();
    }

    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    }

    #region Windows Form Designer generated code

    private void InitializeComponent()
    {
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    this.ClientSize = new System.Drawing.Size(248, 205);
    this.ControlBox = false;
    this.Name = "Form1";
    this.Load += new System.EventHandler(this.Form1_Load);
    }
    #endregion

    [STAThread]
    static void Main()
    {
    Application.Run(new Form1());
    }

    protected override void WndProc(ref Message m)
    {
    if(m.Msg == WM_GETMINMAXINFO)
    {
    MINMAXINFO mmi = (MINMAXINFO)Marshal.PtrToStructure(m.LParam,
    typeof(MINMAXINFO));
    mmi.ptMinTrackSize.y = 2;
    Marshal.StructureToPtr(mmi, m.LParam, false);
    m.Result = new IntPtr(0);
    }
    else
    {
    base.WndProc(ref m);
    }
    }

    }
    }

    Regards,

    Gabriele
     
    Gabriele G. Ponti, Dec 5, 2003
    #12

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mart Rogers

    passing arguments from web-form to win-form

    Mart Rogers, Jul 8, 2003, in forum: Microsoft Dot NET Framework
    Replies:
    2
    Views:
    495
    David Boaz
    Jul 8, 2003
  2. Filip Wtterwulghe
    Replies:
    0
    Views:
    346
    Filip Wtterwulghe
    Oct 21, 2003
  3. Serenaiad
    Replies:
    1
    Views:
    245
    Branimir Giurov
    Mar 19, 2004
  4. Daniel

    obtain a reference to a derived form in its base form

    Daniel, Oct 26, 2004, in forum: Microsoft Dot NET Framework
    Replies:
    1
    Views:
    224
    Girish bharadwaj
    Oct 26, 2004
  5. Tom

    Form Sizing Grip

    Tom, Mar 28, 2008, in forum: Microsoft Dot NET Framework
    Replies:
    1
    Views:
    273
    Family Tree Mike
    Mar 28, 2008
Loading...

Share This Page