help with click events

Hi,
I have a program that has a user input the height and the base of a triangle and the program gives the area and perimeter as a result in two separate text boxes. I used a two radio buttons as a click event to give me either the area or the perimeter. Question, how do i add a menu strip to do the same thing without adding a separate event?
Thanks
Pat

Comments

  • : Hi,
    : I have a program that has a user input the height and the base of a
    : triangle and the program gives the area and perimeter as a result in
    : two separate text boxes. I used a two radio buttons as a click event
    : to give me either the area or the perimeter. Question, how do i add
    : a menu strip to do the same thing without adding a separate event?
    : Thanks
    : Pat


    a good practice is to place your general code for the calculation in its own sub procedure or function, then use the click events to call that code-


    Private Sub mnuCalcArea_Click()
    'menu item click event
    CalculateArea
    End Sub

    Private Sub Option1_Click()
    'radio/option button click event
    CalculateArea
    End Sub


    Private Sub CalculateArea()
    'put code here to calculate the area
    End Sub
  • : : Hi,
    : : I have a program that has a user input the height and the base of a
    : : triangle and the program gives the area and perimeter as a result in
    : : two separate text boxes. I used a two radio buttons as a click event
    : : to give me either the area or the perimeter. Question, how do i add
    : : a menu strip to do the same thing without adding a separate event?
    : : Thanks
    : : Pat
    :
    :
    : a good practice is to place your general code for the calculation in
    : its own sub procedure or function, then use the click events to call
    : that code-
    :
    :
    : Private Sub mnuCalcArea_Click()
    : 'menu item click event
    : CalculateArea
    : End Sub
    :
    : Private Sub Option1_Click()
    : 'radio/option button click event
    : CalculateArea
    : End Sub
    :
    :
    : Private Sub CalculateArea()
    : 'put code here to calculate the area
    : End Sub
    :


    Here is the code for the fuction and the click event for the radio button and the toolmenu:

    Function first:

    Public Class Form1
    Private Function RightTriangleArea(ByVal height As Decimal, ByVal base As Decimal) As Decimal
    Return ((height * base) / 2)
    End Function

    Now the Radio button code:

    Private Sub areaTriRadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles areaTriRadioButton1.CheckedChanged
    Dim height As Decimal
    Dim base As Decimal
    Dim areatriangle As Decimal

    With Me
    Try
    height = Decimal.Parse(.heightTextBox1.Text)
    base = Decimal.Parse(.baseTextBox2.Text)

    areatriangle = RightTriangleArea(height, base)


    .areaTriTextBox5.Text = areatriangle.ToString("N")

    Catch ex As Exception
    MessageBox.Show("Amount needs to be numberic.", _
    "Data entry error", MessageBoxButtons.OK, _
    MessageBoxIcon.Information)
    With .heightTextBox1
    .Clear()
    .Focus()
    End With

    End Try
    End With
    End Sub



    And last the ToolMenu:

    Private Sub MenuStrip1_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles MenuStrip1.ItemClicked
    Dim height As Decimal
    Dim base As Decimal
    Dim areatriangle As Decimal

    With Me
    Try
    height = Decimal.Parse(.heightTextBox1.Text)
    base = Decimal.Parse(.baseTextBox2.Text)

    areatriangle = (height * base) / 2

    .areaTriTextBox5.Text = areatriangle.ToString("N")

    Catch ex As Exception
    MessageBox.Show("Amount needs to be numberic.", _
    "Data entry error", MessageBoxButtons.OK, _
    MessageBoxIcon.Information)
    With .heightTextBox1
    .Clear()
    .Focus()
    End With

    End Try
    End With
    End Sub

    How can i change this code to do what you were saying????
    Thanks
    Pat
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories