PC Review


Reply
Thread Tools Rate Thread

Can't bring form to front

 
 
Anders Thomsen
Guest
Posts: n/a
 
      19th Sep 2003
Hi ng,

I have a problem when trying to focus certain forms.

My application consists of several forms, at first form1 is shown. Clicking
a button here will close form1 and show form2. When form2 i showing, I try
to open the File manager in PPC. From here, I can navigate to my project
folder and open my application by clicking on the .exe. This opens up the
app where I left it, showing form2 - as suspected.

Then I click a button on form2 which closes form2 and create a new instance
of Form1 (the first instance was disposed and it's reference set to null).
On this new instance i've tried to call BringtoFront(), Focus(), Show and
Visible = true, but I simply can't get the form to show. Instead, the file
manager is shown - which is okay, since it's the next form in the Z-order
after form2. But after creating Form1 and calling BringToFront etc. I
believe that form1 should be put on top.

How can I activate form1?

Thanks in advantage,


 
Reply With Quote
 
 
 
 
Jan Yeh
Guest
Posts: n/a
 
      19th Sep 2003
Hi, there

I am wondering when you click the button on form2, it closes form2 itself
AND
create a new instance of form1, is that right?
If correct, the the sequence of statement is important, for example:
<in form2 instance>
this.Close(); // When it close, who will keep the reference of frm?
form1 frm=new form1();
frm.Show();

Another exampler:
<in form2 instance>
form1 frm=new form1();
frm.Show();
this.Close(); // When it close, it dispose everything in form2, including
frm.

The result of above will cause frm instance disappear, as you've seen.

----------------------------------------------------------------------------
--
You may try the following way.
<in form1 instance>
private void Button1_Click(
form2 frm2=new form2(this); // pass the handle of form1 to form2
frm2.Show();
this.Hide();
<in form2 instance>
private form1 f=null;
public form2(form1 frm)
{
f=frm; // form2 will take the handle of form1 instance
}

private void Button1_Click(object sender, EventArgs e)
{
f.Show();
this.Hide(); // or this.Close();
// then it will back to the original form1, instead of a new instance.
}

"Anders Thomsen" <(E-Mail Removed)> ¦b¶l¥ó
news:(E-Mail Removed) ¤¤¼¶¼g...
> Hi ng,
>
> I have a problem when trying to focus certain forms.
>
> My application consists of several forms, at first form1 is shown.

Clicking
> a button here will close form1 and show form2. When form2 i showing, I try
> to open the File manager in PPC. From here, I can navigate to my project
> folder and open my application by clicking on the .exe. This opens up the
> app where I left it, showing form2 - as suspected.
>
> Then I click a button on form2 which closes form2 and create a new

instance
> of Form1 (the first instance was disposed and it's reference set to null).
> On this new instance i've tried to call BringtoFront(), Focus(), Show and
> Visible = true, but I simply can't get the form to show. Instead, the file
> manager is shown - which is okay, since it's the next form in the Z-order
> after form2. But after creating Form1 and calling BringToFront etc. I
> believe that form1 should be put on top.
>
> How can I activate form1?
>
> Thanks in advantage,
>
>



 
Reply With Quote
 
Anders Thomsen
Guest
Posts: n/a
 
      19th Sep 2003
Actually, it's not form2 who creates form1, but some underlying handlers.
The form1 IS there, as it is focused when I minimize the filemanager.



"Jan Yeh" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hi, there
>
> I am wondering when you click the button on form2, it closes form2 itself
> AND
> create a new instance of form1, is that right?
> If correct, the the sequence of statement is important, for example:
> <in form2 instance>
> this.Close(); // When it close, who will keep the reference of frm?
> form1 frm=new form1();
> frm.Show();
>
> Another exampler:
> <in form2 instance>
> form1 frm=new form1();
> frm.Show();
> this.Close(); // When it close, it dispose everything in form2,

including
> frm.
>
> The result of above will cause frm instance disappear, as you've seen.




 
Reply With Quote
 
Mark Arteaga
Guest
Posts: n/a
 
      19th Sep 2003
To set focus on a form I had to P/Invoke to get it to work properly. Try
this code:

[DllImport("coredll",EntryPoint="FindWindow")]
public static extern IntPtr FindWindow(string lpClassName,string
lpWindowName);
[DllImport("coredll",EntryPoint="SetForegroundWindow")]
public static extern bool SetForegroundWindow(IntPtr hWnd);

IntPtr hWnd = FindWindow(null,form1.Text);
if(!hWnd.Equals(IntPtr.Zero))
SetForegroundWindow(hWnd);

HTH
Mark Arteaga
www.clearknowledge.com

"Anders Thomsen" <(E-Mail Removed)> wrote in message
news:u6$(E-Mail Removed)...
> Actually, it's not form2 who creates form1, but some underlying handlers.
> The form1 IS there, as it is focused when I minimize the filemanager.
>
>
>
> "Jan Yeh" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > Hi, there
> >
> > I am wondering when you click the button on form2, it closes form2

itself
> > AND
> > create a new instance of form1, is that right?
> > If correct, the the sequence of statement is important, for example:
> > <in form2 instance>
> > this.Close(); // When it close, who will keep the reference of frm?
> > form1 frm=new form1();
> > frm.Show();
> >
> > Another exampler:
> > <in form2 instance>
> > form1 frm=new form1();
> > frm.Show();
> > this.Close(); // When it close, it dispose everything in form2,

> including
> > frm.
> >
> > The result of above will cause frm instance disappear, as you've seen.

>
>
>



 
Reply With Quote
 
Anders Thomsen
Guest
Posts: n/a
 
      19th Sep 2003
Okay, thanks.

Do you know if there's another way to get the handle of the form - many of
my forms has
the same title.

-and thanks again : )

"Mark Arteaga" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> To set focus on a form I had to P/Invoke to get it to work properly. Try
> this code:
>
> [DllImport("coredll",EntryPoint="FindWindow")]
> public static extern IntPtr FindWindow(string lpClassName,string
> lpWindowName);
> [DllImport("coredll",EntryPoint="SetForegroundWindow")]
> public static extern bool SetForegroundWindow(IntPtr hWnd);
>
> IntPtr hWnd = FindWindow(null,form1.Text);
> if(!hWnd.Equals(IntPtr.Zero))
> SetForegroundWindow(hWnd);
>
> HTH
> Mark Arteaga
> www.clearknowledge.com
>
> "Anders Thomsen" <(E-Mail Removed)> wrote in message
> news:u6$(E-Mail Removed)...
> > Actually, it's not form2 who creates form1, but some underlying

handlers.
> > The form1 IS there, as it is focused when I minimize the filemanager.
> >
> >
> >
> > "Jan Yeh" <(E-Mail Removed)> wrote in message
> > news:%(E-Mail Removed)...
> > > Hi, there
> > >
> > > I am wondering when you click the button on form2, it closes form2

> itself
> > > AND
> > > create a new instance of form1, is that right?
> > > If correct, the the sequence of statement is important, for example:
> > > <in form2 instance>
> > > this.Close(); // When it close, who will keep the reference of frm?
> > > form1 frm=new form1();
> > > frm.Show();
> > >
> > > Another exampler:
> > > <in form2 instance>
> > > form1 frm=new form1();
> > > frm.Show();
> > > this.Close(); // When it close, it dispose everything in form2,

> > including
> > > frm.
> > >
> > > The result of above will cause frm instance disappear, as you've seen.

> >
> >
> >

>
>



 
Reply With Quote
 
Mark Arteaga
Guest
Posts: n/a
 
      19th Sep 2003
yup....on the form set Capture=ture then p/invoke get capture. this will
return the handle.

[DllImport("coredll.dll", EntryPoint="GetCapture", SetLastError=true)]
private static extern IntPtr GetCapture();

HTH
Mark.
"Anders Thomsen" <(E-Mail Removed)> wrote in message
news:u05Dj$(E-Mail Removed)...
> Okay, thanks.
>
> Do you know if there's another way to get the handle of the form - many of
> my forms has
> the same title.
>
> -and thanks again : )
>
> "Mark Arteaga" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > To set focus on a form I had to P/Invoke to get it to work properly.

Try
> > this code:
> >
> > [DllImport("coredll",EntryPoint="FindWindow")]
> > public static extern IntPtr FindWindow(string lpClassName,string
> > lpWindowName);
> > [DllImport("coredll",EntryPoint="SetForegroundWindow")]
> > public static extern bool SetForegroundWindow(IntPtr hWnd);
> >
> > IntPtr hWnd = FindWindow(null,form1.Text);
> > if(!hWnd.Equals(IntPtr.Zero))
> > SetForegroundWindow(hWnd);
> >
> > HTH
> > Mark Arteaga
> > www.clearknowledge.com
> >
> > "Anders Thomsen" <(E-Mail Removed)> wrote in message
> > news:u6$(E-Mail Removed)...
> > > Actually, it's not form2 who creates form1, but some underlying

> handlers.
> > > The form1 IS there, as it is focused when I minimize the filemanager.
> > >
> > >
> > >
> > > "Jan Yeh" <(E-Mail Removed)> wrote in message
> > > news:%(E-Mail Removed)...
> > > > Hi, there
> > > >
> > > > I am wondering when you click the button on form2, it closes form2

> > itself
> > > > AND
> > > > create a new instance of form1, is that right?
> > > > If correct, the the sequence of statement is important, for example:
> > > > <in form2 instance>
> > > > this.Close(); // When it close, who will keep the reference of

frm?
> > > > form1 frm=new form1();
> > > > frm.Show();
> > > >
> > > > Another exampler:
> > > > <in form2 instance>
> > > > form1 frm=new form1();
> > > > frm.Show();
> > > > this.Close(); // When it close, it dispose everything in form2,
> > > including
> > > > frm.
> > > >
> > > > The result of above will cause frm instance disappear, as you've

seen.
> > >
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Lloyd Dupont
Guest
Posts: n/a
 
      10th Oct 2003
When I try to deploy my project with VS.NET on the device (PocketPC 2002) OR
on the emulator TOO !,
VS.NET gives me this error while copying the files:
"Error: Cannot establish a connection. Be sure the device is physically
connected to the development computer."

therefore I can't debug, well I could copy the application and see what
happen....
but it would be better if I could use the debugger !



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bring form to front =?Utf-8?B?QW5ndXM=?= Microsoft Access Form Coding 1 31st Aug 2006 09:25 PM
bring a form to front Fox Microsoft Dot NET Framework Forms 0 26th Dec 2005 07:41 AM
Bring form to the front =?Utf-8?B?VEx1ZWJrZQ==?= Microsoft Access Forms 2 27th Oct 2005 08:05 PM
Re: Bring form to front Bruce Microsoft Access Forms 1 15th Sep 2004 06:27 PM
Bring Form to the front. =?Utf-8?B?bGl1X3dheW5lMTA=?= Microsoft Dot NET Compact Framework 2 12th Aug 2004 01:09 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:31 AM.