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

Open a Form (showdialog) but run code in the background

P: 3
Hi,

I have a VB.net project which consists of one main Form with about 5 buttons on.

When clicking on a button, this will open another Form using the button_click Sub. What I would like it to do is open the form but run a macro in the background and then close the form. The form is a kind of splash screen, a "waiting" message while code is running so it will be called multiple times from all of the buttons in the main form. For example, this is my code...

Expand|Select|Wrap|Line Numbers
  1. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles butCancel.Click
  2.  
  3.   ConnectionForm.ShowDialog()
  4.   Call Macro1()
  5.   ConnectionForm.Dispose()
  6.  
  7. End Sub
  8.  
The problem I have is that the ConnectionForm (this is the "welcome" message) opens, but doesn't run the Macro1.

I could put Macro1 inside the ConnectionForm_Load sub, but it will be a generic welcome message and it doesn't want to run the same macro every time it opens.

Anyone come across this before and have a simple solution?
Oct 23 '13 #1
Share this Question
Share on Google+
2 Replies


!NoItAll
100+
P: 296
Use form.show rather than form.showdialog.
Make sure the macro does not return until you are ready for the form to close - otherwise you need to use threading.thread.sleep after the macro...
Oct 27 '13 #2

P: 3
Blooming heck, is it really that simple? I can't believe I missed that one!!! Thank you so much for your help.

Can you advise though how I get this ConnectionForm.Show to actually show in the CenterParent rather than just the top left? The ShowDialog always shows it as the CenterParent when using the "StartPosition" property, but Show seems to ignore this.
Oct 28 '13 #3

Post your reply

Sign in to post your reply or Sign up for a free account.