How to change the backcolor of a MDI form

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.
 
É

Éric Moreau [VB MVP]

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)
 
G

Guest

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)
 
M

moondaddy

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top