Sizing form...

M

Me

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);
}

..
 
T

Tom Clement

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.
 
G

Gabriele G. Ponti

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
 
T

Tom Clement

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
 
M

Me

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
 
M

Me

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 believe this is what he
was


.
 
M

Me

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
 
G

Gregg Walker

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

Gregg
 
G

Gabriele G. Ponti

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top