Customize Windows.Forms.MdiClient

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there any way to change or turn off the border of an
Windows.Forms.MdiClient control? In my opinion the 3D bevel that the control
uses is outdated and looks poor in my app. The best would be a single line
border that custom draw so I can control the color of the border.

Thanks for any help!
Lance
 
Hi Cor,

Thanks for the idea. Unfortunately the sample will not work for the
following reasons:

1. The sample does not address the need to change the width of the border.
2. The Paint event of the form will not necessarily be fired when the border
of its MdiClient control needs to be updated.
3. The sample will never work as it is written (even for a TextBox) because
it uses the Graphics object that is passed to the form's Paint event which
corresponds to the client area of the form, not the client area of the
control.

Any other ideas?

Thanks,
Lance
 
Try this.

Create a Windows Forms project and set the IsMDiContainer property to True.

Note that the MdiClient area has a sunken 3D border.

Add 2 Buttons (Button1 and Button2) to the form and add the following code.

Dim m_mdiclient As MdiClient = Nothing

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
Handles MyBase.Load

For Each _c As Control In Me.Controls
If _c.GetType Is GetType(MdiClient) Then
m_mdiclient = CType(_c, MdiClient)
Exit For
End If
Next

End Sub

Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Handles Button1.Click

m_mdiclient.Dock = DockStyle.None

m_mdiclient.Location = New Point(-2, -2)

m_mdiclient.Size = New Size(ClientSize.Width + 4, ClientSize.Height + 4)

End Sub

Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs)
Handles Button2.Click

m_mdiclient.Dock = DockStyle.Fill

End Sub

'Run' the project.

Note that the MdiClient area has a sunken 3D border.

Click Button1.

Note that the MdiClient area repaints and no longer has a sunken 3D border.

Click Button2.

Note that the MdiClient area repaints and has a sunken 3D border again.

Click Button1 and then resize the form.

There is still a single, slightly darker line that appears to be around the
MdiClient area it is really the inside edge of the form border.

If you don't reposition and resize the MdiClient area when you set it's Dock
property to DockStyle.None, then it's location becomes 0,0 and it's size
becomes 0,0 which, of course becomes problems.

Have a play with that and see if it helps with what you are trying to
achieve.
 
Hi Lance,

I agree to what Stephany has suggested. We could get the MdiClient of a MDI
parent form and set its Dock property to None to turn off the 3D bevel
border on the MDI parent form.

As for changing the color of a form's border, I have spent some time
researching on this problem but didn't find a good way to do it.

On possible way is to override the WndProc method in the form, and catch
WM_NCPAINT message in the override method. The WM_NCPAINT message is sent
to a window when its frame must be painted. However, when we handle the
WM_NCPAINT message, we need to draw the non-client of the form by
ourselves, including the title bar, which may be much complex.

Alternatively, you could set the 'Active Window Border' or 'Inactive Window
Border' for the entire system. To do this, right-click on the destop and
choose 'Properties'. In the Display properties, switch to the Appearance
tab, and click the 'Advanced' button. In the Advanced Appearance window,
select 'Active Window Border' or 'Inactive Window Border' for the 'Item'
and then change its color.

If you have any concerns, please feel free to let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Thanks Stephany. I was not aware that the border would change when the
MdiClient is not docked. That should let me do what I want.
Lance
 
Back
Top