|
-
Apr 6th, 2007, 02:22 AM
#1
Thread Starter
Junior Member
[RESOLVED] Focus on opened childform
Hi all,
I have created one mdi parent form and several mdi child forms. My question is when i click on open a mdi child form
this happening
Code:
if (frmKlantenbeheer.alreadyopen== false) //to check if form already open
{
frmKlantenbeheer form1 = new frmKlantenbeheer();
form1.MdiParent = this;
form1.Show();
}
else //if already open then focus that form
{
frmKlantenbeheer.ActiveForm.Activate();
frmKlantenbeheer.ActiveForm.BringToFront();
}
if a mdi child already opened i want to focus on that back
so this part doesn't work
Code:
else //if already open then focus that form
{
frmKlantenbeheer.ActiveForm.Activate();
frmKlantenbeheer.ActiveForm.BringToFront();
}[/
Could anyone help me for this
already thanks
bye
-
Apr 6th, 2007, 02:54 AM
#2
Re: Focus on opened childform
BringToFront is not relevant at all. That is what you call on controls while Activate is what you call on forms.
Also, there's not much point calling Activate on the ActiveForm because it's already active. If you want to activate frmKlantenbeheer then you call the Activate method of frmKlantenbeheer:
c# Code:
frmKlantenbeheer.Activate();
That's all you need. I'd still go with the Singleton pattern that I posted in that other thread you posted to. If a form is only supposed to have one instance then that behaviour should be part of the form itself.
-
Apr 6th, 2007, 03:09 AM
#3
Thread Starter
Junior Member
Re: Focus on opened childform
this is too complex for me but i solved this
actually is not complex just using a static function but in this case you have to write in one form other case you have to write code in both forms (child and mdi) heheh i hope it was clear :d
here is the code
Code:
// frmLeveranciersbeheer is the one I'm looking for
frmLeveranciersbeheer childForm = null;
foreach (Form f in this.MdiChildren)
{
if (f is frmLeveranciersbeheer)
{
// found it
childForm = (frmLeveranciersbeheer)f;
break;
}
}
if (childForm != null)
{
childForm.Show();
childForm.Focus();
}
else
{
childForm = new frmLeveranciersbeheer();
childForm.MdiParent = this;
childForm.Show();
childForm.Focus();
}
Thanks for reply
-
Apr 6th, 2007, 03:20 AM
#4
Re: [RESOLVED] Focus on opened childform
Don't call the Focus method. Call Activate.
-
Apr 6th, 2007, 05:22 PM
#5
Thread Starter
Junior Member
Re: [RESOLVED] Focus on opened childform
 Originally Posted by jmcilhinney
Don't call the Focus method. Call Activate.
Can I ask why?
-
Apr 6th, 2007, 07:37 PM
#6
Re: [RESOLVED] Focus on opened childform
Always read the documentation, not that you're the first person not to. From the MSDN help topic for the Focus method:
Focus is a low-level method intended primarily for custom control authors. Instead, application programmers should use the Select method or the ActiveControl property for child controls, or the Activate method for forms.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|