| | |
A small calculator in vb
Please support our VB.NET advertiser: Programming Forums - DaniWeb Sister Site
![]() |
Normal buttons require ALT-key to be pressed. If you don't mind this, name the buttons
and trap "number"-buttons
If you do not want ALT-key to be used, you have to trap KeyUp or similar event and use some other control instead of Button control.
VB.NET Syntax (Toggle Plain Text)
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ' Button1.Text = "&1" Button2.Text = "&2" End Sub
VB.NET Syntax (Toggle Plain Text)
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click, Button2.Click Select Case CType(sender, Button).Text Case "&1" ' Number 1 pressed Case "&2" ' Number 2 pressed End Select End Sub
Teme64 @ Windows Developer Blog
•
•
Join Date: Dec 2007
Posts: 19
Reputation:
Solved Threads: 4
I assume you have your click event sub proceedure running, to add another event for a button say "button1" you have to make sure you have enable its 'tabstop' property and then you can add another event sub proceedure.
However for your calculator, when the tabstop gets to the 'btn1' button all the user has to do is to press the "enter key".
This is in simple context, however you may have to implement threading for complex scenario where you need responses. (My opinion)
I am leaving you with some code snippet for your review, it may help.
[CODE syntax=vb]
Private Sub btn1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles btn1.KeyPress
Dim keyasc As Short
If keyasc >= System.Windows.Forms.Keys.D1 And keyasc <= System.Windows.Forms.Keys.D9 Then
txtDisplay.Text = Val(btn1.Text)
Exit Sub
Else
MessageBox.Show("Error key pressed")
End If
End Sub
[/CODE]
However for your calculator, when the tabstop gets to the 'btn1' button all the user has to do is to press the "enter key".
This is in simple context, however you may have to implement threading for complex scenario where you need responses. (My opinion)
I am leaving you with some code snippet for your review, it may help.
[CODE syntax=vb]
Private Sub btn1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles btn1.KeyPress
Dim keyasc As Short
If keyasc >= System.Windows.Forms.Keys.D1 And keyasc <= System.Windows.Forms.Keys.D9 Then
txtDisplay.Text = Val(btn1.Text)
Exit Sub
Else
MessageBox.Show("Error key pressed")
End If
End Sub
[/CODE]
Last edited by hakimkal; Dec 24th, 2008 at 2:14 am.
abdoolherkym!
![]() |
Similar Threads
- wage calculator HELP (VB.NET)
- Calculator Missing - help please (Windows NT / 2000 / XP)
- need help with 16 - bit calculator (Assembly)
- Pascal calculator program (Pascal and Delphi)
- Help me for application (Python)
- js calculator (JavaScript / DHTML / AJAX)
- calculator (C)
- c# or vb.net - how earn more? (C#)
- Calculator GUI (Java)
- Need help with basic assembly calculator (Assembly)
Other Threads in the VB.NET Forum
- Previous Thread: This Vb.Net code will copy a file to a location and its extension
- Next Thread: Dataset Problem
Views: 1421 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for VB.NET
"crystal .net .net2005 30minutes 2008 access application arithmetic array assignment basic binary box button buttons center code combobox component connectionstring convert cpu data database databasesearch datagrid datagridview design designer dissertation dissertations dissertationthesis dll dosconsolevb.net editvb.net error excel firewall folder highlighting image images isnumericfuntioncall listview login math memory mobile ms mssqlbackend mysql navigate net opacity pan peertopeervideostreaming picturebox picturebox1 plugin port print printing printpreview problem problemwithinstallation project record reports" reuse save savedialog serial server sorting sql storedprocedure string structures studio temp textbox timer updown upload useraccounts usercontrol vb vb.net vb.netcode vb.nettoolboxvisualbasic2008sidebar vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web wpf





