Set ClientRectangle on Form

Stonkie

Well-known member
Joined
Sep 12, 2007
Messages
279
Programming Experience
1-3
I am building custom forms to be inserted as toolboxes into an MDI application. I am painting the title bar manually, and I would like to be able to use my custom drawn title bar as any other title bar.

That means, I would like to have controls docked in it without going over my title bar and such. It seems like the easiest solution would be to set the client area of my form manually to the desired value or set some margin/padding delimiter so that the client area is calculated automatically when the form resizes.

However, no such property exists and the ClientRectangle property is read only.

I am looking for a way to do this so that I can simply build my toolboxes in the designer with this client area already calculated. Is there any way to do that without going through all those inherited forms and padding my controls with 20 pixels on the top?
 
You can put a Panel there and Dock it to Top. Or a Picturebox perhaps.
 
I was looking for an automated way of giving the controls' positions the necessary offset when placed directly on the form, not alowing the child to handle the click event, making my title bar unnaffected by background colors, make it not appear in the controls list and so on.

The default title bar has many qualities that this does not offer and my custom drawn stuff is logically a title bar independant of the form's content. Changing the default title bar to this one should require no ajustement (except the client area would not be exatly the same size).

Changing the client area seemed the best because I could use a very normal form and just have it inherit my custom form and tada, no more work to do! Anyway, I've done a lot of code for this, I won't be stopped by a few more lines! ;)
 
One more thing about docking. It would seem that having a panel docked on top in the base form won't make it appear on top if you dock something on top in the inherited form. The first docking does not limit the available size for further docking, it actually seems to work in reverse so that the later docking limits the size of the previous.

Here's some code to prove it. When Form2 is shown, the red panel shows on top over the green one from the base form.

Base form (Form1) :

VB.NET:
Public Class Form1
    Private pan_Top1 As New Panel()

    Public Sub New()

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

        ' Add any initialization after the InitializeComponent() call.

        pan_Top1.BackColor = Color.Green
        pan_Top1.Dock = DockStyle.Top
        pan_Top1.Height = 100
        Me.Controls.Add(pan_Top1)
    End Sub
End Class

Inherited form (Form2) :

VB.NET:
Public Class Form2
    Dim pan_Top2 As New Panel()

    Public Sub New()

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

        ' Add any initialization after the InitializeComponent() call.

        pan_Top2.BackColor = Color.Red
        pan_Top2.Dock = DockStyle.Top
        pan_Top2.Height = 100
        Me.Controls.Add(pan_Top2)
    End Sub
End Class

This means that the panel containing my menu appears under anything that is docked on top in the inherited form. It will even show over a panel docked on fill and hide the upper information (which is pretty weird...).

Are there really no way to set that client area or solve this in another clean way?
 
In my head this sounds a bit hackish but you could give it a go. Untested by the way..

Override the display rectangle property in form2, set it's Y co-ordinate to the location of the bottom of the panel inheritied from form 1. This might give you the effect you want, but as I said, untested.
 
You're right, it's a hack... But it works! :p

Still some tests left to do but I think we got it. Thanks!
 
Back
Top