473,320 Members | 2,107 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Preventing new form from stealing focus

Hi,

I need to create a popup form what will not steal focus. I've searched
the net and I managed to put some code together.

Below is the result of my code, but I have a single question .... how
can I prevent form2 to show in taskbar? I've tried to set the
ShowInTaskBar to false, but then an exception is thrown.

Here's my code:

Form1 (master form):

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As_
System.EventArgs) Handles Button1.Click
Dim frm2 As New Form2
frm2.Show()
End Sub

Form2 (popup form):

Protected Overrides ReadOnly Property CreateParams() As_
System.Windows.Forms.CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.Style = cp.Style Or &H56000000
Return cp
End Get
End Property

How can I prevent the form to be shown in the taskbar?

Thank you in advance!!

M O J O

Nov 20 '05 #1
13 3574
Set it to minimized.

Regards - OHM#

==============
M O J O wrote:
Hi,

I need to create a popup form what will not steal focus. I've searched
the net and I managed to put some code together.

Below is the result of my code, but I have a single question .... how
can I prevent form2 to show in taskbar? I've tried to set the
ShowInTaskBar to false, but then an exception is thrown.

Here's my code:

Form1 (master form):

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As_
System.EventArgs) Handles Button1.Click
Dim frm2 As New Form2
frm2.Show()
End Sub

Form2 (popup form):

Protected Overrides ReadOnly Property CreateParams() As_
System.Windows.Forms.CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.Style = cp.Style Or &H56000000
Return cp
End Get
End Property

How can I prevent the form to be shown in the taskbar?

Thank you in advance!!

M O J O


Best Regards - OHMBest Regards - OHM On**********@BTInternet.Com
Nov 20 '05 #2
I do not understand how setting my form to minimized should prevent it
from taken focus nor showing in the task bar.

Please explain.

Thank you in advance.

M O J O

One Handed Man [ OHM ] wrote:
Set it to minimized.

Regards - OHM#

==============
M O J O wrote:
Hi,

I need to create a popup form what will not steal focus. I've searched
the net and I managed to put some code together.

Below is the result of my code, but I have a single question .... how
can I prevent form2 to show in taskbar? I've tried to set the
ShowInTaskBar to false, but then an exception is thrown.

Here's my code:

Form1 (master form):

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As_
System.EventArgs) Handles Button1.Click
Dim frm2 As New Form2
frm2.Show()
End Sub

Form2 (popup form):

Protected Overrides ReadOnly Property CreateParams() As_
System.Windows.Forms.CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.Style = cp.Style Or &H56000000
Return cp
End Get
End Property

How can I prevent the form to be shown in the taskbar?

Thank you in advance!!

M O J O

Best Regards - OHMBest Regards - OHM On**********@BTInternet.Com


Nov 20 '05 #3
* M O J O <mojo@_no_spam_delete_this_newwebsolutions.dk> scripsit:
Below is the result of my code, but I have a single question .... how
can I prevent form2 to show in taskbar? I've tried to set the
ShowInTaskBar to false, but then an exception is thrown.


Which exception?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #4
Actually, I appear to have had a mental abberation, I answered your question
without due thought, I appologise. Having thought about it though. Could you
know use the form load even to shift focus back to the parent form ?

OHM#

M O J O wrote:
I do not understand how setting my form to minimized should prevent it
from taken focus nor showing in the task bar.

Please explain.

Thank you in advance.

M O J O

One Handed Man [ OHM ] wrote:
Set it to minimized.

Regards - OHM#

==============
M O J O wrote:
Hi,

I need to create a popup form what will not steal focus. I've
searched the net and I managed to put some code together.

Below is the result of my code, but I have a single question ....
how can I prevent form2 to show in taskbar? I've tried to set the
ShowInTaskBar to false, but then an exception is thrown.

Here's my code:

Form1 (master form):

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As_
System.EventArgs) Handles Button1.Click
Dim frm2 As New Form2
frm2.Show()
End Sub

Form2 (popup form):

Protected Overrides ReadOnly Property CreateParams() As_
System.Windows.Forms.CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.Style = cp.Style Or &H56000000
Return cp
End Get
End Property

How can I prevent the form to be shown in the taskbar?

Thank you in advance!!

M O J O

Best Regards - OHMBest Regards - OHM On**********@BTInternet.Com


Regards - OHM# On**********@BTInternet.com
Nov 20 '05 #5
Hi again,

Hmmmm - I don't want form1 to lose focus at any time.

M O J O

One Handed Man [ OHM ] wrote:
Actually, I appear to have had a mental abberation, I answered your question
without due thought, I appologise. Having thought about it though. Could you
know use the form load even to shift focus back to the parent form ?

OHM#

M O J O wrote:
I do not understand how setting my form to minimized should prevent it
from taken focus nor showing in the task bar.

Please explain.

Thank you in advance.

M O J O

One Handed Man [ OHM ] wrote:
Set it to minimized.

Regards - OHM#

==============
M O J O wrote:
Hi,

I need to create a popup form what will not steal focus. I've
searched the net and I managed to put some code together.

Below is the result of my code, but I have a single question ....
how can I prevent form2 to show in taskbar? I've tried to set the
ShowInTaskBar to false, but then an exception is thrown.

Here's my code:

Form1 (master form):

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As_
System.EventArgs) Handles Button1.Click
Dim frm2 As New Form2
frm2.Show()
End Sub

Form2 (popup form):

Protected Overrides ReadOnly Property CreateParams() As_
System.Windows.Forms.CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.Style = cp.Style Or &H56000000
Return cp
End Get
End Property

How can I prevent the form to be shown in the taskbar?

Thank you in advance!!

M O J O
Best Regards - OHMBest Regards - OHM On**********@BTInternet.Com

Regards - OHM# On**********@BTInternet.com


Nov 20 '05 #6
Dear Herfried,

I couldn't provoke the exception now, don't know why I got an exception now.

If I set ShowInTaskBar to true, then focus is lost from the form1 and
form2 is never shown.

Any ideas??

Thanks!
M O J O

Herfried K. Wagner [MVP] wrote:
* M O J O <mojo@_no_spam_delete_this_newwebsolutions.dk> scripsit:
Below is the result of my code, but I have a single question .... how
can I prevent form2 to show in taskbar? I've tried to set the
ShowInTaskBar to false, but then an exception is thrown.

Which exception?


Nov 20 '05 #7
I've tried your code and I dont get and exception. Not does the form appear
in either the task bark or on screen

Regards OHM#
M O J O wrote:
Hi,

I need to create a popup form what will not steal focus. I've searched
the net and I managed to put some code together.

Below is the result of my code, but I have a single question .... how
can I prevent form2 to show in taskbar? I've tried to set the
ShowInTaskBar to false, but then an exception is thrown.

Here's my code:

Form1 (master form):

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As_
System.EventArgs) Handles Button1.Click
Dim frm2 As New Form2
frm2.Show()
End Sub

Form2 (popup form):

Protected Overrides ReadOnly Property CreateParams() As_
System.Windows.Forms.CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.Style = cp.Style Or &H56000000
Return cp
End Get
End Property

How can I prevent the form to be shown in the taskbar?

Thank you in advance!!

M O J O


Regards - OHM# On**********@BTInternet.com
Nov 20 '05 #8
Hi,

I think you may need to set the owner the form5, since form will have the
WS_CHILD style.

So you sould set the form5's owner as MainForm, this will restrict the
form5 to move inside the mainForm, but the mainform will not lost the focus.
Or you can set the form5's owner to the Desktop, this will let the form5 to
move around the desktop, but when you move the form5, the mainform will
lost the focus.

[MainForm]
Public Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal
hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
Public Declare Function GetDesktopWindow Lib "user32" Alias
"GetDesktopWindow" () As IntPtr
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim frm As New Form5
SetParent(frm.Handle, GetDesktopWindow())
frm.ShowInTaskbar = False
frm.Show()
End Sub

[MainForm]
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim frm As New Form5
frm.Owner = Me
frm.ShowInTaskbar = False
frm.Show()
End Sub

[form5]
Protected Overrides ReadOnly Property CreateParams() As
System.Windows.Forms.CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.Style = cp.Style Or &H56000000
Return cp
End Get
End Property

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Me.Close()
End Sub

If you have any concern on this issue, please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #9
Hi Peter,

I've tried to set the forms owner to Desktop, but then it doesn't show.
Hmmm strange.

I imagine that a combo box's dropdown is a form with a listbox on it.
But if I click the listbox, the dropdown form does not take focus. This
is kinda what I'm trying to archive.

Any other solutions?

Thanks!!!!!!

M O J O

Peter Huang wrote:
Hi,

I think you may need to set the owner the form5, since form will have the
WS_CHILD style.

So you sould set the form5's owner as MainForm, this will restrict the
form5 to move inside the mainForm, but the mainform will not lost the focus.
Or you can set the form5's owner to the Desktop, this will let the form5 to
move around the desktop, but when you move the form5, the mainform will
lost the focus.

[MainForm]
Public Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal
hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As Integer
Public Declare Function GetDesktopWindow Lib "user32" Alias
"GetDesktopWindow" () As IntPtr
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim frm As New Form5
SetParent(frm.Handle, GetDesktopWindow())
frm.ShowInTaskbar = False
frm.Show()
End Sub

[MainForm]
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim frm As New Form5
frm.Owner = Me
frm.ShowInTaskbar = False
frm.Show()
End Sub

[form5]
Protected Overrides ReadOnly Property CreateParams() As
System.Windows.Forms.CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.Style = cp.Style Or &H56000000
Return cp
End Get
End Property

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Me.Close()
End Sub

If you have any concern on this issue, please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Nov 20 '05 #10
Hi Mojo,

I want to make a clarify that the setparent API, is used to set the parent
of a window, not the owner. And I did not make a clear test on my code.

Here is an article about parent and owner of a window.
http://support.dundas.com/Articles/A...?ArticleID=577

It seems that you want to make an app like the combo box.

I think you may try to set the form's style as follows.
Protected Overrides ReadOnly Property CreateParams() As
System.Windows.Forms.CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.Style = cp.Style Or &H40000000
cp.ExStyle = cp.ExStyle Or &H8000000
cp.ExStyle = cp.ExStyle And (Not &H40000)
Return cp
End Get
End Property

I also has sent a sample to you.

If you have any concern on this issue please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #11
Dear Peter,

Than you for your example, but it doesn't work :o( ....

It seams like this line 'cp.Style = cp.Style Or &H40000000' blocks the
listbox, so I cannot chose ane values.

Any ideas??

Thanks again! :o)

M O J O

Peter Huang wrote:
Hi Mojo,

I want to make a clarify that the setparent API, is used to set the parent
of a window, not the owner. And I did not make a clear test on my code.

Here is an article about parent and owner of a window.
http://support.dundas.com/Articles/A...?ArticleID=577

It seems that you want to make an app like the combo box.

I think you may try to set the form's style as follows.
Protected Overrides ReadOnly Property CreateParams() As
System.Windows.Forms.CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.Style = cp.Style Or &H40000000
cp.ExStyle = cp.ExStyle Or &H8000000
cp.ExStyle = cp.ExStyle And (Not &H40000)
Return cp
End Get
End Property

I also has sent a sample to you.

If you have any concern on this issue please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Nov 20 '05 #12
Hi Mojo,

You may try to handle the MouseMove and Click event of listbox.

Private Sub ListBox1_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseMove
ListBox1.SelectedIndex = ListBox1.IndexFromPoint(New Point(e.X,
e.Y))
End Sub

Private Sub ListBox1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles ListBox1.Click
Console.WriteLine(ListBox1.SelectedItem)
End Sub

Since the ListBox can not get focus, the stuff should be down by yourself.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #13
Perfect THANKS!!!!!!!!!!!!!!!!!!!!!!

Have a nice weekend!!!!!

:o)

M O J O

Peter Huang wrote:
Hi Mojo,

You may try to handle the MouseMove and Click event of listbox.

Private Sub ListBox1_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseMove
ListBox1.SelectedIndex = ListBox1.IndexFromPoint(New Point(e.X,
e.Y))
End Sub

Private Sub ListBox1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles ListBox1.Click
Console.WriteLine(ListBox1.SelectedItem)
End Sub

Since the ListBox can not get focus, the stuff should be down by yourself.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Nov 20 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Susan Bricker | last post by:
Hi. I am opening a form (frmUserSettings) just before (or so I thought) the Main Menu form (frmMainMenu) is opening but it's not getting the focus. It gets "painted" and then the Main Menu gets...
5
by: Petec | last post by:
Is there a way to prevent a form from getting focus? Thanks! - Pete
2
by: Robert Misiak | last post by:
Is it possible to display a window on top without it stealing focus? (and I'm not talking about stealing focus from my application - I'm talking about it stealing focus from any application.) ...
0
by: gkelly | last post by:
I have an AppBar that works fine, except for one problem. It's stealing focus -The AppBar is written in C# -Access to it is via a COM object -Main app is a C++ app. -Button on app will use...
2
by: BluDog | last post by:
Hi I have a borderless form that i am using as a popup, i want to display this form without it stealing focus from the form it pops up over. I do not want to display the form modally, as when...
1
by: damonwischik | last post by:
I'm using the Python Image Library (PIL) for Python 2.4. If I have an image and I show it from PIL import Image im = Image.new('RGB',100,100) im.show() then the output window steals focus....
21
by: Sharon | last post by:
I have added an auto scroll feature to my DataGrid control like this: private void DoAutoScroll() { DataView dv = m_DataGrid.DataSource as DataView; DataGridCell cell = m_DataGrid.CurrentCell;...
2
by: Dave Booker | last post by:
I have a Windows form application that I generally run minimized. When a critical event occurs it instantiates another "Alert" form which I want to grab the user focus. In the Alert constructor...
3
by: sravan_reddy001 | last post by:
i want to prevent a form from closing.. to do this i want to handle the formClosing or FormClosed events. from here i want to prevent the form from closing. New instance of same form should...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.