Solved

Fixed mdi child forms vb.net

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
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 …
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

680 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