| | |
Enable only one whitespace in textbox.
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
1
#2 Oct 8th, 2009
This snippet http://www.daniweb.com/code/snippet217265.html allows you to enter only one decimal point. It should be easy adaptable to what you want.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Make love, no war. Cave ab homine unius libri.
Danny
•
•
Join Date: Jul 2009
Posts: 123
Reputation:
Solved Threads: 10
0
#3 Oct 8th, 2009
•
•
•
•
This snippet http://www.daniweb.com/code/snippet217265.html allows you to enter only one decimal point. It should be easy adaptable to what you want.
I am talking about whitespace (enabling spacebar to be pressed once ) not the decimal.
0
#4 Oct 8th, 2009
This will block a double space, ie: "a<space><space>b" but allow "a<space>b<space>c":
To allow only a single space:
C# Syntax (Toggle Plain Text)
private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { TextBox tb = (TextBox)sender; if ((e.KeyChar == ' ') && (tb.Text.Length > 0)) { if (tb.Text[tb.Text.Length - 1] == ' ') e.Handled = true; } }
To allow only a single space:
C# Syntax (Toggle Plain Text)
private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { TextBox tb = (TextBox)sender; if ((e.KeyChar == ' ') && (tb.Text.Contains(' '))) e.Handled = true; }
1
#6 Oct 8th, 2009
•
•
•
•
Originally Posted by vinnijain
I think you haven't read the post properly.
I am talking about whitespace (enabling spacebar to be pressed once ) not the decimal.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Make love, no war. Cave ab homine unius libri.
Danny
1
#7 Oct 8th, 2009
•
•
•
•
I think there is a misunderstanding here between to non native English speaking persons. By whitespace, I understand any character that you don't see on the screen. A tab character is whitespace for instance. You seem to think(correct me if I'm wrong) that hitting the spacebar produces whitespace. Wrong! It produces a space character which is considered whitespace. So I thought my suggestion (by adapting it) would provide you with an answer. But perhaps you did not read my answer to it's full extent
So I adapted your snippet to the code I posted •
•
Join Date: Jul 2009
Posts: 123
Reputation:
Solved Threads: 10
0
#8 Oct 12th, 2009
I am facing one problem in this code:
Problem is that when I am going backspace or when I am moving backwards using arrowkeys , in that case spacebar is disabled. Not even a single space is enabled.
Kindly provide some solution..........
•
•
•
•
This will block a double space, ie: "a<space><space>b" but allow "a<space>b<space>c":
C# Syntax (Toggle Plain Text)
C# Syntax (Toggle Plain Text) private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { TextBox tb = (TextBox)sender; if ((e.KeyChar == ' ') && (tb.Text.Length > 0)) { if (tb.Text[tb.Text.Length - 1] == ' ') e.Handled = true; } }
Problem is that when I am going backspace or when I am moving backwards using arrowkeys , in that case spacebar is disabled. Not even a single space is enabled.
Kindly provide some solution..........
Last edited by vinnijain; Oct 12th, 2009 at 1:54 am.
0
#9 Oct 12th, 2009
Suggest you revisit the code snippet I gave you.
Change all the code that handles a decimal point into code that handles a space. If you like to input letters instead of numbers more changes are needed, but all this cannot be that hard to accomplish, now is it?
Change all the code that handles a decimal point into code that handles a space. If you like to input letters instead of numbers more changes are needed, but all this cannot be that hard to accomplish, now is it?
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Make love, no war. Cave ab homine unius libri.
Danny
•
•
Join Date: Jun 2009
Posts: 210
Reputation:
Solved Threads: 15
1
#10 Oct 12th, 2009
Hello vinnijain.........
try this on textBox1_TextChanged event........
Hope it help you...........
try this on textBox1_TextChanged event........
C# Syntax (Toggle Plain Text)
TextBox t = (TextBox)sender; int index = t.Text.IndexOf(" "); while (index != -1) { t.Text = t.Text.Replace(" ", " "); index = t.Text.IndexOf(" "); } t.SelectionStart = t.Text.Length;
Hope it help you...........
![]() |
Similar Threads
- option button and textbox (Visual Basic 4 / 5 / 6)
- enable/disable groupbox (VB.NET)
- Text Enable/Disable (PHP)
- textbox suggest (ASP.NET)
- disable textbox when dropdown selected (VB.NET)
- How to Enable and disable controls in .aspx page using javascript? (JavaScript / DHTML / AJAX)
Other Threads in the C# Forum
- Previous Thread: Read a part of a tab delimited data in a Text File :C#
- Next Thread: Client-Server Project
| Thread Tools | Search this Thread |







