MDI + FormBorderStyle = None

Stonkie

Well-known member
Joined
Sep 12, 2007
Messages
279
Programming Experience
1-3
I am trying to set the FormBorderStyle property to None to make tool boxes in a MDI application have a custom header (I want them to look like tabs and code stuff so I may join my toolboxes together, a little like Photoshop does, without the Windows title bar). However, the default border for toolboxes seems to apply to those windows inside the Mdi before being painted over by my code so it causes a blue title bar to quickly appear and disappear when the form is made visible for the first time.

I want to prevent this title bar from getting painted on my form either by catching a message in the WndProc or any shorter solution. I want to make sure that it is possible to hide that title bar before I start coding my custom drawn tool boxes.

I don't currently intend to implement it, but it was also considered to use transparency in those tool boxes and I was wondering if there was some way to achieve that result even though it is not supported (something simpler than to handle the paint event and draw something that looks like what's behind).
 
I found a very Quick and dirty method for this...

I simply move the toolboxes outside the client area and move it back to its previous location respectively before and after I call the show method or I set the visible property to true...

I truly searched deep for this and I could hardly find anything but partial solutions messing with complex window messages and API calls, so for the sake of it working on all OS (and of me knowing what I'm doing...), I guess this is the best solution.

I'd really like to find a better one tough, so if anyone knows it, post it! ;)
 
Tool windows usually have FormBorderStyle set to Fixed-/SizableToolWindow, Owner set to the parent window, and ShowInTaskbar=False. They are normally not mdi childs, even though the parent window may be a mdi parent. Normally only document windows are mdi childs (that is the D in MDI - multiple document interface), content windows in other words.

To remove the title bar for a window set Text empty and ControlBox=False.

About tabs there is the TabControl of course, which support DrawMode=OwnerDrawFixed also, this could save you implementing the tabbing functionality yourself and still have custom look.

To move the captionless tool window I found this code excellent (I also used Dock=Fill for the tabcontrol, so there was about no other option), user can just drag the window by the tabs:
VB.NET:
Private mouse_offset As Point

Private Sub TabControl1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles TabControl1.MouseDown
    mouse_offset = New Point(-e.X, -e.Y)
End Sub

Private Sub TabControl1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles TabControl1.MouseMove
    If e.Button = System.Windows.Forms.MouseButtons.Left Then
        Dim mousePos As Point = Control.MousePosition
        mousePos.Offset(mouse_offset)
        Location = mousePos
    End If
End Sub
 
I didn't know about Text empty and ControlBox=False making the title bar dissapear, thanks! I'll see if it prevents the flicker I currently experience (I don't have the project at home) + it implements resizing without any additional code!
 
I have been testing this and it doesn't prevent the flickering that takes place with child forms inside an MDI application. Even with Text empty and ControlBox=False, the default title bar (the color depends on your system) still draws behind my custom drawn title bar.

I have seen this problem on many thread in many forums and the only other solution I found was to go mess with complex API stuff and that was too much for me when I can get around the problem so easily.

I'll be using this though as it allows me to have my toolboxes resizable unlike FormBorderStyle = None an it will avoid me the hassle of coding it.
 
Works for me, can't see squat of a title bar, this goes for both mdi childs and tool windows.
 
Thanks for taking the time.

To reproduce this problem, create a new application with the default Form1. Then just paste this code as Form1's implementation (I set all the necessary properties in the code, there is no need to use the designer for anything).

VB.NET:
Public Class Form1
    Private subForm1 As New Form()
    Private subForm2 As New Form()

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

        Me.Size = New Size(500, 500)
        Me.IsMdiContainer = True

        subForm1.MdiParent = Me
        subForm2.MdiParent = Me

        subForm1.FormBorderStyle = Windows.Forms.FormBorderStyle.None
        subForm2.FormBorderStyle = Windows.Forms.FormBorderStyle.None

        subForm1.Visible = True
    End Sub

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        subForm1.Visible = Not subForm1.Visible
        subForm2.Visible = Not subForm2.Visible

        e.Cancel = True
    End Sub
End Class

Now, whenever you click the close button, the toolboxes will change from visible to invisible. However, when they switch, you will see the default windows title bar appear on top of the toolbox that is being newly shown even tough they are set to FormBorderStyle = None.
 
That is funny, but it doesn't happen with non-mdi childs like the tool window you were creating.
 
Back
Top