5 Replies - 387 Views - Last Post: 15 November 2012 - 04:35 PM Rate Topic: -----

#1 IsaacSims  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 24-October 12

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. :helpsmilie: 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. :surrender:




Is This A Good Question/Topic? 0
  • +

Replies To: Trying to run code immediately after showing form

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9579
  • View blog
  • Posts: 36,293
  • Joined: 12-June 08

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. :surrender:/>

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.
Was This Post Helpful? 0
  • +
  • -

#3 LilGhost  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 98
  • Joined: 12-October 12

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

Was This Post Helpful? 0
  • +
  • -

#4 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Trying to run code immediately after showing form

Posted 15 November 2012 - 02:54 PM

View PostIsaacSims, 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.
Was This Post Helpful? 0
  • +
  • -

#5 IsaacSims  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 24-October 12

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.
Was This Post Helpful? 0
  • +
  • -

#6 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: Trying to run code immediately after showing form

Posted 15 November 2012 - 04:35 PM

View PostIsaacSims, 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1