Solved

Help with Form.Resize event (C#)

Posted on 2008-10-25
4
2,430 Views
Last Modified: 2013-12-17
I have a dilema I cannot seem to solve. I am trying to keep a form resizable, but I want to force it to keep a size ratio of 4:3 no matter how big or small the form gets. I am ok with creating the event I am just not sure the logic behind doing this. I have not found a good way to disable form resizing. I know I can change the FormBorderStyle so that the resizing becomes disabled, however each one of those options makes the form look slightly different by adjusting the size of the forms border, etc (at least in vista). So this makes the form look very clunky when resizing. If someone could provide me with a solution in example form I would appreciate it.
0
Comment
Question by:Pretzel_Jesus
  • 2
4 Comments
 
LVL 26

Accepted Solution

by:
Anurag Thakur earned 500 total points
ID: 22803088
not a direct solution but i found a sample code how this can be done
please read teh following link
http://bytes.com/forum/thread231885.html
0
 
LVL 18

Expert Comment

by:Priest04
ID: 22803404
A simple way to disable form resising without changing form appearance is to set Form's MaximiumSize and MinimumSize property to the same value (desired size).


As for hte 4:3 aspect ratio a simple

private void Form1_Resize(object sender, EventArgs e)
{
    this.Width = this.Height * (4 / 3);
}

will work, but will cause some flickering. If you don't like the flickering the only other way (AFAIK) is to subclass WM_SIZE message.

Goran
0
 

Author Comment

by:Pretzel_Jesus
ID: 22804635
Your code is much simpler than mine, but I accomplished basically the same thing:

if (videoForm.Size.Height >= Convert.ToInt32(videoForm.Size.Width * .75))
            {
                videoForm.Height = Convert.ToInt32(videoForm.Width * .75);
            }
            else if (videoForm.Size.Width >= Convert.ToInt32(videoForm.Size.Height / .75))
            {
                videoForm.Height = Convert.ToInt32(videoForm.Width * .75);
            }

My problem is exactly what you said... massive flicking and it looks like shit. Since I am fairly new to C# I really have no idea how to "subclass WM_SIZE message.". Can you give me an example of how I could accomplish this?
0
 
LVL 18

Expert Comment

by:Priest04
ID: 22805265
Follow the link ragi posted, there you have explanation how to implement subclassing of WM_SIZING. If you dont succeed in implementing it, post here and I (or someone else) will explain.
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question