Solved

Fixed mdi child forms vb.net

Posted on 2006-06-15
3
708 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

911 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

16 Experts available now in Live!

Get 1:1 Help Now