Computing.Net > Forums > Programming > VB.NET buttons change properties?

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

VB.NET buttons change properties?

Reply to Message Icon

Original Message
Name: tImmaY
Date: November 5, 2004 at 12:17:29 Pacific
Subject: VB.NET buttons change properties?
OS: Windows XP Pro SP1
CPU/Ram: AMD Athlon XP 2400+ / 512
Comment:

Hello, i'm trying to make a program that will convert temperatures (Celsius, Fahrenheit, and Kelvin) and i have to have like, 6 buttons at the top of the program that when you click them, the text box for you to input the number will appear and i want the default text boxes to not be visible. right now, i have the program with the buttons, a text box and a description. the visibility is false on the text box, but how do i make it change to true when you click a button? also, how could i use the same text box for each button OR use different text boxes all in the same location? thanks in advance ::tim


Report Offensive Message For Removal


Response Number 1
Name: Robcowell
Date: November 5, 2004 at 15:56:11 Pacific
Reply: (edit)

Hi there!!,

Instead of buttons go for the toolbar approach with a menu item called Temperature and a drop down menu with all the temperature ranges in it, this way you can do the following with the code;

n.b This works in VB6, im not sure if vb.net can support this but give it a whirl..

Private Sub mnuTemperatureCelcius_Click()

mnuTemperatureCelcius.Enabled = False
mnuTemperatureFahreheit.Enabled = True
mnuTemperatureKelvin.Enabled = True

TextBox.Caption = "You have selected to work in Celcius!"

End Sub
------

Private Sub mnuTemperatureFahrenheit_Click()

mnuTemperatureCelcius.Enabled = True
mnuTemperatureFahreheit.Enabled = False
mnuTemperatureKelvin.Enabled = True

TextBox.Caption = "You have selected to work in Fahreheit!"

End Sub
----

Private Sub mnuTemperatureKelvin_Click()

mnuTemperatureCelcius.Enabled = True
mnuTemperatureFahreheit.Enabled = True
mnuTemperatureKelvin.Enabled = False

TextBox.Caption = "You have selected to work in Kelvin!"

End Sub

------------

When you goto the toolbar and select Temperature in the dropdown box you can select only one of the Temperature ranges at any one time....all the other ranges will be shadowed!!

Hope this helps and Good Luck

Rob :-)


Report Offensive Follow Up For Removal

Response Number 2
Name: tImmaY
Date: November 5, 2004 at 23:07:09 Pacific
Reply: (edit)

hmm.. i dont really understand how that works. lol but i did find the Main Menu maker in VB.NET.. so i deleted my buttons and now i have all of the options in a menu. i also have an "about" portion that pops up a messagebox, which is the only thing that works besides the Exit feature that i just got figured out. but depending on the users choice, how do i know which one they want to work with..? like, because i'd have to know so that i could have it use the correct formula...


Report Offensive Follow Up For Removal

Response Number 3
Name: tImmaY
Date: November 5, 2004 at 23:39:47 Pacific
Reply: (edit)

hmm.. with a little research and some craftiness on my part, i've gotten the program to convert celsius to fahrenheit!! here's my code so far.. i think if i keep doing what i'm doing, then i can make all of the formula's work with each selection in the menu. but also, i think i'd like to put like a label at the top of the program that tells the user which temps they're converting to whom. lol so how could i do that? because i could have the label take input from a variable at the end? like "You are currently convertin: var1 to var2"

/*code*/
Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button7 As System.Windows.Forms.Button
Friend WithEvents CtoFinput As System.Windows.Forms.TextBox
Friend WithEvents CtoFtext As System.Windows.Forms.Label
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem11 As System.Windows.Forms.MenuItem
Friend WithEvents ConvertTemp As System.Windows.Forms.MenuItem
Friend WithEvents CtoF As System.Windows.Forms.MenuItem
Friend WithEvents CtoK As System.Windows.Forms.MenuItem
Friend WithEvents FtoC As System.Windows.Forms.MenuItem
Friend WithEvents FtoK As System.Windows.Forms.MenuItem
Friend WithEvents KtoC As System.Windows.Forms.MenuItem
Friend WithEvents KtoF As System.Windows.Forms.MenuItem
Friend WithEvents Shibby As System.Windows.Forms.MenuItem
Friend WithEvents ShibbyAbout As System.Windows.Forms.MenuItem
Friend WithEvents Close As System.Windows.Forms.MenuItem
Friend WithEvents Result As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.CtoFinput = New System.Windows.Forms.TextBox
Me.Button7 = New System.Windows.Forms.Button
Me.Result = New System.Windows.Forms.TextBox
Me.CtoFtext = New System.Windows.Forms.Label
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.MenuItem1 = New System.Windows.Forms.MenuItem
Me.ConvertTemp = New System.Windows.Forms.MenuItem
Me.CtoF = New System.Windows.Forms.MenuItem
Me.CtoK = New System.Windows.Forms.MenuItem
Me.FtoC = New System.Windows.Forms.MenuItem
Me.FtoK = New System.Windows.Forms.MenuItem
Me.KtoC = New System.Windows.Forms.MenuItem
Me.KtoF = New System.Windows.Forms.MenuItem
Me.MenuItem11 = New System.Windows.Forms.MenuItem
Me.Close = New System.Windows.Forms.MenuItem
Me.Shibby = New System.Windows.Forms.MenuItem
Me.ShibbyAbout = New System.Windows.Forms.MenuItem
Me.SuspendLayout()
'
'CtoFinput
'
Me.CtoFinput.Location = New System.Drawing.Point(88, 88)
Me.CtoFinput.Name = "CtoFinput"
Me.CtoFinput.Size = New System.Drawing.Size(120, 20)
Me.CtoFinput.TabIndex = 7
Me.CtoFinput.Text = ""
Me.CtoFinput.Visible = False
'
'Button7
'
Me.Button7.Location = New System.Drawing.Point(16, 200)
Me.Button7.Name = "Button7"
Me.Button7.TabIndex = 9
Me.Button7.Text = "Convert!"
'
'Result
'
Me.Result.Location = New System.Drawing.Point(112, 200)
Me.Result.Name = "Result"
Me.Result.Size = New System.Drawing.Size(168, 20)
Me.Result.TabIndex = 10
Me.Result.Text = ""
'
'CtoFtext
'
Me.CtoFtext.Location = New System.Drawing.Point(80, 64)
Me.CtoFtext.Name = "CtoFtext"
Me.CtoFtext.Size = New System.Drawing.Size(152, 23)
Me.CtoFtext.TabIndex = 11
Me.CtoFtext.Text = "Please input the temperature."
Me.CtoFtext.Visible = False
'
'MainMenu1
'
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.Shibby})
'
'MenuItem1
'
Me.MenuItem1.Index = 0
Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.ConvertTemp, Me.MenuItem11, Me.Close})
Me.MenuItem1.Text = "File"
'
'ConvertTemp
'
Me.ConvertTemp.Index = 0
Me.ConvertTemp.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.CtoF, Me.CtoK, Me.FtoC, Me.FtoK, Me.KtoC, Me.KtoF})
Me.ConvertTemp.Text = "Convert Temp"
'
'CtoF
'
Me.CtoF.Index = 0
Me.CtoF.Text = "Celsius to Fahrenheit"
'
'CtoK
'
Me.CtoK.Index = 1
Me.CtoK.Text = "Celsius to Kelvin"
'
'FtoC
'
Me.FtoC.Index = 2
Me.FtoC.Text = "Fahrenheit to Celsius"
'
'FtoK
'
Me.FtoK.Index = 3
Me.FtoK.Text = "Fahrenheit to Kelvin"
'
'KtoC
'
Me.KtoC.Index = 4
Me.KtoC.Text = "Kelvin to Celsius"
'
'KtoF
'
Me.KtoF.Index = 5
Me.KtoF.Text = "Kelvin to Fahrenheit"
'
'MenuItem11
'
Me.MenuItem11.Index = 1
Me.MenuItem11.Text = "----------------"
'
'Close
'
Me.Close.Index = 2
Me.Close.Text = "Exit"
'
'Shibby
'
Me.Shibby.Index = 1
Me.Shibby.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.ShibbyAbout})
Me.Shibby.Text = "Shibby"
'
'ShibbyAbout
'
Me.ShibbyAbout.Index = 0
Me.ShibbyAbout.Text = "About..."
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(344, 266)
Me.Controls.Add(Me.CtoFtext)
Me.Controls.Add(Me.Result)
Me.Controls.Add(Me.Button7)
Me.Controls.Add(Me.CtoFinput)
Me.Menu = Me.MainMenu1
Me.Name = "Form1"
Me.Text = "Temperature Converter - Shibby Inc. © "
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ClassVar.choice = 0
End Sub

Private Sub ShibbyAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShibbyAbout.Click
MessageBox.Show("Shibby Inc. was founded by Tim Hansen and Chris Foreman.", "About Shibby Inc.", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub

Private Sub Close_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Close.Click
MyBase.Close()
End Sub

Private Sub CtoF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CtoF.Click
ClassVar.choice = 1
CtoFtext.Visible = True
CtoFinput.Visible = True
End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Dim formula
Dim c As Integer
c = Val(CtoFinput.Text)
If ClassVar.choice = 1 Then
formula = (9 / 5) * c + 32
Result.Text = Str$(formula)
End If
End Sub
End Class

Public Class ClassVar
Public Shared choice As Integer
End Class


Report Offensive Follow Up For Removal

Response Number 4
Name: tImmaY
Date: November 7, 2004 at 02:31:14 Pacific
Reply: (edit)

hey, i got my program done and all of the formula's work correctly and such, but if someone has a problem with the program then i'd like to know about it so i added a link. only problem is - i dont know how to make the link go somewhere when its clicked.. SO how do i accomplish this task?


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge
Poll History




Data Recovery Software