473,386 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Fixed aspect size when form is resized

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
5 10096
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
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

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

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: adawson | last post by:
Hi, I need to execute some code when form submission is stopped before the page is returned from the server. For example, a user clicks a button to submit the form, realizes they've made a...
7
by: sql-db2-dba | last post by:
Does DB2 just fudge it when it is an empty table? Is there a "formula" for average row size when you have variable length records. Or you really have to know what your application is packing into...
1
by: SleepSheep | last post by:
two struct in c# public class A { int i1; byte i2; }
2
by: abid gee | last post by:
Please give a kind look on my question. and please comments. I am Using C# as development tool of Dot Net 2.0. I wrote a function read_data() that read data from Serial Port continuously.Till...
0
by: whezker | last post by:
Hi, I'm writing code for design the visual apereance of a Label. My problem comes from, when I set a Property that depends of the control size. When I run the form, the set property compares the...
3
by: Alexio | last post by:
I need to enter a date into a text field when form is loaded. However I need this date to be static when the form is opened at a later date. I have the text box set to readonly. Will this be...
1
by: maximus tee | last post by:
hi, i'm using Python 2.5 and Windows XP. i'm wondering whether is a way to enlarge the font size when print out to CMD window. For eg: print "Hello World". It will print out with standard size in...
3
HaLo2FrEeEk
by: HaLo2FrEeEk | last post by:
I'm overriding the WM_SIZE message so that I can lock my form into a specific aspect ratio. I'm allowing the user to turn on and off aspect ratio locking by toggling a checkbox. So far resizing by...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.