Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / January 2005

Tip: Looking for answers? Try searching our database.

Moving an irregular shaped form in an MDI Container

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Roger.Smith - 27 Jan 2005 19:23 GMT
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
Andrew Smith \(Infragistics\) - 28 Jan 2005 04:15 GMT
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.

> Overview:
> I have been creating custom shaped forms using a bitmap to set the form's
[quoted text clipped - 47 lines]
> Thanks for the help,
> Roger
Chris Dunaway - 28 Jan 2005 16:30 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.