473,382 Members | 1,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Backspace at TextBox.AppendText

I have textbox. I do something in each Keypress (kindof validation) in order
not to rewrite all text inside I'm using AppendText method to write in. BUT
I'm unable to add backspace (\b); e.g I have to change each ZZ to Z so I
want to do myTextBox.AppendText("\bZ"); or (char)8+"Z" - Both writes black
square and Z. I know bout the issue of Win32, but is any way to overrde it?

TNX

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
Nov 16 '05 #1
7 10355
Tamir,

A backspace character is still a character. Rather, when you detect the
second "Z", ignore it, don't append it to the textbox. This way, you don't
place the extra character, and you get the desired effect (one Z).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:eQ**************@tk2msftngp13.phx.gbl...
I have textbox. I do something in each Keypress (kindof validation) in
order not to rewrite all text inside I'm using AppendText method to write
in. BUT I'm unable to add backspace (\b); e.g I have to change each ZZ to Z
so I want to do myTextBox.AppendText("\bZ"); or (char)8+"Z" - Both writes
black square and Z. I know bout the issue of Win32, but is any way to
overrde it?

TNX

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

Nov 16 '05 #2
I'd happy to be simple like that ;) ZZ it only example. It can be "Sd" as
well ;)
I found workaronds:
1) SendKey.Send("{BS}"); //BAD GUY
2)
myTextbox.SelectionStart = myTextbox.TextLength-1;

myTextbox.SelectionLength = 1;

myTextbox.SelectedText="";

BOTH not quite like them.

Any other ideas?
--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@tk2msftngp13.phx.gbl...
Tamir,

A backspace character is still a character. Rather, when you detect
the second "Z", ignore it, don't append it to the textbox. This way, you
don't place the extra character, and you get the desired effect (one Z).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tamir Khason" <ta**********@tcon-NOSPAM.co.il> wrote in message
news:eQ**************@tk2msftngp13.phx.gbl...
I have textbox. I do something in each Keypress (kindof validation) in
order not to rewrite all text inside I'm using AppendText method to write
in. BUT I'm unable to add backspace (\b); e.g I have to change each ZZ to
Z so I want to do myTextBox.AppendText("\bZ"); or (char)8+"Z" - Both
writes black square and Z. I know bout the issue of Win32, but is any way
to overrde it?

TNX

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "


Nov 16 '05 #3
Hi Tamir,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to replace all the ZZ with Z
in a TextBox when a key is pressed. If there is any misunderstanding,
please feel free to let me know.

Besides ignoring the second Z character, I think we can also use the
String.Replace method. When each key is pressed, we can handle the KeyUp
event to check if there is ZZ in the string. If yes, replace them with Z.
Here is a code snippet.

private void textBox1_KeyUp(object sender,
System.Windows.Forms.KeyEventArgs e)
{
string s = this.textBox1.Text.Replace("zz","z");
this.textBox1.Text = s;
}

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #4
Thank you for response.
Two problems:
1) As I mentioned earlier - it not have to be double symbol - it can be
anything
2) It possible more then one ZZ (even legal) in the text

--
Tamir Khason
You want dot.NET? Just ask:
"Please, www.dotnet.us "

"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:4c**************@cpmsftngxa10.phx.gbl...
Hi Tamir,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to replace all the ZZ with Z
in a TextBox when a key is pressed. If there is any misunderstanding,
please feel free to let me know.

Besides ignoring the second Z character, I think we can also use the
String.Replace method. When each key is pressed, we can handle the KeyUp
event to check if there is ZZ in the string. If yes, replace them with Z.
Here is a code snippet.

private void textBox1_KeyUp(object sender,
System.Windows.Forms.KeyEventArgs e)
{
string s = this.textBox1.Text.Replace("zz","z");
this.textBox1.Text = s;
}

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #5
Hi Tamir,

1) In this case, you have to write several Replace in the event handler.
2) Replace method will replace all the ZZ in the text.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #6
Hi Tamir,

I too am having a similar problem. It seems the code that follows does the
job:

myTextbox.SelectionStart = myTextbox.TextLength-1;

myTextbox.SelectionLength = 1;

myTextbox.SelectedText="";

But when I keep hitting the backspace button, to the begining, where there
are no more characters left, an error gets thrown. Any further solutions you
could throw my way?

MikeY

"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:4c**************@cpmsftngxa10.phx.gbl...
Hi Tamir,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to replace all the ZZ with Z
in a TextBox when a key is pressed. If there is any misunderstanding,
please feel free to let me know.

Besides ignoring the second Z character, I think we can also use the
String.Replace method. When each key is pressed, we can handle the KeyUp
event to check if there is ZZ in the string. If yes, replace them with Z.
Here is a code snippet.

private void textBox1_KeyUp(object sender,
System.Windows.Forms.KeyEventArgs e)
{
string s = this.textBox1.Text.Replace("zz","z");
this.textBox1.Text = s;
}

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #7
* Problem of Z *
If only Z has to be replaced, best could be to do a Index search for the
text in textbox.
Condition 1- Text is typed in textbox
....this could be handled in Key event (or text change) and look for Z in
textbox. If Z is already there clear the last type.

Condition 2 - Copy and paste in textbox
Catch text change event and index search for Z, if it is there,
String.Replace it with single Z.

* Problem of Backspace *
Give attn to the condition when there is no text (Length = 0). You are
subtracting 1 in that condition. Check if (TextBox.TextLength > 0) then you
do math on it.

Thanks.

"MikeY" <mi*******@yahoo.c> wrote in message
news:gr********************@news20.bellglobal.com. ..
Hi Tamir,

I too am having a similar problem. It seems the code that follows does the
job:

myTextbox.SelectionStart = myTextbox.TextLength-1;

myTextbox.SelectionLength = 1;

myTextbox.SelectedText="";

But when I keep hitting the backspace button, to the begining, where there
are no more characters left, an error gets thrown. Any further solutions
you
could throw my way?

MikeY

"Kevin Yu [MSFT]" <v-****@online.microsoft.com> wrote in message
news:4c**************@cpmsftngxa10.phx.gbl...
Hi Tamir,

First of all, I would like to confirm my understanding of your issue.
From
your description, I understand that you need to replace all the ZZ with Z
in a TextBox when a key is pressed. If there is any misunderstanding,
please feel free to let me know.

Besides ignoring the second Z character, I think we can also use the
String.Replace method. When each key is pressed, we can handle the KeyUp
event to check if there is ZZ in the string. If yes, replace them with Z.
Here is a code snippet.

private void textBox1_KeyUp(object sender,
System.Windows.Forms.KeyEventArgs e)
{
string s = this.textBox1.Text.Replace("zz","z");
this.textBox1.Text = s;
}

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."


Nov 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: haxmya | last post by:
Ok, made an explorer toolbar (band Object) with a textbox on it. Everything works great....except that the backspace button doesn't actually backspace when you're in the textbox. Shift-backspace...
14
by: Adam Clauss | last post by:
I've an application which is using a multiline textbox to log the status of a fairly long procedure. "Updates" are made to the status by calling textbox.AppendText. As my task is fairly lengthy,...
5
by: Wilfried Mestdagh | last post by:
Hello, textBox += someData + "\r\n"; does not scroll the visible text to the end. How do I perform that ? Also this way seems to me a lot of reallocating memory. Is there better way to add...
4
by: Grant Schenck | last post by:
I want to append text to the end of a text box. If the cursor is currently at the end I just want to append it and have the normal scrolling take place if needed. However, if the selection...
7
by: Andrew | last post by:
VB .NET 2003, WinXP Pro: Adding text to a text box with the TextBox.AppendText method limits the amount of text in the textbox to 32K. I have a short program that uses the GetFiles function of...
13
by: WALDO | last post by:
I have a .Net TextBox (TextBoxBase, really) in which I am appending about 20 lines of text per second. I use the AppendText() method to accomplish this. This is a great substitute for taking the...
0
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, I have a scrolling RichTextBox to which I add characters one at a time using the AppendText method as they are received by my application. Some of these characters may be backspace...
7
by: Anil Gupte | last post by:
I have read a lot about getting lines from a multiline textbox in VB.Net. However, I cannot for the life of me figure out how to write to a multiline textbox. Basically, I have created an array of...
3
by: zacks | last post by:
I have a multiline textbox control where I would like to load up with something like the following: This is Line 1 <- this line is NOT bold This is Line 2 <- this line is...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.