Greetings and salutations. I really need help for school.
This is what I'm dealing with:
Cannot make selection until one option is picked.
The "You have selected a hostel location" text shouldn't show up until "Select Location" is pressed.
My assignment is a hostel selection, allowing the user to select one or the other. Once the selection is made via btnselect, lblselected is supposed to show up, then the window is supposed to close.
Please help me. I have no idea what I'm doing. I'm a web designer trying to expand my knowledge.
Option Explicit On
Public Class frmhostelselection
Private Sub btnlondon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlondon.Click
End Sub
Private Sub btndublin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndublin.Click
End Sub
Private Sub btnselect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnselect.Click
End Sub
Private Sub btnexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnexit.Click
End Sub
Private Sub lblselected_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblselected.Click
End Sub
Private Sub lblmsg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblmsg.Click
End Sub
End Class
Ok, i get you a logic
First on you loadsub
you must add
londonlistbox.enabled = false
dublinlistbox.enabled = false
then, add to you london button
dublinlistbox.enabled = false
london.enabled = false
and add the opposite to the dublin button
then, select location
select case londonlistbox and dublinlistbox
case londonlistbox.enabled = true
label1.text = londonlistbox.selecteditems
case dublinlistbox.enabled = true
label1.text = dublinlistbox.selecteditems
that's all
You want to hide the label. In visual studio, you want to select the label, and set its visible value to false. Or you can set it to be invisible for the formload event.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
lblselected.visible = false
end sub
You then need it to show for the button click event.
lblselected.visible = true
From your picture i am unsure what the buttons are to do. You seem to have 2 actual locations to choose (as buttons) and another button which seems to act as a select button.
You also have requested a select case command in your question.
So perhaps you want t select case to load when you click the select location button, and that a value will be set if you click either of the other buttons?
As above said, you have made no attempt to try this yourself, so i won't write the code, but it sounds like you want this...
The 2nd label should be invisible until the select button is clicked.
You want to string or something that will identify what has been pressed. This string should be a global variable that is declared beneath the public path.
When either londen button or... other button is pressed, the global string should change to either London or...Dublin.
When you press the select button, it should load a select case method which will check for either london or dublin.
Select case globalstring
case "London"
' make label visible, maybe change lblselected text to reflect that London was pressed.
case "Dublin"
' Make label visible, maybe change lblselected text to reflect that Dublin was pressed.
case default
' Produce an error message saying that nothing was pressed.
end Select
I'm guessing you also want images to show in those pictureboxs. Use initial image to get that one.
And the exit button will just be me.close()
Related
I have this six button
After i press one button, for example i press settings it will open an new windows after i close that windows the button remain pressed.
Here are the settings button code:
Private Sub btn_SETTINGS_MouseEnter(sender As System.Object, e As System.EventArgs) Handles btn_SETTINGS.MouseEnter
btn_SETTINGS.ForeColor = Color.White
End Sub
Private Sub btn_SETTINGS_MouseLeave(sender As System.Object, e As System.EventArgs) Handles btn_SETTINGS.MouseLeave
btn_SETTINGS.ForeColor = SystemColors.HotTrack
End Sub
Private Sub btn_SETTINGS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_SETTINGS.Click
OpenSettings()
End Sub
Any suggestion what can i do to fix this problem.
Okay, this problem seems related to Focus that got set to the button when you pressed it. Very easy and quick fix of this problem is, change the focus of control to some other control. On the same side, add one label control which is of Hidden type say lblHidden. So when you're doing following code then change focus.
Private Sub btn_SETTINGS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_SETTINGS.Click
OpenSettings()
Me.ActiveControl = lblHidden
End Sub
This will change the focus to hidden control. However if you are doing any formatting change of button on click event then revert it back to original in above even.t
I have trouble in coding in this area. I have a two forms. In the first form, i have list view that when i checked the checkbox, i will click the button to show the 2nd form and the 2nd form will show the item that i selected in first form.
but i have error like this: InvalidArgument=Value of '0' is not valid for 'index'. Parameter name: index
This is my code:
'View Technicians Daily Task Code
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e _
As System.EventArgs) Handles Button3.Click
frm_pe.Show()
Me.Close
frm_pe.txtid.Text = ListView1.CheckedItems(0).SubItems(0).Text
frm_pe.txtlname.Text = ListView1.CheckedItems(0).SubItems(1).Text
frm_pe.txtfname.Text = ListView1.CheckedItems(0).SubItems(2).Text
frm_pe.txtmi.Text = ListView1.CheckedItems(0).SubItems(3).Text
End Sub
Don't close the first form until you have gathered the data you want, instead wait to close the form like this:
'View Technicians Daily Task Code
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e _
As System.EventArgs) Handles Button3.Click
frm_pe.Show()
frm_pe.txtid.Text = ListView1.CheckedItems(0).SubItems(0).Text
frm_pe.txtlname.Text = ListView1.CheckedItems(0).SubItems(1).Text
frm_pe.txtfname.Text = ListView1.CheckedItems(0).SubItems(2).Text
frm_pe.txtmi.Text = ListView1.CheckedItems(0).SubItems(3).Text
Me.Close
End Sub
OR
You can just hide the form, like this:
Me.Hide
Note: Hiding the form will still keep the form in memory, but make it invisible to the user.
I have an event in VB.NET to handle several button clicks at once. I need to know which button from the selection kicked off the event. Any ideas how to do this? My code is below:
Private Sub Answer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAnswer1.Click, btnAnswer2.Click, btnAnswer3.Click, btnAnswer4.Click
'output button ID that caused event
End Sub
I've tried sender.Id, e.Id, sender.name, e.name. None of them work
You have to cast the sender to the object type expected.
Dim btn As Button = CType(sender, Button)
Then you can access what you need.
Try CType(Sender, Button).Name. Sender is an Object you need to cast to the calling Type in this case Button. If you need more properties from the Sender then use U1199880 's answer. But usually when I am trying to handle multiple clicks I will use the Tag property, assign an index to it. Something like this.
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click, Button2.Click, Button3.Click
Dim index As Integer
If Not Integer.TryParse(CType(sender, Button).Tag.ToString, index) Then Exit Sub
Select Case index
Case 0
Case 1
Case 2
....
End Select
End Sub
Even simpler:
If sender is btnAnswer1 then ...
I have created the text box, and the generate button.
when I click on the generate button, I want it to display a text box with numbers. How do I do so using the event handler?. Sorry, basic question.
If all that you are trying to do is to set the value of a text box when a button is clicked, then you can do it like in the following example. You'll have to replace the names of the controls with whatever you have called them:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Static count As Integer = 0
count += 1
Select Case count
Case 1
TextBox1.Text = "123"
Case 2
TextBox1.Text = "345"
End Select
End Sub
First, drag a TextBox from your tool box, then double-click on your button and edit your Button1_Click method, like this:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = "12234234234"
End Sub
Ok Here is what I have so far. I am trying to do the checkbox so that way only one is check at a time. But for some reason they both will check. And another thing I have the labels on there but in the radiobuttons no matter which one you check and submit it only stats the bottom one. Can someone help me and tell me what I am doing wrong...
Public Class Form1
Dim Message As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load, MaskedTextBox1.TextChanged
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
If TextBox1.Text <> "" Then
ErrorProvider1.Clear()
Label1.Text = TextBox1.Text
Else
ErrorProvider1.SetError(TextBox1, "Please enter text")
End If
End Sub
Private Sub MonthCalendar1_DateChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles MonthCalendar1.DateChanged
Me.Text = Me.MonthCalendar1.SelectionRange.Start.ToShortDateString
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Label2.Text = MaskedTextBox1.Text
Label3.Text = RadioButton1.Text
Label3.Text = RadioButton2.Text
Label3.Text = RadioButton3.Text
Label4.Text = CheckBox1.Text
Label5.Text = CheckBox2.Text
Label6.Text = MonthCalendar1.Text
Dim message As String
message = ""
If CheckBox1.Checked Then
message += "first one clicked"
End If
If CheckBox2.Checked Then
message += " second one clicked"
End If
MessageBox.Show(message)
End Sub
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged, RadioButton2.CheckedChanged, RadioButton1.CheckedChanged
Dim radMessage As RadioButton = CType(sender, RadioButton)
If radMessage.Checked Then
Message = radMessage.Text
End If
End Sub
End Class
Ok and this is suppose to be what my commands are suppose to be doing..
Create a new window Project .change the title of the form to Lab3.drag the following controls to your form,textbox,masked textbox (set to phone number),3 radiobuttons in a groupbox(container control),2 checkboxes, Month calendar,all on the left of the form,add a label for each control on the right, add an errorprovider for the textbox and insure it has data entered, add tooltips to every control, add a button
Task
When the user mouses over any control on the left they get a tooltip, change the text on the button to "Submit", when the user clocks the button, the info from the controls on the left appears in the label on the right,if no data is entered in the textbox use the errorprovider control to prompt the user for data, only use 1 label for all three radiobuttons, Only display each check box data if the check boxes checked, make sure to add code to erase the appropriate label if the user UNCHECKS a check box, set the tab order of the controls so you can tab though them in order down the left side, look on the internet to find out how to rettrieve the selected date from the calendar control when the user clicks the button.
I am not expecting anyone to do this for me. I am trying to do the code but i know i mest up some where. I am still a newbie at this so sorry.
I don't expect this answer to solve all of your problems but hopefully it should prove a starting point.
Firstly, why do you want only one checkbox to be selected at any moment? I can't see that as a requirement in your task? By default checkboxes do not exhibit that behaviour (that is what radio buttons are for), but they can be made to. To do this you would need to look at the selected_change event of the checkbox and when one is selected, deselect all the others. However before you do that, make sure it is what you are after before progressing.
With the radio buttons issue, I am assuming you want to set the text of the selected radio button into a label? Well currently you are assigning the selected text into a field, Message, but you are not using this anywhere else. When you set up your labels you have the following:
Label3.Text = RadioButton1.Text
Label3.Text = RadioButton2.Text
Label3.Text = RadioButton3.Text
Whereas I am guessing you need something along the lines of
Label3.Text = Message
At the moment you are setting the same Label text three times and only the third radio button text will be displayed.
On another note I would possibly think about using different variable names that Message as it could result in some confusion later on.
Hope that gets you somewhere