By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,224 Members | 1,309 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,224 IT Pros & Developers. It's quick & easy.

create deactivated form

P: n/a
hy,

I've got a quite simple application: one windows form that consists of a
button, and as soon as the user hits the button a second form shall appear.
The difficult thing about it is that I want the new form to be created as
"deactivated" - that means that the second form has an editbox in it, and
this must NOT have the focus - instead, the calling form shall keep its
focus.

One simple way would be to immediately set focus back after the second form
got it, but this won't work in the future for me when I will extend my app.
So I'm looking for a way to immediately create a window that doesn't have
focus.
I've already tried overriding the CreateParams-method like this (the
WS_EX_NOACTIVATE style here is the one from CreateWindowEx in win32-sdk):
protected override CreateParams CreateParams
{
get
{
const int WS_EX_NOACTIVATE = 0x08000000;
CreateParams myParams = base.CreateParams;
myParams.ExStyle = myParams.ExStyle | WS_EX_NOACTIVATE;
return myParams;
}
}
Or do I have to override a method like myForm.Show(), or myForm.Activated()
(because the new window gets focus as soon as I call myForm.Show())

I really appreciate any hints that could lead to a solution,
thx in advance,
ekim!
Nov 16 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
If the form is not a dialog, why dont you re-activate the original form once
you have created the new one?
private void button1_Click(object sender, System.EventArgs e)

{

Form2 myform = new Form2();

myform.Show();

this.Activate();

}

Br,

Mark.

"Ekim" <th************@gmx.net> wrote in message
news:2p************@uni-berlin.de...
hy,

I've got a quite simple application: one windows form that consists of a
button, and as soon as the user hits the button a second form shall appear. The difficult thing about it is that I want the new form to be created as
"deactivated" - that means that the second form has an editbox in it, and
this must NOT have the focus - instead, the calling form shall keep its
focus.

One simple way would be to immediately set focus back after the second form got it, but this won't work in the future for me when I will extend my app. So I'm looking for a way to immediately create a window that doesn't have
focus.
I've already tried overriding the CreateParams-method like this (the
WS_EX_NOACTIVATE style here is the one from CreateWindowEx in win32-sdk):
protected override CreateParams CreateParams
{
get
{
const int WS_EX_NOACTIVATE = 0x08000000;
CreateParams myParams = base.CreateParams;
myParams.ExStyle = myParams.ExStyle | WS_EX_NOACTIVATE;
return myParams;
}
}
Or do I have to override a method like myForm.Show(), or myForm.Activated() (because the new window gets focus as soon as I call myForm.Show())

I really appreciate any hints that could lead to a solution,
thx in advance,
ekim!

Nov 16 '05 #2

P: n/a
thanks for your answer - this would of course work if the case would be as
simple as I had described it.
but in fact I don't call the second form to be created from within this
..NET-project, but call it from a c++-win32-client via com-interop (com
callable wrappers). more detailled, I create the .NET-form as soon as the
user makes some keystrokes into an editbox of my win32-toolbar (and
therefore I MUST NOT lose focus, so that the user can keep on entering keys
into my editbox) ;-(
"Mark Broadbent" <no************@no-spam-please.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
If the form is not a dialog, why dont you re-activate the original form once you have created the new one?
private void button1_Click(object sender, System.EventArgs e)

{

Form2 myform = new Form2();

myform.Show();

this.Activate();

}

Br,

Mark.

"Ekim" <th************@gmx.net> wrote in message
news:2p************@uni-berlin.de...
hy,

I've got a quite simple application: one windows form that consists of a
button, and as soon as the user hits the button a second form shall

appear.
The difficult thing about it is that I want the new form to be created as "deactivated" - that means that the second form has an editbox in it, and this must NOT have the focus - instead, the calling form shall keep its
focus.

One simple way would be to immediately set focus back after the second

form
got it, but this won't work in the future for me when I will extend my

app.
So I'm looking for a way to immediately create a window that doesn't have focus.
I've already tried overriding the CreateParams-method like this (the
WS_EX_NOACTIVATE style here is the one from CreateWindowEx in win32-sdk):

protected override CreateParams CreateParams
{
get
{
const int WS_EX_NOACTIVATE = 0x08000000;
CreateParams myParams = base.CreateParams;
myParams.ExStyle = myParams.ExStyle | WS_EX_NOACTIVATE;
return myParams;
}
}
Or do I have to override a method like myForm.Show(), or

myForm.Activated()
(because the new window gets focus as soon as I call myForm.Show())

I really appreciate any hints that could lead to a solution,
thx in advance,
ekim!


Nov 16 '05 #3

P: n/a
Ah, I see. Im sure I've seen this thing come up before in the ngs and I'm
not sure there is a good answer, however hopefully one of the gurus will
come to your assistance.
Good Luck!

"Ekim" <th************@gmx.net> wrote in message
news:2p************@uni-berlin.de...
thanks for your answer - this would of course work if the case would be as
simple as I had described it.
but in fact I don't call the second form to be created from within this
.NET-project, but call it from a c++-win32-client via com-interop (com
callable wrappers). more detailled, I create the .NET-form as soon as the
user makes some keystrokes into an editbox of my win32-toolbar (and
therefore I MUST NOT lose focus, so that the user can keep on entering keys into my editbox) ;-(
"Mark Broadbent" <no************@no-spam-please.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
If the form is not a dialog, why dont you re-activate the original form

once
you have created the new one?
private void button1_Click(object sender, System.EventArgs e)

{

Form2 myform = new Form2();

myform.Show();

this.Activate();

}

Br,

Mark.

"Ekim" <th************@gmx.net> wrote in message
news:2p************@uni-berlin.de...
hy,

I've got a quite simple application: one windows form that consists of a button, and as soon as the user hits the button a second form shall

appear.
The difficult thing about it is that I want the new form to be created as "deactivated" - that means that the second form has an editbox in it, and this must NOT have the focus - instead, the calling form shall keep its focus.

One simple way would be to immediately set focus back after the second

form
got it, but this won't work in the future for me when I will extend my

app.
So I'm looking for a way to immediately create a window that doesn't have focus.
I've already tried overriding the CreateParams-method like this (the
WS_EX_NOACTIVATE style here is the one from CreateWindowEx in win32-sdk):

protected override CreateParams CreateParams
{
get
{
const int WS_EX_NOACTIVATE = 0x08000000;
CreateParams myParams = base.CreateParams;
myParams.ExStyle = myParams.ExStyle | WS_EX_NOACTIVATE;
return myParams;
}
}
Or do I have to override a method like myForm.Show(), or

myForm.Activated()
(because the new window gets focus as soon as I call myForm.Show())

I really appreciate any hints that could lead to a solution,
thx in advance,
ekim!



Nov 16 '05 #4

P: n/a
In the second form you could call something like :

(this.parent as Form).Activate();
.....

Steph.

__________________________________________________ ____________

Stephane Orban
IT Manager
EOLE-UNICLAM
EMail : in**********@uniclam.com
Web : www.uniclam.com
Tel : +32 (0) 2 227 54 98
Fax : +32(0) 2 218 74 60

"Ekim" <th************@gmx.net> wrote in message
news:2p************@uni-berlin.de...
thanks for your answer - this would of course work if the case would be as
simple as I had described it.
but in fact I don't call the second form to be created from within this
.NET-project, but call it from a c++-win32-client via com-interop (com
callable wrappers). more detailled, I create the .NET-form as soon as the
user makes some keystrokes into an editbox of my win32-toolbar (and
therefore I MUST NOT lose focus, so that the user can keep on entering keys into my editbox) ;-(
"Mark Broadbent" <no************@no-spam-please.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
If the form is not a dialog, why dont you re-activate the original form

once
you have created the new one?
private void button1_Click(object sender, System.EventArgs e)

{

Form2 myform = new Form2();

myform.Show();

this.Activate();

}

Br,

Mark.

"Ekim" <th************@gmx.net> wrote in message
news:2p************@uni-berlin.de...
hy,

I've got a quite simple application: one windows form that consists of a button, and as soon as the user hits the button a second form shall

appear.
The difficult thing about it is that I want the new form to be created as "deactivated" - that means that the second form has an editbox in it, and this must NOT have the focus - instead, the calling form shall keep its focus.

One simple way would be to immediately set focus back after the second

form
got it, but this won't work in the future for me when I will extend my

app.
So I'm looking for a way to immediately create a window that doesn't have focus.
I've already tried overriding the CreateParams-method like this (the
WS_EX_NOACTIVATE style here is the one from CreateWindowEx in win32-sdk):

protected override CreateParams CreateParams
{
get
{
const int WS_EX_NOACTIVATE = 0x08000000;
CreateParams myParams = base.CreateParams;
myParams.ExStyle = myParams.ExStyle | WS_EX_NOACTIVATE;
return myParams;
}
}
Or do I have to override a method like myForm.Show(), or

myForm.Activated()
(because the new window gets focus as soon as I call myForm.Show())

I really appreciate any hints that could lead to a solution,
thx in advance,
ekim!



Nov 16 '05 #5

P: n/a
thx for your efforts,

indeed I've solved the problem in the meantime - although I found no
possibility to deactivate the .net-form at startup, I made some changes to
my win32-program...it's about setting the focus to the current window again
just in the right moment...however, it works, thx!
"Ekim" <th************@gmx.net> wrote in message
news:2p************@uni-berlin.de...
thanks for your answer - this would of course work if the case would be as
simple as I had described it.
but in fact I don't call the second form to be created from within this
.NET-project, but call it from a c++-win32-client via com-interop (com
callable wrappers). more detailled, I create the .NET-form as soon as the
user makes some keystrokes into an editbox of my win32-toolbar (and
therefore I MUST NOT lose focus, so that the user can keep on entering keys into my editbox) ;-(
"Mark Broadbent" <no************@no-spam-please.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
If the form is not a dialog, why dont you re-activate the original form

once
you have created the new one?
private void button1_Click(object sender, System.EventArgs e)

{

Form2 myform = new Form2();

myform.Show();

this.Activate();

}

Br,

Mark.

"Ekim" <th************@gmx.net> wrote in message
news:2p************@uni-berlin.de...
hy,

I've got a quite simple application: one windows form that consists of a button, and as soon as the user hits the button a second form shall

appear.
The difficult thing about it is that I want the new form to be created as "deactivated" - that means that the second form has an editbox in it, and this must NOT have the focus - instead, the calling form shall keep its focus.

One simple way would be to immediately set focus back after the second

form
got it, but this won't work in the future for me when I will extend my

app.
So I'm looking for a way to immediately create a window that doesn't have focus.
I've already tried overriding the CreateParams-method like this (the
WS_EX_NOACTIVATE style here is the one from CreateWindowEx in win32-sdk):

protected override CreateParams CreateParams
{
get
{
const int WS_EX_NOACTIVATE = 0x08000000;
CreateParams myParams = base.CreateParams;
myParams.ExStyle = myParams.ExStyle | WS_EX_NOACTIVATE;
return myParams;
}
}
Or do I have to override a method like myForm.Show(), or

myForm.Activated()
(because the new window gets focus as soon as I call myForm.Show())

I really appreciate any hints that could lead to a solution,
thx in advance,
ekim!



Nov 16 '05 #6

P: n/a
Great. I would have suggested Stephs method too but it wasn't strictly what
you were asking for.
I don't even think it is possible in Winforms to start form deactivated, but
would love to hear from a GUI expert to confirm this. (Im sure this question
keeps cropping up over and over)

Br,

Mark.

"Ekim" <th************@gmx.net> wrote in message
news:2p************@uni-berlin.de...
thx for your efforts,

indeed I've solved the problem in the meantime - although I found no
possibility to deactivate the .net-form at startup, I made some changes to
my win32-program...it's about setting the focus to the current window again just in the right moment...however, it works, thx!
"Ekim" <th************@gmx.net> wrote in message
news:2p************@uni-berlin.de...
thanks for your answer - this would of course work if the case would be as
simple as I had described it.
but in fact I don't call the second form to be created from within this
.NET-project, but call it from a c++-win32-client via com-interop (com
callable wrappers). more detailled, I create the .NET-form as soon as the user makes some keystrokes into an editbox of my win32-toolbar (and
therefore I MUST NOT lose focus, so that the user can keep on entering keys
into my editbox) ;-(
"Mark Broadbent" <no************@no-spam-please.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
If the form is not a dialog, why dont you re-activate the original form
once
you have created the new one?
private void button1_Click(object sender, System.EventArgs e)

{

Form2 myform = new Form2();

myform.Show();

this.Activate();

}

Br,

Mark.

"Ekim" <th************@gmx.net> wrote in message
news:2p************@uni-berlin.de...
> hy,
>
> I've got a quite simple application: one windows form that consists
of a > button, and as soon as the user hits the button a second form shall
appear.
> The difficult thing about it is that I want the new form to be
created as
> "deactivated" - that means that the second form has an editbox in
it, and
> this must NOT have the focus - instead, the calling form shall keep

its > focus.
>
> One simple way would be to immediately set focus back after the

second form
> got it, but this won't work in the future for me when I will extend my app.
> So I'm looking for a way to immediately create a window that doesn't

have
> focus.
> I've already tried overriding the CreateParams-method like this (the
> WS_EX_NOACTIVATE style here is the one from CreateWindowEx in

win32-sdk):
>
>
> protected override CreateParams CreateParams
> {
> get
> {
> const int WS_EX_NOACTIVATE = 0x08000000;
> CreateParams myParams = base.CreateParams;
> myParams.ExStyle = myParams.ExStyle | WS_EX_NOACTIVATE;
> return myParams;
> }
> }
>
>
> Or do I have to override a method like myForm.Show(), or
myForm.Activated()
> (because the new window gets focus as soon as I call myForm.Show())
>
> I really appreciate any hints that could lead to a solution,
> thx in advance,
> ekim!
>
>



Nov 16 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.