Tuesday, March 10, 2020

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.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.