Moving an irregular shaped form in an MDI Container

R

Roger.Smith

Overview:
I have been creating custom shaped forms using a bitmap to set the form's
region. This has worked well, and I have had a lot of success finding
resources to help out. However, most of the examples that I have located
have been stand-alone forms, where the single form is the entire
application. What I need is to create custom shaped forms, and use them as
child forms inside of a MDI Container form. Getting this custom shaped
forms to be MDI children is not a problem, however moving them is.

Statement of the Problem.
The problem that I am having specifically is that when I place code on the
form to move it (in responce to a mouse clicking and dragging the form), the
form jumps down as soon as I begin to drag the form. My logic looks like
this (in the child form):

In the header.........
Private pntPointClicked As Point
Mouse Down Event.......
Private Sub frmIrregular_MouseDown(...) Handles MyBase.MouseDown
blnFormDragging = True
pntPointClicked = New Point(-e.X, -e.Y)
End Sub

Mouse Move Event.......
Private Sub frmIrregular_MouseMove(...) Handles MyBase.MouseMove
If blnFormDragging Then
Dim aMoveToPoint As Point
' Use the current mouse position to find the target location.
aMoveToPoint = Control.MousePosition
' Adjust the position based on where you started.
aMoveToPoint.Offset(pntPointClicked.X, pntPointClicked.Y)
' Try to account for the MDI Container not being in the upper left
of the screen.
aMoveToPoint.Offset(-Me.ParentForm.Location.X, -Me.ParentForm.Location.Y
)
' Move the form.
Me.Location = aMoveToPoint
End If
End Sub

Mouse Up Event.......
Private Sub frmIrregular_MouseUp(...) Handles MyBase.MouseUp
blnFormDragging = False
End Sub

What I need is some code to move the form when I click on the form (not a
control on the form), that doesn't cause the form to jump when the dragging
begins, and that accounts for the form being an MDI Child.

Thanks for the help,
Roger
 
A

Andrew Smith \(Infragistics\)

Maybe you should try converting the coordinates to screen coordinates -
using the mdichild's PointToScreen - since the coordinates you'll get in the
mouse events will be in client coordinates relative to the form. Then once
you've calculated the new top, left, use the Parent of the mdichild (which
should be the mdiclient) and use its PointToClient to convert to client
coordinates so you can set the mdichild's location.
 
C

Chris Dunaway

Have you tried overriding the child forms WndProc method like this:

Protected Overrides Sub WndProc(ByRef m As
System.Windows.Forms.Message)
Const WmNcHitTest As Integer = &H84
Const HtCaption As Integer = 2

If m.Msg = WmNcHitTest Then
m.Result = New IntPtr(HtCaption)
Else
MyBase.WndProc(m) 'THIS IS IMPORTANT!
End If
End Sub
 

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