| | |
A small calculator in vb
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
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
| Thread Tools | Search this Thread |
.net .net2008 2008 access advanced application array basic beginner browser button buttons center click client code combo convert cuesent data database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic eclipse excel exists fade filter forms function generatetags html images input intel internet listview map mobile module monitor msaccess net number objects open panel pdf picturebox picturebox2 port position print printing problem read regex remove right-to-left save search searchvb.net select serial settings shutdown socket sqldatbase sqlserver survey temperature textbox timer timespan transparency txttoxmlconverter user usercontol vb vb.net vba vbnet visual visualbasic visualbasic.net visualstudio.net visualstudio2008 web winforms winsock wpf wrapingcode xml year





