Solved

Fixed mdi child forms vb.net

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

822 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