Home > Net >  Turn a great god, and the two form how to switch?
Turn a great god, and the two form how to switch?

Time:11-08

Private Sub form1_Load (sender As Object, As EventArgs e) Handles MyBase. Load
Dim timer1 As New Timer
Timer1. Enabled=True
Timer1. Start ()
Timer1. Interval=300

End Sub

Private Sub Timer1_Tick (ByVal sender As System. Object, ByVal e the As System. EventArgs)
Me. Hide ()
Form2. The Show ()
End Sub

I this code, no response

CodePudding user response:

You have too many this code problem,
1. Timer1 is a local variable
2. Less Timer1_Tick also Handles statement

Changed once, to play:
 
Public Class Form1

Dim WithEvents timer1 As New Timer

Private Sub Form1_Load (sender As Object, As EventArgs e) Handles MyBase. Load

Timer1. Interval=3000
Timer1. Enabled=True

End Sub

Private Sub Timer1_Tick (sender As Object, As EventArgs e) Handles timer1. Tick

If Me. Visible Then

Me. Hide ()
Form2. The Show ()

The Else

Form2. Hide ()
Me. The Show ()

End the If

End Sub

The End of the Class

CodePudding user response:

As a form of two panel, by setting the visible to switch back and forth

CodePudding user response:

Resize form2 method is different from vb6, must first establish an instance, and then show
Dim frmNew as new form2
FrmNew. Show

There are also some problems:
Timer1. Enabled=True
Timer1. Start ()
Timer1. Interval=300
Before and after the change
Timer1. Interval=300
Timer1. Enabled=True

In addition, the timer1. Start () there is no need to use,

CodePudding user response:

Second floor of the correct answer

CodePudding user response:


Two form switch?
Code switching only a form

CodePudding user response:

reference 1st floor tengwei6328 response:
you too many questions of this code,
1. Timer1 is a local variable
2. Less Timer1_Tick also Handles statement

Changed once, to play:
 
Public Class Form1

Dim WithEvents timer1 As New Timer

Private Sub Form1_Load (sender As Object, As EventArgs e) Handles MyBase. Load

Timer1. Interval=3000
Timer1. Enabled=True

End Sub

Private Sub Timer1_Tick (sender As Object, As EventArgs e) Handles timer1. Tick

If Me. Visible Then

Me. Hide ()
Form2. The Show ()

The Else

Form2. Hide ()
Me. The Show ()

End the If

End Sub

The End of the Class

Thank the bosses

CodePudding user response:

refer to the second floor of guiyang horse Ma Shanfu plugging waterproof engineering professional maintenance of swimming pool response:
, as a form of two panel, by setting the visible to switch back and forth

Ok, I will study the

CodePudding user response:

In recent years, don't need to use the timer mechanism and so on, should be used directly Task programming framework mechanism,
 Public Class Form1 
Private Sub Form1_Load (sender As Object, As EventArgs e) Handles MyBase. Load

End Sub

Public Async Sub switch later (f the As System. Windows. Forms. The Form, the seconds As Integer)
Await Task. Delay (TimeSpan. FromSeconds (seconds))
F.S how ()
F.A ctivate ()
End Sub
End the Class

CodePudding user response:

In addition, the so-called "switch" to have a reasonable process to deal with the reality demand, want to consider switching full "end" action, such as
 Public Class Form1 
Private Sub Form1_Load (sender As Object, As EventArgs e) Handles MyBase. Load

End Sub

Public Async Function switch later (f the As System. Windows. Forms. The Form, the seconds As Integer) As a Task
Await Task. Delay (TimeSpan. FromSeconds (seconds))
F.S how ()
F.A ctivate ()
End the Function

Private Async Sub btnTest_Click (sender As Object, As EventArgs e) Handles btnTest. Click
MsgBox (" according to confirm, after 3 seconds will open the Form2 ")
Dim f As New Form2
AddHandler f.F ormClosed, Sub ()
Me. The Close ()
End Sub
Await later switch (f, 3)
Me. Hide ()
End Sub
End the Class

CodePudding user response:

Over the years the.net asynchronous programming design has a lot of support, so now also have no reason to change, but to fully use this framework to eliminate many tedious design earlier,

The example above, for example, when a modal dialog click on the "confirm" button, after 3 seconds to wander, the main thread (UI thread) not be jammed, can use the mouse to drag to test, what does not use in Form1 to use this timer, use a Task programming framework mechanism can be in any place, any frequently asynchronously multithreaded programming, (other) programming technology use range is very broad, it can be said that the Task is a technical watershed, the knowledge of the landmark,

CodePudding user response:

reference 1st floor tengwei6328 response:
you too many questions of this code,
1. Timer1 is a local variable
2. Less Timer1_Tick also Handles statement

Changed once, to play:
 
Public Class Form1

Dim WithEvents timer1 As New Timer

Private Sub Form1_Load (sender As Object, As EventArgs e) Handles MyBase. Load

Timer1. Interval=3000
Timer1. Enabled=True

End Sub

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related