Selom
Selom

Reputation: 735

How to reload windows form without closing it using VB.NET?

Can you please tell me how I can reload a windows form without closing it using VB.NET?

Upvotes: 10

Views: 121968

Answers (8)

Fernando Oviedo
Fernando Oviedo

Reputation: 1

Execute the following line:
Form_Load(sender, e)

Upvotes: 0

Jaime
Jaime

Reputation: 55

I know. I'm late to the party. But, maybe it works for who need it.

If you shows a form from other form with .ShowDialog the code after this call will be executed when the form that has been showed is closed. Example:

Private Sub button1_Click(sender As Object, e As EventArgs) Handles button1.Click
    Dim form2 As New Form2
    form2.ShowDialog
    UpdateThisForm()
End Sub

Then it's not necessary update the form from the other form (Form2).

Upvotes: 0

Etienne
Etienne

Reputation: 189

I know that it is late, but useful

Me.Controls.Clear() 'removes all the controls on the form
InitializeComponent() 'load all the controls again
Form1_Load(e, e) 'Load everything in your form, load event again

Upvotes: 13

Dan
Dan

Reputation: 77

Application.Restart()

Shuts down the application and immediately opens a new instance.

Upvotes: 5

His Lombres
His Lombres

Reputation: 13

Me.Controls.Clear() 'removes all the controls on the form
InitializeComponent() 'load all the controls again
main_Load(e, e)
MsgBox("Thank you for sending report", vbInformation, "")
Refresh()

Upvotes: 1

Eman Aboellil
Eman Aboellil

Reputation: 104

try using Me.Refresh() it worked with me

Upvotes: 2

Konrad Rudolph
Konrad Rudolph

Reputation: 546133

You cannot do that.

Why do you want to reload a form? Do you want to clear all input controls or something like that? The simplest solution might be to just do the clearing by hand.

Alternatively, you can put all your controls into a user control container. Then just instantiate that user control on your form. If you want to reload your form content, you now just need to remove and re-instantiate the user control.

Upvotes: 5

Joey
Joey

Reputation: 354854

Put all your initialization code into a method and not the constructor or the Form.Load event and just call that method. This can also include the designer-generated InitializeComponent() method which sets up all controls on the form. You should remove all controls on the form as your first action in that method, though.

Upvotes: 10

Related Questions