3 Replies - 256 Views - Last Post: 07 December 2017 - 02:15 PM Rate Topic: -----

#1 shiftadelete   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 71
  • Joined: 04-November 16

Hide() Command

Posted 07 December 2017 - 01:17 PM

Hello,
I am trying to make a calculator in vb.net form application.And I added operations in comboBox I want to factorial calculation. Normally I have two textboxes to input two numbers but, in factorial calculation I only need one textBox so when the user choose factorial in the list, it will hide textBox2. But in my code when I choose factorial it doesn't hide suddenly it only hides after calculation..

  If ComboBox1.SelectedIndex = 6 Then
            TextBox2.Hide()
            Label2.Hide()
            Dim fact = 1
            Dim i
            For i = 1 To Val(TextBox1.Text)
                fact *= i
            Next
            Label3.Text = fact
            Label3.Text = TextBox1.Text & " ! " & " = " & Label3.Text

        End If


Before calculate:
https://imgur.com/a/KjuVK
After calculate:
https://imgur.com/a/CwPvW

Is This A Good Question/Topic? 0
  • +

Replies To: Hide() Command

#2 shiftadelete   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 71
  • Joined: 04-November 16

Re: Hide() Command

Posted 07 December 2017 - 01:33 PM

TextBox2.Enabled = False

      Label2.Enabled = False


better than hide() but still same.
Was This Post Helpful? 0
  • +
  • -

#3 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14095
  • View blog
  • Posts: 56,482
  • Joined: 12-June 08

Re: Hide() Command

Posted 07 December 2017 - 02:10 PM

The calculations are sucking up the UI time before it has a chance to update. perhaps repaint, throw a wait in there, or what ever.

For fair warning - disabling is preferred over hiding.
Was This Post Helpful? 0
  • +
  • -

#4 IronRazer   User is offline

  • Custom Control Freak
  • member icon

Reputation: 1502
  • View blog
  • Posts: 3,799
  • Joined: 01-February 13

Re: Hide() Command

Posted 07 December 2017 - 02:15 PM

So... what event do you have this code in? Perhaps you should add the code to hide the label and/or textbox in the ComboBox's SelectedIndexChanged event so that they are hidden as soon as the user changes the selected item in the ComboBox.

I would also recommend using the Visible property of the Label and TextBox instead of the Hide method.

For example...
    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
        If ComboBox1.SelectedIndex = 6 Then
            Label1.Visible = False
            TextBox1.Visible = False
        Else
            Label1.Visible = True
            TextBox1.Visible = True
        End If
    End Sub


Was This Post Helpful? 1
  • +
  • -

Page 1 of 1