How to change the backcolor of a MDI form

  • Thread starter Thread starter moondaddy
  • Start date Start date
M

moondaddy

I'm writing an app in vb.net 1.1 and need to change the backcolor of an MDI
form. I saw in another posting in this user group which referred to a link
<URL:http://vbaccelerator.com/article.asp?id=4306>
which had a good example, however, it was in C# and I wasn't able to get
through it. Can anyone refer a good vb example?

Thanks.
 
I use this:

Dim ctl As Control
Dim ctlMDI As MdiClient
'Loop, looking for MdiClient type Forms
For Each ctl In Me.Controls
Try
' Attempt to cast the control as a MdiClient
ctlMDI = CType(ctl, MdiClient)
ctlMDI.BackColor = Color.DarkSeaGreen
Catch exc As InvalidCastException
' ignore
End Try
Next


--

HTH

Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Concept S2i inc.(www.s2i.com)
 
Yup, Éric's got it right. I've done it the same way but prefer to avoid the
exception overhead handling by using TypeOf.

Dim ctl As Control
Dim ctlMDI As MdiClient
'Loop, looking for MdiClient type Forms
For Each ctl In Me.Controls
If TypeOf (ctl) Is MdiClient Then
ctlMDI = CType(ctl, MdiClient)
ctlMDI.BackColor = Color.DarkSeaGreen
Exit For
End If
Next

Cheers,
Gwynn

-----------------------------------------------------------------
Gwynn Kruger
http://www.compusolvecanada.com
-----------------------------------------------------------------


Éric Moreau said:
I use this:

Dim ctl As Control
Dim ctlMDI As MdiClient
'Loop, looking for MdiClient type Forms
For Each ctl In Me.Controls
Try
' Attempt to cast the control as a MdiClient
ctlMDI = CType(ctl, MdiClient)
ctlMDI.BackColor = Color.DarkSeaGreen
Catch exc As InvalidCastException
' ignore
End Try
Next


--

HTH

Éric Moreau, MCSD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Concept S2i inc.(www.s2i.com)
 
Thanks.

--
(e-mail address removed)
Gwynn Kruger said:
Yup, Éric's got it right. I've done it the same way but prefer to avoid
the
exception overhead handling by using TypeOf.

Dim ctl As Control
Dim ctlMDI As MdiClient
'Loop, looking for MdiClient type Forms
For Each ctl In Me.Controls
If TypeOf (ctl) Is MdiClient Then
ctlMDI = CType(ctl, MdiClient)
ctlMDI.BackColor = Color.DarkSeaGreen
Exit For
End If
Next

Cheers,
Gwynn
 
Back
Top