Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dragging borderless form 2

Status
Not open for further replies.

MasterRacker

Active member
Oct 13, 1999
3,343
US
I have a borderless form that I need to be able to drag around the screen via its' body. I found this override to be added to the form :
Code:
    protected override void WndProc(ref Message msg)
    {
      if (msg.Msg == 0x0084) // WM_NCHITTEST
        msg.Result = (IntPtr) 2; // HTCAPTION
      else
        base.WndProc(ref msg);
    }
This works fine for the most part. I'm guessing this somehow modifies the click event to make the entire window behave like a title bar. The unfortunate side effect is that double-clicking the form maximizes it. I had a double-click event defined to close the form, but this override seems to be processed first, rendering my event useless.

Can anyone suggest a modification to only allow dragging?


Jeff
[purple]It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day

"The software I buy sucks, The software I write sucks. It's time to give up and have a beer..." - Me
 
I'm curious as to why you are trying to drag a borderless form. The idea seems to break common GUI Practices.

Could you explain the context in which you are using this form?

<insert stupid signature here>
 
It's borderless because it's irregularly shaped as well. It uses our logo as a background image and the background color is set transparent so it's essentially the logo floating on the desktop. It's kind of a cutesy thing I have in mind for an internal application. I want the end user to be able to put it where they want.

Think of it as a .NET variation of a Konfabulator widget.

Jeff
[purple]It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day

"The software I buy sucks, The software I write sucks. It's time to give up and have a beer..." - Me
 
I would forget about the WndProc events and stick to the good ol' events.


Form1_MouseDown(object sender, EventArgs e)
{
this.MouseMove += new EventHandler(Form1_MouseMove);
}

Form1_MouseMove(object sender, MouseEventArgs e)
{
this.Location = new Point(e.Position);
}

Form_MouseUp(object sender, EventArgs e)
{
this.MouseMove = null;
}


So the form attaches the MouseMove event when the form is clicked. When the mouse is lifted again, the event handler is removed by setting it to null or to a different handler that does nothing. As you move the mouse, you can change the position of the form relative to the mouse.

Hope that helps - and cool idea!
 
I want the end user to be able to put it where they want.

We are programmers, we don't care what users want, users will do what we want.

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Christiaan,

I've been trying to program users for years with very limited success. ;-)

Jeff
[purple]It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day

"The software I buy sucks, The software I write sucks. It's time to give up and have a beer..." - Me
 
JurkMonkey and Chip,

I've been redirected and won't be able to work in this for a while, but that looks like a pretty straightforward alternate solution. Thanks.

Jeff
[purple]It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day

"The software I buy sucks, The software I write sucks. It's time to give up and have a beer..." - Me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top