P.S. If you know how to Dim multiple variables using a For Loop or something of that kind, could you tell me.
5 Replies - 154 Views - Last Post: 15 November 2012 - 04:35 PM
#1
Trying to run code immediately after showing form
Posted 15 November 2012 - 12:12 PM
I'm working in Visual Studio 2010 and was wondering if there was a way to run code immediately after showing a form, each time you want it to be shown again. I was working on a Jeopardy game and every time I switched forms, I couldn't find a way to make it read the other form without a button or something like that. If you have suggestions, I'm open to any and all.
Thanks in advance.
P.S. If you know how to Dim multiple variables using a For Loop or something of that kind, could you tell me.
P.S. If you know how to Dim multiple variables using a For Loop or something of that kind, could you tell me.
Replies To: Trying to run code immediately after showing form
#2
Re: Trying to run code immediately after showing form
Posted 15 November 2012 - 12:19 PM
Quote
P.S. If you know how to Dim multiple variables using a For Loop or something of that kind, could you tell me.
/>
An array of what ever object type you are using.
Example:
Dim blarg(5) As foo '-- see, an array of size 5 of object type foo
For Each temp As foo In blarg '-- loop through the uninstantiated objects
temp = New foo(String.Empty, 0) '-- create the objects and provide their incoming constructor values.
Next
Quote
if there was a way to run code immediately after showing a form
The form's "shown" event should work.
#3
Re: Trying to run code immediately after showing form
Posted 15 November 2012 - 01:45 PM
Private Sub FormNum_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
BackgroundWorker1.runworkerasync()
End Sub
is how i'd do it so that as soon as the form loads it's not slowed down by trying to run extra code.
You'll need to code in a bg worker of course.
This post has been edited by LilGhost: 15 November 2012 - 01:45 PM
#4
Re: Trying to run code immediately after showing form
Posted 15 November 2012 - 02:54 PM
IsaacSims, on 15 November 2012 - 01:12 PM, said:
a way to run code immediately after showing a form, each time you want it to be shown again.
The docs for .Shown, say "The Shown event is only raised the first time a form is displayed; subsequently minimizing, maximizing, restoring, hiding, showing, or invalidating and repainting will not raise this event."
I'd try .VisibleChanged.
#5
Re: Trying to run code immediately after showing form
Posted 15 November 2012 - 04:02 PM
I'll do the .VisibleChanged, and maybe try shown if it don't work, hadn't even thought there was an event like that so thanks! I'll also try using the For Each loop in an array, definitely gonna help to not make 50+ variables.
#6
Re: Trying to run code immediately after showing form
Posted 15 November 2012 - 04:35 PM
IsaacSims, on 15 November 2012 - 05:02 PM, said:
I'll do the .VisibleChanged, and maybe try shown if it don't work, hadn't even thought there was an event like that so thanks! I'll also try using the For Each loop in an array, definitely gonna help to not make 50+ variables.
If you are looking at the Form code pane in Visual Studio, at the top are two dropdown lists. The left one lets you choose a control. Just under the Form, you'll see "Form Events", choose that one, and drop down the right hand list. There you'll see all the events you can choose to make subroutines for. Choose the one you want, and a subroutine skeleton will appear in the Form code. Fill in what you want to do, and you're all set.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote








|