I'm trying to execute a command when a Form was opened, but the command is not executed, can someone help me?
Code:
Private Sub MenuPrincipal_Load(sender As Object, e As EventArgs)
MessageBox.Show("You answered yes, yes and no.")
End Sub
Unless you have an AddHandler somewhere we can't see, you should declare that your Sub handles the event:
Private Sub MenuPrincipal_Load(sender As Object, e As EventArgs) Handles MyBase.Load
^^^^^^^^^^^^^^^^^^^
...
You want to use a command when the form opens.
Then put the command in Formload , in the example i use Form2 .
Make a Private Sub and then put the name in Load. Don't know what form you are using but changing is not so hard.
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
MenuPrincipal()
End Sub
Private Sub MenuPrincipal()
MessageBox.Show("You answered yes, yes and no.")
End Sub
Related
I'm trying to figure out how to disable my form(Form1.vb) without hiding it then enabling it after I'm done with the other form(Form2.vb).
I've searched on youtube but it says C#. I've tried it but somehow it was indicated as an error in VS 2015. I tried messing around with the syntax because I really can't figure it out. The syntax that I have tried is "LandingForm.ActiveForm.Owner.Enabled = True".
Indicated below are the codes of my system. The first one is form1.vb/LandingForm.vb and the second one is form2.vb/AcctSettings.vb.
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.Enabled = False
AcctSettings.Show()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
LandingForm.ActiveForm.Owner.Enabled = True
Me.Hide()
End Sub
Am I missing something? Can somebody help?
On your form1 just have a simple line like
Form2.Show()
wherever/however you wish to open the other form (button etc.)
then in the code for that form2 in the formload handeler have
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Form1.Enabled = False
End Sub
This will keep form1 open but basically grey it out.
Then have a simple button click like so to have access to form 1.
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Form1.Enabled = True
End Sub
And you are done! And if you wish just add another button or a IF statement to the button2 sub and say form1.enabled = false if you want to be able to enable/disable etc.
To enable/disable your userform :
To disable your userform you will need yo enable it before :
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Form1.Enabled = True
Form1.Enabled = False
End Sub
To disable it will be easier you just got to set your userform.enabled as False
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Form2.Enabled = True
End Sub
If you want to close your userform useroform.Unload might be the solution.
In your code it would be like this :
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.Enabled = False
AcctSettings.Show()
form1.Unload
End Sub
and
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
LandingForm.ActiveForm.Owner.Enabled = True
Me.Hide()
form2.Unload
End Sub
an other option is to Hide your user form : it will just hide the userform and will not release the objects and variables from the memory. Where as Unload method will release the objects and variables from the memory.
UserForm1.Hide
To conclude : Hide method will be used when we want to hide the form temorarly and to show after sometime to the user. Where as unload will be used when it completes the task.
Note that this is YourUserForm_Name.Unload
i'm just a beginner here, please help me to solve my problem, and actually i didn't have a code yet for this.
i have a 2 flow out panel and have a buttons. the Menu button in the upper side and the Menu button in the bottom side. how can i click them at the same time?
No you cannot do that, but there is a way to achieve your problem,
Do something like this,
This is only a suggestion..
Private Sub btnMenuUpper_Click(sender As Object, e As EventArgs) Handles btnMenuUpper.Click
'Code Here
End Sub
That's the first button and that will be activate also the second button.
Private Sub btnMenuBottom_Click(sender As Object, e As EventArgs) Handles btnMenuBottom.Click
'Code Here
End Sub
And just call the btnMenuBottom to btnMenuUpper.
Private Sub btnMenuUpper_Click(sender As Object, e As EventArgs) Handles btnMenuUpper.Click
'Code
btnMenuBottom_Click(sender, e)
End Sub
This should work
Private Sub btn1_click(sender as object, e as EventArgs) handles btn1.click
btn2.performclick
end sub
I searched over the Stackoverflow and Google about solution for my problem but no way! so it's the time to ask my own question.
I'm making a big project using C# and VB.net (not our topic -_-)
I opened this question to ask about VB.net problem
I'm trying to load a lot of forms but in the same time, hide the previous form!
Firstly, look here on Form1:
Private Sub Timer4_Tick(sender As Object, e As EventArgs) Handles Timer4.Tick
If Label1.Text = "Setting profile.dat=Roblox.AuthAccess ..." Then
Form2.Show()
Me.Hide()
End If
End Sub
This is a timer, which detect if Label1's Text is "Setting profile.dat=Roblox.AuthAccess ..." it must show Form2 and then close Form1 (THIS IS WORKING PERFECTLY) :-)
Form2:
Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
If WebBrowser1.Url.ToString().Contains("home") Then
Me.Hide()
Form3.Show()
End If
End Sub
This will detect if "WebBrowser1"'s URL does contain "home" then it will hide Form2 and show Form3 (AND HERE THE PROBLEM STARTED!!!)
Problem is: It shows Form3 then after 2 seconds, Form2 come back again (now both are opened once) and they're opening and closing forever (I close them by going to Task Manager and ending "vshost32.exe")
Form3:
Public Class Form3
Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Form2.Close()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Form4.Show()
End Sub
End Class
Actually, stopping timers is still not a stable solution and disabling them are more better.
Just replace Timer4.Stop() with Timer4.Enabled = False .
Thank you very much #jmcilhinney :)
I never thought about stopping every "Timer" after it's job had finished!
Just replaced Timer4_Tick with:
Private Sub Timer4_Tick(sender As Object, e As EventArgs) Handles Timer4.Tick
If Label1.Text = "Setting profile.dat=Roblox.AuthAccess ..." Then
Me.Hide()
Form2.Show()
Timer4.Stop()
End If
End Sub
So at last, I fixed that by adding Timer4.Stop() .
I'm working on a custom GUI, my last step is for the button to change automatically check if the file exists or not on startup. The method below is my download/open button. Any help is appreciated!
Private Sub Button7_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button7.Click
If Dir("DownloadedFile.zip") <> "" Then
Process.Start("DownloadedFile.zip")
Else
WC.DownloadFileAsync(New Uri("http://download852.mediafire.com/3a688rz1a6ig/dk71cs34ihs3v6x/Devil+went+down+to+georgia.rar"), "DownloadedFile.zip")
MsgBox("Starting Download")
End If
End Sub
A subroutine is a seperate method that does not return a value. I would take the If statement out of your click eventhandler and put it in its own method as I stated like this.
Private Sub CheckForFile()
If Dir("DownloadedFile.zip") <> "" Then
Process.Start("DownloadedFile.zip")
Else
WC.DownloadFileAsync(New Uri("http://download852.mediafire.com/3a688rz1a6ig/dk71cs34ihs3v6x/Devil+went+down+to+georgia.rar"), "DownloadedFile.zip")
MsgBox("Starting Download")
End If
End Sub
Call it from your button like this.
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
CheckForFile()
End Sub
Then handle the Shown Event and call it from there. It will run as soon as the initial form is shown
Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
CheckForFile()
End Sub
Responding to your comment You need to use the WebClient DownloadFileCompleted Event and the WebClient DownloadProgressChanged Event
***THE CODE FROM THE FIRST WINDOW GOES INTO A TEXT BOX AND YOU HIT THE BUTTON HERE.
Private Sub btnOk_Click(sender As Object, e As EventArgs) Handles btnOk.Click
Me.Close()
End Sub
***THE CODE ON THE FORM WHERE I WANT THE INFO TO BE PLACED IS HERE.
Private Sub Loan1Form_Load(sender As Object, e As EventArgs) Handles Me.Load
Me.lblCompanyName.Text = DataEntryForm.txtCompanyNameInput.Text
End Sub
Anyway's that's what I found on a youtube video and im having trouble getting it to work. Any help would be appreciated.
Thanks.
Pass the data to an instance of the form:
Private Sub btnOk_Click(sender As Object, e As EventArgs) Handles btnOk.Click
Dim f As New OtherForm
f.lblCompanyName.Text = txtCompanyNameInput.Text
f.Show()
Me.Close() 'make sure this form is not the one that closes the app if it closes
End Sub