Locking window size and position

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Using .NET 2.0, I would like to lock my form derived window size and position
(it is not full screen and extends to the bottom) so it does not move when
the auto-hide task bar property is turned off.

Any ideas?

Thanks,
Ken
 
You don't want user to move your form? Why?
Do you think user has no right to locate it as s/he wants?

Anyway, you can hide borders and title bar, so user won't have anything to
grab on. Then it won't move

HTH
Alex
 
We have a touch screen application (using the whole screen) running on the XP
OS on our hardware. It is not targeted for standard desktop configurations.

Turning the border and title bar off ( FormBorderStyle = None) does not
prevent the form from moving when it overlaps the taskbar area.

Ken
 
Then you can handle Move event and Resize event (EndResizing) restoring
required position and size
 
But hasn't the form already moved and resized by the time we get those
events? I tried changing the location in these events and it does move to
the right position, but I see it move to the other position first.

I am considering catching the WM_WINDOWPOSCHANGING message and setting the y
coordinate to my desired location before it gets processed by the base. I am
not sure I can programmatically prevent the taskbar grab line from showing
when my window does not take the whole screen and I would prefer not to
disable it for the whole system (maintenance guys do use other apps).
 
You can set a form's MaximumSize and MinimumSize sizes to some value
which will lock it in place.

You can prevent the user rom grabbing the window by overriding the
WndProc and stopping WM_NCHITTEST from responding.

You may also wish to run the code in kiosk mode by not loading Explorer
at startup but running your own application. In this case the desktop
will not exist but all windows services and API's will still function.

In this case, or maybe in all cases, force the app to run maximised.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Setting the MaximumSize and MinimumSize do not lock the window in position.
Changing the autohide property to false and applying it still moves my
window.

I can't prevent the user from grabbing the window by overriding the WndProc
and stopping the WM_NCHITTEST from responding because the taskbar is not my
code (am I not understanding your suggestion?).

I have been able to prevent the moving of my window by overriding the
WndProc and resetting the location to what I desire before passing it back on
along the message path. The grab bar is still there and shows the task bar
when grabbed.

However, I think I actually want to hide the grab bar. I can
programmatically hide it, but I think I may have some problems because we
have several apps and since we don't have a keyboard (touchscreen) it can be
difficult to get the taskbar back if the apps don't shut down properly.

The only way I have been able to hide the grab bar, is with an application
that takes up the full screen and is not resizable (which is the way our apps
used to work). Now we have a single navigation app that takes the top of the
screen and multiple apps that sit below it.

Thanks for your help,

Ken
 
Back
Top