|
-
Jun 18th, 2004, 01:44 AM
#1
Thread Starter
Registered User
textbox value..
hi to everyone..im very new in this thing
i have a form w/ corresponding textbox.
in the textbox the user input a value and in pressing "enter" the value in textbox will be store in a string..
what i want is when the user press "esc" while editing in textbox it will fill the previous value..
how to do it?
thanks in advance..
-
Jun 18th, 2004, 02:06 AM
#2
Fanatic Member
-
Jun 18th, 2004, 02:22 AM
#3
Thread Starter
Registered User
Originally posted by brown monkey
use a stack
ok i try it..
tanx for the suggs...
-
Jun 18th, 2004, 05:49 AM
#4
PowerPoster
Hi,
I don't think it is quite that simple. Allowing a user access to the ESC key always give rise to problems. It is safer to use Confirm and Cancel buttons, making all other controls.Enabled=False. In the MouseEnter (or possibly TextChanged) event of the Textbox use something like
VB Code:
If bFirst=false then
othercontrols.enabled=False
bfirst=True
strText=Textbox.Text
end if
Then in the click event of the confirm button
VB Code:
bFirst=False
strText=""
othercontrols.enabled=True
btnConfirm.Enabled=False
btnCancel.Enabled=False
In the click event of the cancel button
VB Code:
bfirst=False
Textbox.Text=strText
strText=""
btnConfirm.Enabled=False
btnCancel.Enabled=False
bFirst is a form scope boolean and strText is a form scope string
Last edited by taxes; Jun 18th, 2004 at 06:19 AM.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jun 18th, 2004, 09:03 PM
#5
Thread Starter
Registered User
tanx for the great idea guys...
more power
-
Jun 21st, 2004, 06:30 AM
#6
Junior Member
Try this its the easiest
Well I will tell you the easiest way.
On got focus store the value in a variable called strOld value
Capture the key down event and declare a string strNewvalue store the new value in it.
‘To store values in the strnew variable. Use this code in ‘TextBox1_KeyPress Event
strnew = strnew + e.KeyChar
Now do what ever you want to do you have both the values with you.
On ESc use Old value and on Enter Use New Value.
I bet nothing could be easier than this… J
Give me a place to stand and I will move the Earth 
-
Jun 21st, 2004, 07:12 AM
#7
PowerPoster
Re: Try this its the easiest
Hi,
Any idea why I get the message
"KeyChar is not a member of System.EventArgs" ?
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jun 21st, 2004, 08:03 AM
#8
Hyperactive Member
Hi Taxes, I don't know in which part of your code it happens, but it seems to be a request of keychar argument in a keydown or keyup event. In these events you can obtain Keycode, for example but not keychar that is available in keypress event.
Live long and prosper (Mr. Spock)
-
Jun 21st, 2004, 09:00 AM
#9
PowerPoster
Originally posted by alextyx
Hi Taxes, I don't know in which part of your code it happens, but it seems to be a request of keychar argument in a keydown or keyup event. In these events you can obtain Keycode, for example but not keychar that is available in keypress event.
Sorry. I did not make myself clear. I was referring to the post by veins above when he said
"To store values in the strnew variable. Use this code in ‘TextBox1_KeyPress Event
strnew = strnew + e.KeyChar"
I did not like to say he could not do that as it might have been something I was missing.
So let's get back to veins' post.
Firstly, you can't do it like that for two reasons;
1. As above, KeyChar is not available.
2. Even if you use KeyPress you cannot use it as if the operator makes an error and uses a backspacedelete, you will have an unintelligible character.
What you can do is use
strNew = TextBox1.Text
but only in the KeyUp event. If you use it in the KeyDown or KeyPress event strNew will be 1 character in arrears.
Thanks alextyx.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jun 21st, 2004, 10:39 AM
#10
Hyperactive Member
Nothing Taxes
Dear Loner, if you only want to store the value in Textbox1 when press Enter and to recover it when press Esc, you can try this:
Code:
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
Static Copiatesto As String
If e.KeyCode = Keys.Enter Then
Copiatesto = TextBox1.Text
End If
If e.KeyCode = Keys.Escape Then
Me.TextBox1.Text = Copiatesto
End If
End Sub
If you need something different....try to explain it to me once again
Live long and prosper (Mr. Spock)
-
Jun 21st, 2004, 08:16 PM
#11
Thread Starter
Registered User
thanks alex...
but it only store the last value inputed in the textbox..
what i want is all the value inputed will retrieve every time the user press "esc".
thanks in advance and more power..
-
Jun 21st, 2004, 08:18 PM
#12
Fanatic Member
stack is what you are finding... everytime you hit enter, push it and everytime you hit escape, pop it.
-
Jun 22nd, 2004, 12:26 AM
#13
Thread Starter
Registered User
Originally posted by brown monkey
stack is what you are finding... everytime you hit enter, push it and everytime you hit escape, pop it.
thank you BM and the rest of the guys..
i already got it by using stack.
VB Code:
Dim x As New Stack()
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.Escape Then
TextBox1.Text = x.Pop
End If
If e.KeyCode = Keys.Enter Then
x.Push(TextBox1.Text)
TextBox1.Text = ""
End If
End Sub
thanks and more power
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|