Solved

Fixed mdi child forms vb.net

Posted on 2006-06-15
3
722 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 86

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 86

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

630 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