How Do I Prevent Form Resizing

J

John Bowman

Hi All,

I must be missing something really obvious, so I'd appreciate someone
helping me out. I have a simple Windows form that currently only has a title
bar (aka the Text Property is set) and the MinmizeBox, ControlBox and
MaximizeBox(es) are all set to false. It's FormBorderStyle is set to "Fixed
Single". Eventually this form will have a nice background image. I need to
use this form as sort of back drop while other forms/operations appear
during application use in front of this form, so this Form is initially
displayed with the "Show" method so it's not modal. Here's the problem:
everything initally appears as expected, but the user can still double click
on the title bar of this back drop form and it still resizes. It's set to
FixedSingle, why is it still resizing and how do I prevent this? It's OK if
they can drag the title bar to move the back drop form, but resizing is
considerd a no-no for this app. What am I missing here?

TIA,
 
N

Nicholas Paldino [.NET/C# MVP]

John,

There are a few ways I can see going about this.

The first would be to override the OnResize method on your form. Do NOT
call the base class implementation, and that might prevent the form from
being resized.

If that doesn't work, you can set the MaximumSize and MinimumSize
properties to the same size, and that shouldn't allow a resize of any kind
to occur.

As a last resort, you can handle the WM_NCLBUTTONDBLCLK windows message
in an overridden WndProc procedure, and do nothing when you process it (this
is sent when a non-client double click occurs, like on the frame, or title
part of the window).

Hope this helps.
 
J

John Bowman

Nicholas,

Thanks for the fast response. I think I just figured out how to solve this.
After thinking about the MinimumSize & MaximumSize you mentioned, I
discoevered something. First of all, I foundI had the form's WindowState set
to Maxmize. Once I set that back to Normal, it started behaving like every
other form I've ever worked with. Then I put some code into it's constructor
just after the call to InitializeComponent() to make the back drop fill the
available screen, but still allow access to the taskbar... even if it's
autohidden. Here's the temp code that I put in there. Obviously, this code
can be modified to set the back drop's size & location to some other more
desirable fixed size & location.


Point NewLoc = Screen.FromControl(this).WorkingArea.Location;
//Modifiy the location so any toolbars & taskbar can be easily accessed.
NewLoc.X += 1;
NewLoc.Y += 1;
this.Location = NewLoc;

Size NewSize = Screen.FromControl(this).WorkingArea.Size;
//Modifiy the size so any toolbars & taskbar can be easily accessed.
NewSize.Height -= 1;
NewSize.Width -= 1;
this.Size = NewSize;

this.MinimumSize = this.Size;
this.MaximumSize = this.MinimumSize;


Thanks for the help.

John

Nicholas Paldino said:
John,

There are a few ways I can see going about this.

The first would be to override the OnResize method on your form. Do
NOT call the base class implementation, and that might prevent the form
from being resized.

If that doesn't work, you can set the MaximumSize and MinimumSize
properties to the same size, and that shouldn't allow a resize of any kind
to occur.

As a last resort, you can handle the WM_NCLBUTTONDBLCLK windows message
in an overridden WndProc procedure, and do nothing when you process it
(this is sent when a non-client double click occurs, like on the frame, or
title part of the window).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

John Bowman [email protected]> said:
Hi All,

I must be missing something really obvious, so I'd appreciate someone
helping me out. I have a simple Windows form that currently only has a
title bar (aka the Text Property is set) and the MinmizeBox, ControlBox
and MaximizeBox(es) are all set to false. It's FormBorderStyle is set to
"Fixed Single". Eventually this form will have a nice background image. I
need to use this form as sort of back drop while other forms/operations
appear during application use in front of this form, so this Form is
initially displayed with the "Show" method so it's not modal. Here's the
problem: everything initally appears as expected, but the user can still
double click on the title bar of this back drop form and it still
resizes. It's set to FixedSingle, why is it still resizing and how do I
prevent this? It's OK if they can drag the title bar to move the back
drop form, but resizing is considerd a no-no for this app. What am I
missing here?

TIA,

--
John C. Bowman
Software Engineer
Thermo Electron Scientific Instruments Div.
<Remove this before reply> (e-mail address removed)
 
R

Richard Blewett [DevelopMentor]

John Bowman [email protected]> said:
Hi All,

I must be missing something really obvious, so I'd appreciate someone
helping me out. I have a simple Windows form that currently only has a
title bar (aka the Text Property is set) and the MinmizeBox, ControlBox
and MaximizeBox(es) are all set to false. It's FormBorderStyle is set to
"Fixed Single". Eventually this form will have a nice background image. I
need to use this form as sort of back drop while other forms/operations
appear during application use in front of this form, so this Form is
initially displayed with the "Show" method so it's not modal. Here's the
problem: everything initally appears as expected, but the user can still
double click on the title bar of this back drop form and it still resizes.
It's set to FixedSingle, why is it still resizing and how do I prevent
this? It's OK if they can drag the title bar to move the back drop form,
but resizing is considerd a no-no for this app. What am I missing here?

TIA,

--
John C. Bowman
Software Engineer
Thermo Electron Scientific Instruments Div.
<Remove this before reply> (e-mail address removed)

Just set the MaximizeBox property to false on the form - then it can't be
maximized

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk
 
J

John Bowman

Richard,

It would appear you didn't read my post completely. I already did that. Read
my previous post to learn the solution.

John

"Richard Blewett [DevelopMentor]" <richard at nospam dotnetconsult dot co
dot uk> wrote in message news:%[email protected]...
 
R

Richard Blewett [DevelopMentor]

John Bowman [email protected]> said:
Richard,

It would appear you didn't read my post completely. I already did that.
Read my previous post to learn the solution.

John

"Richard Blewett [DevelopMentor]" <richard at nospam dotnetconsult dot co
dot uk> wrote in message news:%[email protected]...
Just set the MaximizeBox property to false on the form - then it can't be
maximized

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

Sorry John,

I missed that bit but I tested the same config on my machine and it worked
as you wanted. I cannot double click on the title bar and make it resize.

I'm using version 2.0, I don;t have a 1.1 environment to hand to test
whether it was a bug in 1.1 that has been fixed in 2.0.

Can you create a vanilla winforms app and set the MaximizeBox property to
false and test?

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk
 
J

John Bowman

Richard,

Thanks again for looking into this. See my post: 10/24/2005 9:51 am CDT for
my resolution of the problem. The crux of it was that the WindowState
property was set to Maximize. This causes the undesirable behavior. When I
set it to Normal, everything went back to working as expected.

John

"Richard Blewett [DevelopMentor]" <richard at nospam dotnetconsult dot co
dot uk> wrote in message news:%[email protected]...
John Bowman [email protected]> said:
Richard,

It would appear you didn't read my post completely. I already did that.
Read my previous post to learn the solution.

John

"Richard Blewett [DevelopMentor]" <richard at nospam dotnetconsult dot co
dot uk> wrote in message news:%[email protected]...
"John Bowman (e-mail address removed)>" <<Remove this before reply> wrote
in message Hi All,

I must be missing something really obvious, so I'd appreciate someone
helping me out. I have a simple Windows form that currently only has a
title bar (aka the Text Property is set) and the MinmizeBox, ControlBox
and MaximizeBox(es) are all set to false. It's FormBorderStyle is set
to "Fixed Single". Eventually this form will have a nice background
image. I need to use this form as sort of back drop while other
forms/operations appear during application use in front of this form,
so this Form is initially displayed with the "Show" method so it's not
modal. Here's the problem: everything initally appears as expected, but
the user can still double click on the title bar of this back drop form
and it still resizes. It's set to FixedSingle, why is it still resizing
and how do I prevent this? It's OK if they can drag the title bar to
move the back drop form, but resizing is considerd a no-no for this
app. What am I missing here?

TIA,

--
John C. Bowman
Software Engineer
Thermo Electron Scientific Instruments Div.
<Remove this before reply> (e-mail address removed)


Just set the MaximizeBox property to false on the form - then it can't
be maximized

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

Sorry John,

I missed that bit but I tested the same config on my machine and it worked
as you wanted. I cannot double click on the title bar and make it resize.

I'm using version 2.0, I don;t have a 1.1 environment to hand to test
whether it was a bug in 1.1 that has been fixed in 2.0.

Can you create a vanilla winforms app and set the MaximizeBox property to
false and test?

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk
 

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