Solved

Fixed mdi child forms vb.net

Posted on 2006-06-15
3
706 Views
Last Modified: 2011-10-03
Hello experts I am working with an mdi application.  How do I make the child forms fixed so that they cant me moved with the mouse?  I quess it would be like docking the child forms.  What I am trying to do is create multiple child forms and have them aligned so that they are side by side and none of them can be moved.

 Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim f As New Form3  'Form3 needs to be docked or fixed. Any child form loaded next
                                        'should be docked next  this one.
        f.MdiParent = Me
        f.Show()
    End Sub
0
Comment
Question by:tentavarious
  • 2
3 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 16912415
Add this code to the Child that you don't want to be moved around:

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        Const WM_NCHITTEST As Integer = 132
        Const HTCAPTION As Integer = &H2

        MyBase.WndProc(m)
        If m.Msg = WM_NCHITTEST Then
            If m.Result.ToInt32() = HTCAPTION Then
                m.Result = New IntPtr(0)
            End If
        End If
    End Sub

Be sure to remove min/max buttons if you don't want them...
0
 

Author Comment

by:tentavarious
ID: 16912442
Ok, that works now how would I dock the child form in the upper left corner of the parent form for example?
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 250 total points
ID: 16912701
You can manually place them using their Location() property.

But have you considered placing Panels in your MdiParent form?  Then you can embed the MdiChild form inside the Panel...

For instance, place a Panel (Panel1) in your MdiParent and Dock it to the Left.  Then add another Panle (Panel2) to the right of the first and also Dock it to the left.  This will changes the available "client" area of your MdiParent so that "free moving" child forms will be to the right of both them.

Now you can embed forms in the Panels.  You have to programmatically change their TopLevel property to False.  You can take off their form borders as well:

    Private Sub MdiParent_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim cf As Form
       
        cf = New ChildForm
        cf.TopLevel = False
        cf.FormBorderStyle = FormBorderStyle.None
        cf.Dock = DockStyle.Fill
        Panel1.Controls.Add(cf)
        cf.Show()

        cf = New SomeOtherChildForm
        cf.TopLevel = False
        cf.FormBorderStyle = FormBorderStyle.None
        cf.Dock = DockStyle.Fill
        Panel2.Controls.Add(cf)
        cf.Show()
    End Sub
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now