473,386 Members | 1,924 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.

Fixing form on the screen

If I remove the top band from the form, the form will be fixed on the
screen (you cannot move the form about on the screen). Is there a way to
stop the form from being moved about, whilst retaining the band at the top
of the form?

Thank you.
Patrick.


Nov 15 '05 #1
3 1471
Hi Patrick,
The easiest way, I believe, is to override WndProc and trap WM_NCHITTEST
message. If the hit happens to fall over the caption just fool the windows
that it is somwhere else (or nowhere). This will stop the form from moving
by the mouse. That was easy. Not so easy, though, is to prevent using Move
command from the system menu. The best is to disable that menu item on the
system menu, but this involves dealing with P\Invoke and Win32 API. The
easiest is to swallow SC_MOVE in the WndProc.
So the code for WndProc, I would suggest, is as follows

private int WM_NCHITTEST = 0x0084;
private int HTCAPTION = 2;
private int HTNOWHERE = 0;
private int WM_SYSCOMMAND = 0x0112;
private int SC_MOVE = 0xF010;
protected override void WndProc(ref Message m)
{
if(m.Msg == WM_NCHITTEST)
{
base.WndProc(ref m);
if((int)m.Result == HTCAPTION) m.Result = (IntPtr)HTNOWHERE;
return;
}
else if(m.Msg == WM_SYSCOMMAND && (m.WParam.ToInt32() & 0xFFF0) ==
SC_MOVE)
{
//Swallow the move request from the system menu
m.Result = IntPtr.Zero;
return;
}

base.WndProc (ref m);
}

Now the form is pinned.
--
HTH
B\rgds
100

"Patrick De Ridder" <id***********@all.here> wrote in message
news:10***************@news-01.evisp.enertel.nl...
If I remove the top band from the form, the form will be fixed on the
screen (you cannot move the form about on the screen). Is there a way to
stop the form from being moved about, whilst retaining the band at the top
of the form?

Thank you.
Patrick.

Nov 15 '05 #2

"Stoitcho Goutsev (100) [C# MVP]" <10*@100.com> wrote in message
news:#4*************@tk2msftngp13.phx.gbl...
Hi Patrick,
The easiest way, I believe, is to override WndProc and trap WM_NCHITTEST
...
So the code for WndProc, I would suggest, is as follows

<snipped>


This is truly fantastic.
This is going to make all the difference to my application.
Thank you very much!

Patrick.
Nov 15 '05 #3
I'm glad it works for you :-)

--
B\rgds
100

"Patrick De Ridder" <id***********@all.here> wrote in message
news:10***************@news-01.evisp.enertel.nl...

"Stoitcho Goutsev (100) [C# MVP]" <10*@100.com> wrote in message
news:#4*************@tk2msftngp13.phx.gbl...
Hi Patrick,
The easiest way, I believe, is to override WndProc and trap WM_NCHITTEST
...
So the code for WndProc, I would suggest, is as follows

<snipped>


This is truly fantastic.
This is going to make all the difference to my application.
Thank you very much!

Patrick.

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Nige | last post by:
I've just given one of my sites (www.wealdbroadband.co.uk) an overhaul. Anyone know if there is a way of fixing text at a certain relative position down a page? I'd like the "(c) 2003 ..." notice...
3
by: Scott M | last post by:
Hi, I am currently trying to write a simple game using vb.net the form I am working on is 800*600 (this is set as the maximum size) and autoscroll is set to true. The user moves around the...
11
by: Jozef | last post by:
I have some old code that I use from the Access 95 Developers handbook. The code works very well, with the exception that it doesn't seem to recognize wide screens, and sizes tab controls so that...
5
by: Stan Shankman | last post by:
C# -- Visual Studio.Net – Windows Application Greetings all, How do I copy a Form’s image to a bitmap? – And do so before it gets to the screen. I haven’t been able to find anyone that knows...
0
by: Scott M | last post by:
Hi, I am currently trying to write a simple game using vb.net the form I am working on is 800*600 (this is set as the maximum size) and autoscroll is set to true. The user moves around the...
14
by: Galen Somerville | last post by:
My current screen resolution is set to 1024 x 768. My form size always comes up as 1032 x 748. I have tried the help sample ' Retrieve the working rectangle from the Screen class ' using the...
12
by: > Adrian | last post by:
How do I fix a form on the screen using VS C# 2005. By "fixing" I mean that the user cannot move the form about on the display. Thanks, Adrian.
3
by: Peter Oliphant | last post by:
I'm programming using MS VS VC++ 2008 Express (Beta 2) in /Cli pure mode. I've found the Screen class. With it I can very easily get the count and all the data on the various Screens attached to...
10
by: =?Utf-8?B?UmljaA==?= | last post by:
A lot of users at my workplace use different screen resolutions, and I build apps to use 1680 x 1050 pixels res by default. But some users are using 800 x 600, and the apps are too large for their...
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: 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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.