I am developing a calculator app for Windows. I want to create a numeric keypad that has ONLY numbers and the decimal points. How do I create one and pop it up whenever the user selects ANY textbox?
Thanks and Regards,
S Sandeep
Well, I guess I got the answer myself:
I added two boolean variables in the form declarations called yesfocusedtxtno1 and yesfocusedtxtno2. I used them in the GotFocus() method of both textboxes and kept changing the variables accordingly. For example if txtno1 has the focus, I say yesfocusedtxtno2 = False and yesfocusedtxtno1 = true. Then I added this code in the OnClick method of each button in the keypad. (I've just given one for sample.)
Dim keynum As String = "1"
If yesfocusedtxtno1 = True Then
txtNo1.Focus()
txtNo1.Text = txtNo1.Text + keynum
Else
txtNo2.Focus()
txtNo2.Text = txtNo2.Text + keynum
End If
Related
i used to have some code that worked "kinda" ok for a stocktaking application. Where the user can scan a product and then enter the value of how many they have counted. i added the ability to be able to press the "+" key on the numpad and it would add the value that was already in the cell to the value you now entered in. so for example you counted 2 and then later you find more of the same product you now press + 5 and the cell would then show 7.
i had to use this stocktaking application today, and noticed the + function didnt work. when i looked at my code later tonight, there is no code there to handle the + and add the values. and for the life of me i cant remember how i got this working.
this is the code thats remaing so far.
STCellValue is a public integer value that stores the value already in the cell.
Private Sub DataGridView1_CellBeginEdit...
If Not IsDBNull(DataGridView1.Rows(rowindex).Cells("COUNTED").Value) Then
If STAddKeyPressed = True Then STCellValue =
CInt(DataGridView1.Rows(rowindex).Cells("COUNTED").Value)
ElseIf STAddKeyPressed = True Then
STCellValue = 0
End If
STAddKeyPressed is a boolean public value that is changed to true on the keydown event for the datagridview.
Private Sub DataGridView1_KeyDown(....
If e.KeyCode = Keys.Escape Then
'does things for escape key
ElseIf e.KeyCode = Keys.Add And FILE_Advanced_StocktakeMode.Checked = True Then
STAddKeyPressed = True
end if
i then have this code in the datagridview cellbeginedit subroutine.
If Not IsDBNull(DataGridView1.Rows(rowindex).Cells("COUNTED").Value) Then
If STAddKeyPressed = True Then STCellValue =
CInt(DataGridView1.Rows(rowindex).Cells("COUNTED").Value)
ElseIf STAddKeyPressed = True Then
STCellValue = 0
End If
End if
obviously this does nothing with the Value in the cell, nor does it add the two together, i played around with several things, but cant get it work.
i would have thought that in:
Private Sub DataGridView1_CellValueChanged
there would have been the code to handle the addition of the two values. but its not there.
at the moment if I press the + key on the numpad then a number, the cell will only record the number it will ignore the + and wont even leave it in the cell. so you don't end up with "+5" in the cell just "5". not sure how that's occurring to be honest.
like I said I did have this working in the past, but no idea why the code is now missing :/ I remember that it didn't always 100% of the time work the way it was intended but i didn't mind it was rare the issue would arise. I know im probably not going about the right way in handeling the key.down and events so if you can recommend a better way then im all ears!
I'm trying to align text in a textbox to the right side. Either through code TextBox.TextAlign = fmTextAlignRight or setting the property "directly".
Unfortunately, it becomes left-aligned as soon as the text (string) gets too big to be displayed fully in the textbox. Like this example which has all letters from a to z (abcdefghijklmnropqrstuvwxyz) and should be right-aligned, but it's not:
It should look like this:
Any ideas on how to change this behavior / how to force the alignment? Thanks!
Probably this TextBox has the property Enabled set to false. You need to turn it on, and then the TextAlign property will work as you wish. Also, you can use this function:
Public Function SetTextBox(itm1 As MSForms.textbox, ByVal txtAlign1 As MSForms.fmTextAlign)
Dim notEnabled1 As Boolean
If Not itm1.Enabled Then itm1.Enabled = True: notEnabled1 = True
itm1.SetFocus
itm1.TextAlign = txtAlign1
itm1.SelStart = Len(itm1.Text)
If notEnabled1 Then itm1.Enabled = False
End Function
I'm working with VBA, and I'm struggling to get a combobox with two options:
First option: the textbox next to it must appear one "-", like if is supposed to be empty or disabled.
Second option: the same texbox must must be able to receive an input, like numbers.
Like: "Do you have an ID?" if no, don't fill the texbox. If yes, fill it with your number.
Thanks!
I'm assuming C# implementation but this would work essentially for any .net or WINFORMS project.
if(cbo.selectedindex = 0)
tbFoo.text = "-";
else if(cbo.selectedindex == 1)
tbFoo.text = "filltextwithID";
Check if the selectedindex of your combobox is the first or second options in the list and do your first option with the first selectedindex, else if it is the second, fill your textbox with whatever you need to fill it with(textwise).
Use your conditional if statement(naturally, I know) to check your conditions that you want your combobox to do to your textbox.
Otherwise another way to do this is with a selectedindexchanged event and do your switch statement or if statement based on which selectedindex you are talking about. 0 is the first item....all the way up to n items.
I got it! Here's the code:
Private Sub ComboBox_Change()
If ComboBox = "I don't have an ID" Then
IdTextBox.Visible = False 'Hidden
IdLabel.Visible = False
Else
IdTextBox.Visible = True 'Unhidden
IdLabel.Visible = True
End If
End Sub
I am trying to make the reversi game in VB.Net. I have some difficulties translating the game`s logic into vb.net
If a button is black and the button next to it is white,than the button next to the white one will be black wen pressed.
newButton.tag = colum of button + (row of button * amount of columns)
-> I made 64 buttons via a function loop and added a tag
Dim knop As Button = sender
Dim value As String = knop.Tag
If value = "...(?)" Then
knop.BackColor = Color.Black
If ....(?)
End If
End If
I already made a scheme with the label of the buttons, but I find it hard to implement the logic. Can someone help me out with thid one?
EDIT: http://i.stack.imgur.com/3gdrJ.png
If you use Dim ButtonList As List(Of List(Of Button)) and add the buttons to the form in runtime you can add each the button for each row to a list then add that list to ButtonList. Now you can access each button by the indexes in the 2 dimensional list.
Since you're changing the backcolor just use that instead of using the tag.
I am making a game of tic tac toe, and I have 9 buttons lined up in a grid pattern. I want to select a random button for the computer to start the game from.
I have an array set up with all the names of my buttons, and I was thinking of picking a random entry from that array to start working from. This I have done fine, but I cannot change the text of a button. My code:
''# Define the array
random(0) = "tl"
random(1) = "tc"
random(2) = "tr"
random(3) = "cl"
random(4) = "cc"
random(5) = "cr"
random(6) = "bl"
random(7) = "bc"
random(8) = "br"
''# Grab a random array entry
StartPoint = random(RandomClass.Next(0, 8))
as you can see, I can't simply do StartPoint.Text = "O", even thought StartPoint holds the name for the button.
Any help on changing the buttons text from the name in StartPoint would be helpful, thanks.
You should create an array of actual buttons (not their names). Then when you grab a random button into a button object, it'll actually be a button so you can change it's text property.
Since you're just passing around references to the actual buttons, this should work pretty well.
Dim buttons(8) As Button
buttons(0) = tl
buttons(1) = tc
''# ...
Why don't you create an array of Button objects?
That way, all you have to do is cast access them and set the Text property.
Button startButton = random(RandomClass.Next(0,8))
startButton.Text = "o"