By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,873 Members | 1,040 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,873 IT Pros & Developers. It's quick & easy.

Fixed aspect size when form is resized

P: n/a
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

Nov 15 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
hi ron
just use the Dock-Property on the Control :-)
cheers Jazper
"Ron Vecchi" <rv*****@xilehdvecchi.com> schrieb im Newsbeitrag
news:Ol**************@TK2MSFTNGP12.phx.gbl...
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

Nov 15 '05 #2

P: n/a
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
"Jazper" <j.***@bluewin.ch> wrote in message
news:e$**************@TK2MSFTNGP11.phx.gbl...
hi ron
just use the Dock-Property on the Control :-)
cheers Jazper
"Ron Vecchi" <rv*****@xilehdvecchi.com> schrieb im Newsbeitrag
news:Ol**************@TK2MSFTNGP12.phx.gbl...
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


Nov 15 '05 #3

P: n/a

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" <rv*****@xilehdvecchi.com>
| References: <Ol**************@TK2MSFTNGP12.phx.gbl>
<e$**************@TK2MSFTNGP11.phx.gbl>
| 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: <#l**************@tk2msftngp13.phx.gbl>
| 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!tk2msftn gp13.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
|
|
| "Jazper" <j.***@bluewin.ch> wrote in message
| news:e$**************@TK2MSFTNGP11.phx.gbl...
| > hi ron
| > just use the Dock-Property on the Control :-)
| > cheers Jazper
| >
| >
| > "Ron Vecchi" <rv*****@xilehdvecchi.com> schrieb im Newsbeitrag
| > news:Ol**************@TK2MSFTNGP12.phx.gbl...
| > > 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
| > >
| > >
| > >
| >
| >
|
|
|

Nov 15 '05 #4

P: n/a

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: v-*****@online.microsoft.com ("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" <rv*****@xilehdvecchi.com>
| | References: <Ol**************@TK2MSFTNGP12.phx.gbl>
| <e$**************@TK2MSFTNGP11.phx.gbl>
| | 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: <#l**************@tk2msftngp13.phx.gbl>
| | 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!tk2msftn gp13.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
| |
| |
| | "Jazper" <j.***@bluewin.ch> wrote in message
| | news:e$**************@TK2MSFTNGP11.phx.gbl...
| | > hi ron
| | > just use the Dock-Property on the Control :-)
| | > cheers Jazper
| | >
| | >
| | > "Ron Vecchi" <rv*****@xilehdvecchi.com> schrieb im Newsbeitrag
| | > news:Ol**************@TK2MSFTNGP12.phx.gbl...
| | > > 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
| | > >
| | > >
| | > >
| | >
| | >
| |
| |
| |
|

Nov 15 '05 #5

P: n/a
Thanks Jeffery that helped alot

Ron
""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> wrote in message
news:HV**************@cpmsftngxa06.phx.gbl...

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" <rv*****@xilehdvecchi.com>
| References: <Ol**************@TK2MSFTNGP12.phx.gbl>
<e$**************@TK2MSFTNGP11.phx.gbl>
| 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: <#l**************@tk2msftngp13.phx.gbl>
| 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!tk2msftn gp13.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
|
|
| "Jazper" <j.***@bluewin.ch> wrote in message
| news:e$**************@TK2MSFTNGP11.phx.gbl...
| > hi ron
| > just use the Dock-Property on the Control :-)
| > cheers Jazper
| >
| >
| > "Ron Vecchi" <rv*****@xilehdvecchi.com> schrieb im Newsbeitrag
| > news:Ol**************@TK2MSFTNGP12.phx.gbl...
| > > 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
| > >
| > >
| > >
| >
| >
|
|
|

Nov 15 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.