Fixed aspect size when form is resized

R

Ron Vecchi

I know the math I need to perform on width and height to keep an aspect
ratio but where and how would I implement keeping a set aspect ratio on a
form when a user resizes it. Override OnResize? couldn't quite figure it
out.
 
R

Ron Vecchi

I dont see how this will help with keeping the form a fixed aspect ratio.


When the form starts up lets say it is 800x400, an aspect of 2/1
I have the FormBorderStyle set to sizable.

Symotaneously as the user is sizing the form I would like to check the width
and keep the height excaly half of the value of the width. keeping the
aspect ratio of 2/1

Im I missing something with using the Dock property?

Thanks
Ron Vecchi
 
J

Jeffrey Tan[MSFT]

Hi Ron,

Thanks for posting in this group.
If you just set the aspect ratio in the form_resize or form_sizechanged
event, this may partially meet your need.
But the form will resize with its size "flashing". This is because, when
you set the height width ratio in the event, windows will resend WM_SIZE
message to the form, which will make the form resize again, then the form
will flashing size.
I think to workaround this, you should hook its WM_SIZING message and
change some fields.
Here is the sample code:(I wanna keep the width and height to the same
value)

[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
public const int WM_SIZING = 0x0214;
static int org_size=0;
protected override void WndProc(ref Message m)
{
if(m.Msg==WM_SIZING)
{
RECT rc;
rc=(RECT)Marshal.PtrToStructure(m.LParam, typeof(RECT));

if(rc.Right-rc.Left!=org_size)
{
rc.Bottom =rc.Right -rc.Left+rc.Top;
Marshal.StructureToPtr(rc,m.LParam ,true);
}
else
{
rc.Right=rc.Bottom-rc.Top +rc.Left ;
Marshal.StructureToPtr(rc,m.LParam ,true);
}
org_size=rc.Right -rc.Left ;
}

base.WndProc (ref m);
}

In this sample, I create a static variable org_size to store the origial
form width.
Then in the WM_SIZING message, we will determine if it is the width
change(height follow width) or the height change(width follow height).
It works well on my machine, if you still have any question, please feel
free to let me know.

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.

--------------------
| From: "Ron Vecchi" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: Re: Fixed aspect size when form is resized
| Date: Wed, 12 Nov 2003 23:53:19 -0500
| Lines: 43
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.3790.0
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: pcp02828467pcs.roylok01.mi.comcast.net 68.85.156.233
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:198899
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| I dont see how this will help with keeping the form a fixed aspect ratio.
|
|
| When the form starts up lets say it is 800x400, an aspect of 2/1
| I have the FormBorderStyle set to sizable.
|
| Symotaneously as the user is sizing the form I would like to check the
width
| and keep the height excaly half of the value of the width. keeping the
| aspect ratio of 2/1
|
| Im I missing something with using the Dock property?
|
| Thanks
| Ron Vecchi
|
|
| | > hi ron
| > just use the Dock-Property on the Control :)
| > cheers Jazper
| >
| >
| > | > > I know the math I need to perform on width and height to keep an
aspect
| > > ratio but where and how would I implement keeping a set aspect ratio
on
| a
| > > form when a user resizes it. Override OnResize? couldn't quite figure
it
| > > out.
| > >
| > >
| > >
| > >
| > > --
| > > Ron Vecchi
| > >
| > >
| > >
| >
| >
|
|
|
 
J

Jeffrey Tan[MSFT]

Hi Ron,

The WM_SIZING value can be found in C:\Program Files\Microsoft Visual
Studio\VC98\Include\WINUSER.H

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.

--------------------
| Newsgroups: microsoft.public.dotnet.languages.csharp
| From: (e-mail address removed) ("Jeffrey Tan[MSFT]")
| Organization: Microsoft
| Date: Thu, 13 Nov 2003 07:17:25 GMT
| Subject: Re: Fixed aspect size when form is resized
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
|
|
| Hi Ron,
|
| Thanks for posting in this group.
| If you just set the aspect ratio in the form_resize or form_sizechanged
| event, this may partially meet your need.
| But the form will resize with its size "flashing". This is because, when
| you set the height width ratio in the event, windows will resend WM_SIZE
| message to the form, which will make the form resize again, then the form
| will flashing size.
| I think to workaround this, you should hook its WM_SIZING message and
| change some fields.
| Here is the sample code:(I wanna keep the width and height to the same
| value)
|
| [StructLayout(LayoutKind.Sequential)]
| public struct RECT
| {
| public int Left;
| public int Top;
| public int Right;
| public int Bottom;
| }
| public const int WM_SIZING = 0x0214;
| static int org_size=0;
| protected override void WndProc(ref Message m)
| {
| if(m.Msg==WM_SIZING)
| {
| RECT rc;
| rc=(RECT)Marshal.PtrToStructure(m.LParam, typeof(RECT));
|
| if(rc.Right-rc.Left!=org_size)
| {
| rc.Bottom =rc.Right -rc.Left+rc.Top;
| Marshal.StructureToPtr(rc,m.LParam ,true);
| }
| else
| {
| rc.Right=rc.Bottom-rc.Top +rc.Left ;
| Marshal.StructureToPtr(rc,m.LParam ,true);
| }
| org_size=rc.Right -rc.Left ;
| }
|
| base.WndProc (ref m);
| }
|
| In this sample, I create a static variable org_size to store the origial
| form width.
| Then in the WM_SIZING message, we will determine if it is the width
| change(height follow width) or the height change(width follow height).
| It works well on my machine, if you still have any question, please feel
| free to let me know.
|
| 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.
|
| --------------------
| | From: "Ron Vecchi" <[email protected]>
| | References: <[email protected]>
| <[email protected]>
| | Subject: Re: Fixed aspect size when form is resized
| | Date: Wed, 12 Nov 2003 23:53:19 -0500
| | Lines: 43
| | X-Priority: 3
| | X-MSMail-Priority: Normal
| | X-Newsreader: Microsoft Outlook Express 6.00.3790.0
| | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| | Message-ID: <#[email protected]>
| | Newsgroups: microsoft.public.dotnet.languages.csharp
| | NNTP-Posting-Host: pcp02828467pcs.roylok01.mi.comcast.net 68.85.156.233
| | Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| | Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.languages.csharp:198899
| | X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| |
| | I dont see how this will help with keeping the form a fixed aspect
ratio.
| |
| |
| | When the form starts up lets say it is 800x400, an aspect of 2/1
| | I have the FormBorderStyle set to sizable.
| |
| | Symotaneously as the user is sizing the form I would like to check the
| width
| | and keep the height excaly half of the value of the width. keeping the
| | aspect ratio of 2/1
| |
| | Im I missing something with using the Dock property?
| |
| | Thanks
| | Ron Vecchi
| |
| |
| | | | > hi ron
| | > just use the Dock-Property on the Control :)
| | > cheers Jazper
| | >
| | >
| | > | | > > I know the math I need to perform on width and height to keep an
| aspect
| | > > ratio but where and how would I implement keeping a set aspect
ratio
| on
| | a
| | > > form when a user resizes it. Override OnResize? couldn't quite
figure
| it
| | > > out.
| | > >
| | > >
| | > >
| | > >
| | > > --
| | > > Ron Vecchi
| | > >
| | > >
| | > >
| | >
| | >
| |
| |
| |
|
 
R

Ron Vecchi

Thanks Jeffery that helped alot

Ron
"Jeffrey Tan[MSFT]" said:
Hi Ron,

Thanks for posting in this group.
If you just set the aspect ratio in the form_resize or form_sizechanged
event, this may partially meet your need.
But the form will resize with its size "flashing". This is because, when
you set the height width ratio in the event, windows will resend WM_SIZE
message to the form, which will make the form resize again, then the form
will flashing size.
I think to workaround this, you should hook its WM_SIZING message and
change some fields.
Here is the sample code:(I wanna keep the width and height to the same
value)

[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
public const int WM_SIZING = 0x0214;
static int org_size=0;
protected override void WndProc(ref Message m)
{
if(m.Msg==WM_SIZING)
{
RECT rc;
rc=(RECT)Marshal.PtrToStructure(m.LParam, typeof(RECT));

if(rc.Right-rc.Left!=org_size)
{
rc.Bottom =rc.Right -rc.Left+rc.Top;
Marshal.StructureToPtr(rc,m.LParam ,true);
}
else
{
rc.Right=rc.Bottom-rc.Top +rc.Left ;
Marshal.StructureToPtr(rc,m.LParam ,true);
}
org_size=rc.Right -rc.Left ;
}

base.WndProc (ref m);
}

In this sample, I create a static variable org_size to store the origial
form width.
Then in the WM_SIZING message, we will determine if it is the width
change(height follow width) or the height change(width follow height).
It works well on my machine, if you still have any question, please feel
free to let me know.

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.

--------------------
| From: "Ron Vecchi" <[email protected]>
| References: <[email protected]>
<[email protected]>
| Subject: Re: Fixed aspect size when form is resized
| Date: Wed, 12 Nov 2003 23:53:19 -0500
| Lines: 43
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.3790.0
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: pcp02828467pcs.roylok01.mi.comcast.net 68.85.156.233
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:198899
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| I dont see how this will help with keeping the form a fixed aspect ratio.
|
|
| When the form starts up lets say it is 800x400, an aspect of 2/1
| I have the FormBorderStyle set to sizable.
|
| Symotaneously as the user is sizing the form I would like to check the
width
| and keep the height excaly half of the value of the width. keeping the
| aspect ratio of 2/1
|
| Im I missing something with using the Dock property?
|
| Thanks
| Ron Vecchi
|
|
| | > hi ron
| > just use the Dock-Property on the Control :)
| > cheers Jazper
| >
| >
| > | > > I know the math I need to perform on width and height to keep an
aspect
| > > ratio but where and how would I implement keeping a set aspect ratio
on
| a
| > > form when a user resizes it. Override OnResize? couldn't quite figure
it
| > > out.
| > >
| > >
| > >
| > >
| > > --
| > > Ron Vecchi
| > >
| > >
| > >
| >
| >
|
|
|
 

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