开发者

Don't know what I am doing wrong in controls

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
   开发者_StackOverflow中文版 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜