473,394 Members | 1,766 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,394 software developers and data experts.

Problem with Dialog Boxes and Notify Icons

Hi there, this is probably really dumb, but I am using a dialog as my main
form and my startup form is my splash screen - which implements some
progress bars to load up some relevant data. When that is done, loading
form does this:

Me.Visible = False
mainform.ShowDialog()
Application.Exit()

So far so good (is this a dumb way of doing that???). Now, I am
implementing a notification icon in mainform. Here is some relevant stuff:

(class variable shown as boolean = true and notify icon set up correctly)

Private Sub Open_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles NotifyIcon1.DoubleClick
Me.WindowState = FormWindowState.Normal
Me.ShowInTaskbar = True
shown = True
NotifyIcon1.Visible = False
End Sub

Private Sub MainFormSizeChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.SizeChanged
If shown And Me.WindowState = FormWindowState.Minimized Then
shown = False
Me.ShowInTaskbar = False
NotifyIcon1.Visible = True
End If
End Sub

Here is the problem: When I hit the ol minimize button on mainform, the
application control is passed back to loading and the application exits
since that is the next line. What am I doing wrong/what can I adjust so
that control doesn't go back to loading when the form is minimized??

Plus, any tips on making that better are certainly welcome!

Thanks!
Nov 20 '05 #1
18 1743
"Derek Martin" <dm*****@DONTSPAMMEokstate.edu> schrieb
Hi there, this is probably really dumb, but I am using a dialog as my
main form and my startup form is my splash screen - which implements
some progress bars to load up some relevant data. When that is done,
loading form does this:

Me.Visible = False
mainform.ShowDialog()
Application.Exit()

So far so good (is this a dumb way of doing that???).
IMO not a good idea. You should only use a Form as the startup object if the
Form will always be visible from the start til the end of the application.
[...]
Here is the problem: When I hit the ol minimize button on mainform,
the application control is passed back to loading and the application
exits since that is the next line. What am I doing wrong/what can I
adjust so that control doesn't go back to loading when the form is
minimized??


ShowDialog probably exits when the Form is minimized. If you change what
I've written above, this problem should have been solved also.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2
I can live with that :-)
Any suggestions then on how to accomplish a splash screen in the main
form????
Thanks!
Derek

"Armin Zingler" <az*******@freenet.de> wrote in message
news:40***********************@news.freenet.de...
"Derek Martin" <dm*****@DONTSPAMMEokstate.edu> schrieb
Hi there, this is probably really dumb, but I am using a dialog as my
main form and my startup form is my splash screen - which implements
some progress bars to load up some relevant data. When that is done,
loading form does this:

Me.Visible = False
mainform.ShowDialog()
Application.Exit()

So far so good (is this a dumb way of doing that???).
IMO not a good idea. You should only use a Form as the startup object if

the Form will always be visible from the start til the end of the application.
[...]
Here is the problem: When I hit the ol minimize button on mainform,
the application control is passed back to loading and the application
exits since that is the next line. What am I doing wrong/what can I
adjust so that control doesn't go back to loading when the form is
minimized??


ShowDialog probably exits when the Form is minimized. If you change what
I've written above, this problem should have been solved also.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3
"Derek Martin" <dm*****@DONTSPAMMEokstate.edu> schrieb
I can live with that :-)
Any suggestions then on how to accomplish a splash screen in the
main form????


/In/ the main form or before showing the main form? I assume the latter:

shared sub main
dim splash as new splashform
dim main as mainform
splash.show
splash.refresh
main = new mainform
main.show
splash.close
application.run(main)
end sub

I only answered the question above - not the one with the NotifyIcon. ;-)

--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #4
This is the way I did my splash screen. It seems to work great.

This is the code in the main, startup form:

Private Sub Main_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

frmSplash = New frmSplash() ' my name for the form
frmSplash.ShowSplash()
' Apparently this method is available for a reason,
' so it may be better than the .ShowDialog method, etc.

' This is my own stuff for controling the splashscreen
' activity from this main form...
frmSplash.lstSplash.Items.Add("Loading...")
' This is so above changes are displayed...
frmSplash.Refresh()

' When you're done with the splashscreen...
frmSplash.Close()

End Sub
Hope that helps.

Derek Martin wrote:
Hi there, this is probably really dumb, but I am using a dialog as my main
form and my startup form is my splash screen - which implements some
progress bars to load up some relevant data. When that is done, loading
form does this:

Me.Visible = False
mainform.ShowDialog()
Application.Exit()

So far so good (is this a dumb way of doing that???). Now, I am
implementing a notification icon in mainform. Here is some relevant stuff:

(class variable shown as boolean = true and notify icon set up correctly)

Private Sub Open_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles NotifyIcon1.DoubleClick
Me.WindowState = FormWindowState.Normal
Me.ShowInTaskbar = True
shown = True
NotifyIcon1.Visible = False
End Sub

Private Sub MainFormSizeChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.SizeChanged
If shown And Me.WindowState = FormWindowState.Minimized Then
shown = False
Me.ShowInTaskbar = False
NotifyIcon1.Visible = True
End If
End Sub

Here is the problem: When I hit the ol minimize button on mainform, the
application control is passed back to loading and the application exits
since that is the next line. What am I doing wrong/what can I adjust so
that control doesn't go back to loading when the form is minimized??

Plus, any tips on making that better are certainly welcome!

Thanks!

Nov 20 '05 #5
Thank you to both for your assistance. They have aided me in learning more
about the splashes, however, my particular case seems to be a bit different.

My splash screen uses a progress bar to actually show things as they are
being done on the mainform, loading up some objects, etc. I followed some
patterns from these posts and I get to a certain part that works well, but
it doesn't lend itself to threading very easily. For instance, in the
loading code, if I am referencing the mainform by an object instead of
creating it in the loading code (here I create it in the main method), I
cannot start up a thread on that object, I'd have to recreate it which beats
the purpose. I have attached my code if anyone can assist.

Thanks!

Derek
Public Class loading
Inherits System.Windows.Forms.Form
Dim elapsed As Short = 0
Dim t As Thread
Dim mainform As main

Private Sub StartTimer_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles StartTimer.Tick
elapsed += 1
Me.Opacity = 1
If elapsed >= 10 Then
Me.StartTimer.Enabled = False
Me.beginLoadingComponents()
End If
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Me.ProgressBar1.Value += Me.ProgressBar1.Maximum / 10
If Me.ProgressBar1.Value >= Me.ProgressBar1.Maximum Then
Timer1.Enabled = False
t.Join()
Me.Hide()
Me.Cursor = Cursors.Arrow
mainform.ShowDialog(Me) 'INSTEAD OF DOING THIS, I need to pass
control to this form and dispose of this one...that way I can minimize to a
tray icon without exiting the app! Help!!!!
Application.Exit()
End If
End Sub

Private Sub beginLoadingComponents()
Me.Timer1.Enabled = True
mainform = New main
t = New Thread(AddressOf mainform.gettingstarted)
t.Start()
'mainform.gettingstarted()
End Sub

Private Overloads Sub loading_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.Cursor = Cursors.AppStarting
Me.StartTimer.Enabled = True
End Sub
End Class
Nov 20 '05 #6
"Derek Martin" <dm*****@DONTSPAMMEokstate.edu> schrieb
Thank you to both for your assistance. They have aided me in
learning more about the splashes, however, my particular case seems
to be a bit different.

My splash screen uses a progress bar to actually show things as they
are being done on the mainform, loading up some objects, etc. I
followed some patterns from these posts and I get to a certain part
that works well, but it doesn't lend itself to threading very easily.
For instance, in the loading code, if I am referencing the mainform
by an object instead of
creating it in the loading code (here I create it in the main
method), I cannot start up a thread on that object, I'd have to
recreate it which beats the purpose. I have attached my code if
anyone can assist.


If you want an independent splash screen showing the progress, you need to
create it in it's own thread. I wouldn't create the Mainform in a different
thread.

Within Class Loading (example only):

public shared sub showInstance
dim t as thread
t = new thread(addressof threadstart)
t.start
end sub

private sub threadstart
application.run(new loading)
end sub

Sub main would look like in my first example. If anything happens within the
Mainform that is to be displayed in the Splash Form, I'd raise an event in
the Mainform, handle it in the class/module containing sub main and update
the Splash Form in the event handler. But, when updating the splash Form,
you must use Begininvoke to do it because the event handler handling the
event from the Mainform is executed in the main thread, not in the thread
that created the Splash Form.

--
Armin

Nov 20 '05 #7
Thanks Armin, that went a little over my head, but I will investigate this
procedure, it sounds pretty good.
Quick question:

If the sub main() looks like your previous example, then where are you
executing showInstance in the loading class? In formload?

:-)

Derek

"Armin Zingler" <az*******@freenet.de> wrote in message
news:40***********************@news.freenet.de...
"Derek Martin" <dm*****@DONTSPAMMEokstate.edu> schrieb
Thank you to both for your assistance. They have aided me in
learning more about the splashes, however, my particular case seems
to be a bit different.

My splash screen uses a progress bar to actually show things as they
are being done on the mainform, loading up some objects, etc. I
followed some patterns from these posts and I get to a certain part
that works well, but it doesn't lend itself to threading very easily.
For instance, in the loading code, if I am referencing the mainform
by an object instead of
creating it in the loading code (here I create it in the main
method), I cannot start up a thread on that object, I'd have to
recreate it which beats the purpose. I have attached my code if
anyone can assist.
If you want an independent splash screen showing the progress, you need to
create it in it's own thread. I wouldn't create the Mainform in a

different thread.

Within Class Loading (example only):

public shared sub showInstance
dim t as thread
t = new thread(addressof threadstart)
t.start
end sub

private sub threadstart
application.run(new loading)
end sub

Sub main would look like in my first example. If anything happens within the Mainform that is to be displayed in the Splash Form, I'd raise an event in
the Mainform, handle it in the class/module containing sub main and update
the Splash Form in the event handler. But, when updating the splash Form,
you must use Begininvoke to do it because the event handler handling the
event from the Mainform is executed in the main thread, not in the thread
that created the Splash Form.

--
Armin


Nov 20 '05 #8
"Derek Martin" <dm*****@DONTSPAMMEokstate.edu> schrieb
Thanks Armin, that went a little over my head, but I will investigate
this procedure, it sounds pretty good.
Quick question:

If the sub main() looks like your previous example, then where are
you executing showInstance in the loading class? In formload?

:-)


Yes, like the previous example, the only difference is the call to
showInstance instead of Show. I renamed it afterwards.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #9
I uploaded a project to demonstrate a multithreaded splash screen:

http://people.freenet.de/armin.zingl...adedSplash.zip

(anybody knows why the main form looses focus?)

--
Armin

Nov 20 '05 #10
"Armin Zingler" <az*******@freenet.de> schrieb
I uploaded a project to demonstrate a multithreaded splash screen:

http://people.freenet.de/armin.zingl...adedSplash.zip

(anybody knows why the main form looses focus?)


...because it never gets the focus. Problem solved, project updated.
--
Armin

Nov 20 '05 #11
I just completed mine. Thanks so much for your help! Works great,
Derek

"Armin Zingler" <az*******@freenet.de> wrote in message
news:40*********************@news.freenet.de...
"Armin Zingler" <az*******@freenet.de> schrieb
I uploaded a project to demonstrate a multithreaded splash screen:

http://people.freenet.de/armin.zingl...adedSplash.zip

(anybody knows why the main form looses focus?)


..because it never gets the focus. Problem solved, project updated.
--
Armin

Nov 20 '05 #12
Hi Armin,

I think I do not understand you.

I changed it to this and I thought the mainform keeps the focus.

I want to change the one I have from you with the progres bar for this as
sample, however I want to use not the application start but the form load
and change that. Do you have a problem with that (Your name will always be
told however with a little addition that I made small but not major
changes).

Public Sub Start()
Me.Show()
RaiseEvent Progress(1, 3)
'Thread.Sleep simulates action without blocking
' the thread showing the Splashform
For i As Integer = 100 To 1000 Step 1000
Threading.Thread.Sleep(i)
Application.DoEvents()
Next
RaiseEvent Progress(2, 3)
For i As Integer = 100 To 2000 Step 100
Threading.Thread.Sleep(i)
Application.DoEvents()
Next
RaiseEvent Progress(3, 3)
End Sub
Private Sub Button1_Click(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
MessageBox.Show("hello")
End Sub

Cor
Nov 20 '05 #13
"Cor Ligthert" <no**********@planet.nl> schrieb
Hi Armin,

I think I do not understand you.

I changed it to this and I thought the mainform keeps the focus.

I want to change the one I have from you with the progres bar for
this as sample, however I want to use not the application start but
the form load and change that. Do you have a problem with that (Your
name will always be told however with a little addition that I made
small but not major changes).

Public Sub Start()
Me.Show()
RaiseEvent Progress(1, 3)
'Thread.Sleep simulates action without blocking
' the thread showing the Splashform
For i As Integer = 100 To 1000 Step 1000
Threading.Thread.Sleep(i)
Application.DoEvents()
Next
RaiseEvent Progress(2, 3)
For i As Integer = 100 To 2000 Step 100
Threading.Thread.Sleep(i)
Application.DoEvents()
Next
RaiseEvent Progress(3, 3)
End Sub
Private Sub Button1_Click(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
MessageBox.Show("hello")
End Sub

I don't understand what's your intention. Of course you can create different
situations. I also thought about it but it would have been more work to
handle them all. In the uploaded project, the work (in Sub Start) is done
before the main Form is shown. In you example, the Form is shown before, so
you can make other examples of course.
--
Armin

Nov 20 '05 #14
You had a question about the focus, that I do not understand, only one
sentence in your code gives it the focus in my idea that first me.show that
I added.

Cor
Nov 20 '05 #15
"Cor Ligthert" <no**********@planet.nl> schrieb
You had a question about the focus, that I do not understand, only
one sentence in your code gives it the focus in my idea that first
me.show that I added.


The Show was already in my code. The main form was shown /after/ the splash
form. Despite it didn't get the focus. That's what I did not understand.
After adding the MainForm.Activate() in the current version of the code, the
problem is solved, so I don't know which problem you are after.

I don't know why Show should be called 2 times. In addition, I don't want to
show the form before the initialization is completely done (in sub start),
that's why there is a splash screen.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #16
Hi Armin,

did I wrote this
uploaded a project to demonstrate a multithreaded splash screen: http://people.freenet.de/armin.zingl...adedSplash.zip (anybody knows why the main form looses focus?)


I thought it is Armin, quick start with checking however did not understand
what you mean because I was nothing, the form was hidden because the wait of
the thread, so I added a lot of code but did found nothing that let me
understand the problem.

Cor
Nov 20 '05 #17
"Cor Ligthert" <no**********@planet.nl> schrieb
Hi Armin,

did I wrote this


Is this a question??

uploaded a project to demonstrate a multithreaded splash screen:

http://people.freenet.de/armin.zingl...adedSplash.zip

(anybody knows why the main form looses focus?)


I thought it is Armin, quick start with checking however did not
understand what you mean because I was nothing, the form was hidden
because the wait of the thread, so I added a lot of code but did
found nothing that let me understand the problem.

The Form was not only hidden (visible =false). Even after the Form was
shown, it did not have the focus. It was hidden behind all other
applications, but it was visible in the taskbar and I could click on it to
bring it to front. I did (and don't) understand why.

In other words:
1. I start the exe in the explorer
2. Splash form is shown and has the focus
3. After some seconds, the Splash form disappears and the Main Form is
shown, BUT it does not have the focus. The Explorer has the focus. I have to
minimize the explorer to see the Main form behind.

After I added
MainForm.Activate()

after
MainForm.Show()

The problem was solved.

--
Armin

Nov 20 '05 #18
Hi Armin,

Is this a question??


You know where I did come from so you too now we are not that Strict as
German

Yes it was a question without a question mark.

:-)

Now I understand what you mean, in the way I did it I got the same problem,
I changed it all back to the same way you intended it, however without the
applications.start.

Than you get this code.

Private Sub MainForm_Load(ByVal sender As Object, ByVal _
e As System.EventArgs) Handles MyBase.Load
spsFrm = New SplashForm
spsFrm.AsyncShow()
AddHandler MainForm.Progress, AddressOf MainformProgress
RaiseEvent Progress(1, 3)
'Thread.Sleep simulates action without blocking
' the thread showing the Splashform
Threading.Thread.Sleep(1000)
RaiseEvent Progress(2, 3)
Threading.Thread.Sleep(3000)
RaiseEvent Progress(3, 3)
spsFrm.AsyncClose()
Me.Activate()
End Sub

I had also to add that Me.Activate to let the form get the focus.

Cor
Nov 20 '05 #19

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

Similar topics

0
by: Bruce Davis | last post by:
I'm having a problem on windows (both 2000 and XP) with a multi-threaded tkinter gui application. The problem appears to be a deadlock condition when a child thread pops up a Pmw dialog window in...
7
by: calan | last post by:
I need a dialog box with Yes, No, and Cancel buttons that pops up when a link is clicked. I'm using asp on the server side, and basically, if the user clicks yes, I want to go to a certain page...
2
by: Marian Heddesheimer | last post by:
Hi, I have a C# main form which creates a new non-modal Dialog. From the modal Dialog I can update data via a public attribute from the Dialog, but how do I notify the main window that data has...
2
by: Dennis C. Drumm | last post by:
This is a restatement of an earlier post that evidently wasn't clear. I am building a custom MessageBox dialog that has, among other things, a few new button options (yes to all, no to all, etc.)...
10
by: Zeljko | last post by:
Hi, I have a form with a tray icon. However, when I minimize the form, it stays visible - not in the task bar (I have showintaskbar property set to false), but in a form of a rectangle sitting...
3
by: jm | last post by:
Hi, I have a C# program that changes the notifyIcon during the program. What I have noticed is that sometimes when the program is over the old icon will still be in the system tray. But when i...
10
by: Opa | last post by:
I have tried for two days to solve this problem with no luck. I have a singleton class which has some events declared. When I inherit from this class the events don't seem to come along with it....
10
by: james | last post by:
My app has a notify Icon, but after the app exits, the Icon is still visible, and then when I runthe app multiple times I get multiple icons so that my status bas keeps accumulating them to the...
0
by: Vittorio Pavesi | last post by:
Hello, I'm using a notify icon and I'm trying to add icons on my menu, I took a look on http://msdn.microsoft.com/msdnmag/issues/04/02/CuttingEdge/default.aspx but on the bottom of the page there...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.