Sunday, November 24, 2019
Difference Between Form1.Hide and Unload Me in VB 6
Difference Between Form1.Hide and Unload Me in VB 6 Hide and Unload are techniques in Visualà Basic 6- VB.NET does things differently. In VB6, you can see the difference clearly by creating a form with a CommandButton component and a test statement in the Click event. Note that these two statements are mutually exclusive, so only one can be tested at a time. Visual Basic 6 Unload Statement The Unload statement removes the form from memory. In most simple VB6 projects, Form1 is the startup object so the program stops running too. To prove this, code the first program with Unload. Private Sub Command1_Click()à à à Unload MeEnd Sub When the button is clicked in this project, the program stops. Visual Basic 6Hide Statement To demonstrateà Hide, run this code in VB6 so the Hide method of Form1 is executed. Private Sub Command1_Click()à à à Form1.HideEnd Sub Notice that Form1 disappears from the screen, but the square End icon on the Debug toolbar showsà the project is still active. If youre in doubt, the Windows Task Manager that is displayed with CtrlAltDel shows the project is still in Run mode. Communicating With a Hidden Form The Hide method only removes the form from the screen. Nothing else changes. For example, another process can still communicate with objects on the form after the Hide method is called. Heres a program that demonstrates that. Add another form to the VB6 project and then add a Timer componentà and this code to Form1: Private Sub Command1_Click()à à à Form1.Hideà à à Form2.ShowEnd Sub Private Sub Timer1_Timer()à à à Form2.Hideà à à Form1.ShowEnd Sub In Form2, add a Command button control and this code: Private Sub Command1_Click()à à à Form1.Timer1.Interval 10000 10 secondsà à à Form1.Timer1.Enabled TrueEnd Sub When you run the project, clicking the button on Form1 makes Form1 disappear and Form2 appear. However, clicking the button on Form2 uses the Timer component on Form1 to wait 10 seconds before making Form2 disappear and Form1 appear again even though Form1 isnt visible. Since the project is still running, Form1 keeps appearing every 10 seconds- a technique you might use to drive a coworker batty one day.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.