Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form question

Status
Not open for further replies.

kurgan383

IS-IT--Management
Jan 7, 2003
17
US
I want to have something run in a form as soon as the form starts (i don't want to wait for a button to be pressed or anything) anyone know how to do this?

tom
 
I tried that, but i can't see my form on the screen?!

tom
 
try the form_activated event and if you only want your code to run the first time the form appears, set a flag after running your code and check it before running the code.
 
If that didnt make sense here's some code. If you want to know why the flag is important, try removing the "tstflag=true" line.

Public Class Form1
Inherits System.Windows.Forms.Form
Dim tstflag As Boolean

Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
If Not tstFlag Then
MsgBox("Your code here")
tstflag = True
End If
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
tstFlag = False
End Sub
end class
 
That was it! I wonder why form_load DIDN't work, but Form1_Activated did?? If anyone knows, I'd love to hear it! Anyway, thanks everyone for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top