Link to home
Start Free TrialLog in
Avatar of Jeanette Durham
Jeanette DurhamFlag for United States of America

asked on

vb.net 2005, How do I Remove MDI title bar from the form when my child window is maximized?

Dear Experts,

I am trying to write a nice looking application for work, hopefully to sell, but anyways- I'm trying to make it with a good design that looks and works good. I have no menubar, just a toolbar that is docked on the left side of my window. It's going to have icons for all my menu actions. The application uses a MDI window, and has a number of windows that may be used. This is why I wanted to use the MDI form. There are two screens which take all the space available to me, and they are meant to be shown just by themselves. One's a datagrid and the other is a single record view. So, what I need to do is take away the title bar that appears at the top of the form, which has the x and - and all in it, and when they're on those two forms, hide or remove that bar. The rest of the time the bar would be fine.

My other issue with the bar is my toolbar on the left is blue and the title bar keeps appearing as the system color (brown) instead of the professional (blue) and they clash horribly. This also is unacceptable. I have no idea how to set the color or access that title bar object programmatically. I do wonder if more could be done with it, if there was a way to access it.

Does anyone know how to do this? I've been searching on the internet for quite some time now without any luck, but I've seen samples for vb6 (which don't work for .net).

Thanks! ~Michael
Avatar of roshkins
roshkins

1. Post a link to the vb6 code. Maybe I could help.

2. To hide the titlebar Me.Borderstyle = none . (If me is the child frm.)
If a System's settings dictate a Brown TitleBar then I would expect a ToolBar, by default, to be a color consistent with that - based on Brown, but probably a few shades different.  This is because the default palette that the VB.NET designer uses for generating controls is the System palette, and the actual colors in that will depend on the System's settings.  

When we are designing an app, and go to alter one of the colors in a control, we are presented with other palettes as well - Custom and Web - and it is very tempting to select from those.  But those will then be fixed and, if the System settings are different from those on our development machine (or even - as looks to be the case here - clash with those on our development machine) it can produce anomalies.  That is because (so far as I know) there are certain elements (including TitleBars) that we cannot change from the System-set colors.  There can be cases in which the need to use a particular color is so great that it overrides aesthetic considerations like that.  By and large, though, my preference would be to stick to the System palette.  This preference would be particularly strong where the app was likely to be used by a variety of users.  This is because the System settings are User-determined so, even on the same machine, one User may have preferred one color scheme and a another user may have preferred a different one.

So, and it's really a question rather than an answer, I wonder why - if the title bar is brown - the toolbar is blue?

Roger
But he said that he had VB6 code, otherwise I would have said "it's set by the system."
>>
vb.net 2005, How do I Remove MDI title bar from the form when my child window is maximized?

[...]

I've seen samples for vb6 (WHICH DON'T WORK FOR .NET).
<<

My EMPHASIS ;-)

Roger
BUT, may become useful (after conversion to vb.net, etc.) He didn't say it was converted.
ASKER CERTIFIED SOLUTION
Avatar of VBRocks
VBRocks
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jeanette Durham

ASKER

VBRocks:

Your solution does indeed remove the mdiform's title bar. I didn't say exactly what I meant I guess. Um.. Ok, so what about the other bar that pops up? Right underneath the title bar of the mdiform there is a bar which applies to the child form, it has a minimize and maximize and close button and an icon where I think the window's icon would go. If I wanted to remove that but leave the mdiform's title bar, what would I do?

Thanks! Michael

Also..
Sancler:
Ok, I see what you mean now about the colors. The other toolbar I had set to 'Professional' because I liked the color. But.. it would be better to go with the default, since the other toolbar is always going to be the default. So yeah, the reason they were different colors is because I changed the toolbar to 'Professional'.

Also..
P.S. As Sancler mentioned this is for vb 2005, not vb6. Altho I am going to be upgrading to the new vs 2008 since I went to the Heroes Happen Here event by Microsoft! :) So.. if this is easier to do in 2008, that'd be interesting to know too.
I don't fully understand what you mean.  Do you mean remove the child form's title bar and leave the MDI title bar alone?  Or are you referring to something else?

VBRocks:

This might be rather hard to change since it's part of the behaviour of mdiforms. I just modified the code you gave me slightly to use the mdi child form instead of the me.mdiparent, and when stepping through it I actually did see the bar go away for a second, altho it came right back.

Basically, as near as I can figure, the way the mdiform works is because you have multiple windows inside a window anytime a window completely obscures all the other windows, ie. is maximized, then there is a brown bar that shows up right between the main window's title bar and your form. In it it has the maximize, close and minimize buttons as well as a spot for an icon.

This is the behaviour I want, altho on two of my forms they really are the only ones open, so none others are obscured, and I need the space to display them. So during those times I want to hide or remove that title bar.

I was thinking about it on my way to work today. It might be possible to take the main window, and turn off it's MDI-ness somehow, and then insert my window inside a dynamically created frame. I do that in a different program, but it does not use a mdi window.

Here is an example of that idea:

Public formInForm As Object

Me.frameInnerForm.Controls.Clear()
Me.frameInnerForm.Visible = True
formInForm = ConfigReport 'New ConfigReport
formInForm.toplevel = False
Me.frameInnerForm.Controls.Add(formInForm)
formInForm.show()

So yeah, now that you know which title bar I'm actually talking about.. any ideas?

Thanks! Michael
VBRocks:

After messing more with the code you gave me, I was actually able to get it to work, by setting the form's border style to none. So in the end it was easier to do than I suspected. Thank you very much for your help!

~Michael
For those of you who come after, and are trying to figure out how to do the same thing as me.. here is some working code that demonstrates this exactly. Thanks again to VBRocks for the solution:


Public Class Form1
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Form2.MdiParent = Me
        Form2.Show()
    End Sub
End Class
 
Public Class Form2
    Public Sub New()
        ' This call is required by the Windows Form Designer.
        InitializeComponent()
 
        ' Add any initialization after the InitializeComponent() call.
        Me.WindowState = FormWindowState.Maximized
    End Sub
 
    Private Sub Form2_Resize(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles MyBase.Resize
 
        Debug.Print(Me.WindowState.ToString)
        Dim frm As Form = Me 'Me.MdiParent
        'If Me.WindowState <> FormWindowState.Normal Then Stop
        If frm Is Nothing Then Exit Sub
 
        If Me.WindowState = FormWindowState.Maximized Then
            frm.FormBorderStyle = Windows.Forms.FormBorderStyle.None
        Else
            'Change to whatever you want it to be as default
            frm.FormBorderStyle = Windows.Forms.FormBorderStyle.None
        End If
    End Sub
End Class

Open in new window

Given that both the if and the else contain

            frm.FormBorderStyle = Windows.Forms.FormBorderStyle.None

I wonder why you don't just set the FormBorderStyle to .None at design time, or in the Load sub, and dispense with the Resize code?

Roger