Detecting MDI Children

5 views
Skip to first unread message

dannosliwcd

unread,
May 8, 2008, 10:21:11 PM5/8/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hi, I'm a newbie to programming, taking a high school class in VB .net
and trying to teach myself C#.

I'm trying to make a sort of word processor just as a kind of practice
thing. I'm having some trouble with a few text formatting functions
because if there isn't an open MDI child with the Richtextbox to apply
the format to, it crashes the program. I am currently using Try...
Catch statements to get around the crash, but I'm pretty sure that
isn't the stylistically right way to do it. Is there some kind of
function that I could use in an if statement to say only apply the
formatting if there is an active MDI child?

Thanks

Joshua Russo

unread,
May 10, 2008, 8:52:34 AM5/10/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
One thing you might try is to create a static variable of type Form
that you call ActiveForm. Then assign it in the Activated event of
each child with This and nullify it in the Deactivate of each child.
In your formatting function you just have to see if the ActiveForm is
null and if you have multiple types of child forms, check the type and
cast to the proper type.

Josh

Cerebrus

unread,
May 11, 2008, 12:53:35 PM5/11/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
IMHO, the "Form.ActiveMdiChild" Property should return null if there
is no active child windows.

Joshua Russo

unread,
May 12, 2008, 9:06:25 AM5/12/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Ya, I guess if you what to use the easy way that would be better. :o)

Cerebrus

unread,
May 12, 2008, 12:18:20 PM5/12/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Lol !

dannosliwcd

unread,
May 12, 2008, 5:19:01 PM5/12/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
It may return null if it doesn't have any mdi children, but it doesn't
let me test to see if it is in an if statement. Though it turns out I
ran across the answer in a different problem I was working on. It
turns out that the mdi children are stored as an array, so I can check
to see if frmMainForm.MdiChildren.Length < 0 before reading any more
statements. Thanks for all the suggestions.

On May 11, 12:53 pm, Cerebrus <zorg...@sify.com> wrote:

Cerebrus

unread,
May 13, 2008, 1:30:10 PM5/13/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Does this code not work for you ?

Dim child As Form = Me.ActiveMdiChild
If child is Nothing Then
' No active child exists.
Else
'An active child exists.
End If
> > > Thanks- Hide quoted text -
>
> - Show quoted text -

dannosliwcd

unread,
May 17, 2008, 7:25:42 PM5/17/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
I didn't realize there was a difference between using the "is" keyword
and using the "=" operator. Well, now I do. Thanks for the help, your
code suggestion works great.

Cerebrus

unread,
May 18, 2008, 2:35:59 AM5/18/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
I'm glad to be of assistance. You're most welcome ! :-)
> > > - Show quoted text -- Hide quoted text -
Reply all
Reply to author
Forward
0 new messages