|
Not a good idea. What happens if you want to put a space in a word as you type?
|
|
|
|
|
Please post specific coding questions, like this one, in the Q&A forum, thanks.
Since (to the best of my knowledge) you cannot now delete this question here, and repost it in Q&A, I'll respond.
First, if you want to create a re-usable TextBox because: you want to use many TextBoxes that behave like this; my esteemed colleague Dave K. is absolutely right when he advises you to make a TextBox Control Class that inherits from Windows Forms TextBox.
If you don't know how to effectively sub-class WinForms Controls, please research Codeproject, the VS 201#x documentation, and MSDN, for information on creating your own Components, or UserControls. If you have problems with understanding, or implementing, them: ask them here on Q&A.
Here's some sample code that just modifies the behavior of one specific TextBox, 'textBox1:
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (textBox1.SelectionStart == 0)
{
if
(Char.IsWhiteSpace(e.KeyChar))
{
e.Handled = true;
}
}
}
Note: that you don't need to explicitly set e.Handled to 'false because 'false is the default value.
If you only want to suppress the space-character, and you want to allow tabs, or cr/lf's to be typed at position #0 in the TextBpx: then change the code above.
And, something you might think about: what happens if the user pastes text in, at position #0 in the TextBox, and the pasted-in content begins with spaces, tabs, etc. ? Try that, using the code above, and observe
Resources you should review: [^],[^],[^].
bill
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
|
|
|
|
|
thanks
|
|
|
|
|
Bill, there is no reason that this question is not suitable for this forum.
|
|
|
|
|
Pete O'Hanlon wrote: Bill, there is no reason that this question is not suitable for this forum. Hi Pete,
I must, respectfully, disagree: this is a language-specific "general programming" forum; the design of CodeProject (originally, anyway), for a good reason, had both a C# Q&A forum, as well as this "general programming" forum.
I am sure the intent of having two types of Forums, with two very different facilities ... one having formatting-free back-and-forth commenting, and a whole different voting structure with a range of scoring levels, and a way for the user to "accept" a given answer, and the other operating like all the other non Q&A forums ... was to have a place where, on the one hand, there could be substantive discussions of broader aspects of the use of the C# language, or, more advanced problems in programming that involved advanced concepts in C#. (this forum), and the other (Q&A): a place for specific programming questions of the "how do I ?," "how can I ?," "I'm stuck trying to" forms.
In practice, however, this forum has become a place where there is a creep-in of the type of questions that are best-suited for Q&A.
The analogy I'd use is: once a master-gardener designed two adjacent gardens, for very different purposes. One garden was intended for rare plants that needed special care, and where gardeners could meet to have educational discussions about the best gardening practices in taking care of both ordinary, and the "rare" plants.
The other garden was designed for common plants, plants for which gardening was a simple matter, and a place where those beginning to garden came to learn the basics of gardening, by hands-on practice, and having the opportunity to work alongside more experienced gardeners.
Using this analogy, I would say that, now: the strong hedge-row between the two gardens has collapsed, and many of the rare plants have stopped their rare blossoming, and both gardens are over-run with weeds and gardeners-gone-starkers who claim to be virtual incarnations of the original gardener, themselves, and run virtual 24-hour radio-stations broadcasting their grandiosities
Isn't the "downfall" of Q&A reflected clearly in your own admission on CP (sone time ago), that you withdrew from participating in Q&A, yourself, because you were uncomfortable with what was happening there ?
It's fine with me if CM changes the whole structure around. It's quite possible the time has come for that (?).
But, I feel it's entirely legitimate, and not disrespectful, to suggest to posters on this forum that their type of post is best-served, for both them, and CP, as a whole, on Q&A.
yours, Bill
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
|
|
|
|
|
You do know that the QA forum is relatively new don't you? For years, this forum did the job perfectly well. The intent of this forum was always intended to be the back and forth, as was best suited to by a forum format, where the thread can build out the answer.
|
|
|
|
|
Pete O'Hanlon wrote: the QA forum is relatively new Hi Pete,
I joined CP exactly one year before you did, but I have such great respect for you that I'd pick your view of CP's Forums' history and QA's inception over mine ! You have been a "prime mover" on CP, in my eyes, while I regard my walk-on role as that of a "spear-carrier in the third act" who often speaks-in-tongues when he's supposed to be: silent
If you tell me that you think I am doing a "bad thing" by advising people here to post on Q&A, and you don't share my view about what's happened with this forum, and Q&A, I will certainly re-evaluate my views, and very likely change my behavior. I wonder if, in your eyes, my advising people to post on Q&A, as I think appropriate, is kind of a presumptuous act on my part, a kind of lese majeste ?
But, may I ask: isn't the reason you gave (a while back) for your own withdrawal from Q&A provide evidence that you think the "system," as is, may need to be changed.
Perhaps changed, not because it is "broken," but, changed, because times have changed, the membership of CP has grown exponentially, and different modes of member behavior have emerged.
I remember this forum as a place, long ago, where substantial discussions of bigger-picture aspects of C# were discussed in depth.
Perhaps I am (as Rene Dubos, in his book, "The Mirage of Health" describes, a la Rousseau) imagining this forum had "golden age" in which humanity was more "noble," and lived "at one" with nature ?
In any case, please be assured that your opinions are valued, and will be heeded, after careful consideration.
In fact, as of now, I will no longer advise anyone on CP to post on Q&A.
yours, Bill
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
|
|
|
|
|
BillWoodruff wrote: But, may I ask: isn't the reason you gave (a while back) for your own withdrawal from Q&A provide evidence that you think the "system," as is, may need to be changed.
My withdrawal from Q and A had more to do with the personalities and ego crashing that do the rounds there. While the forums can occassionally bring out the jerk in people, this seems to be a much more common feature in QA. I do not like the fact that people have taken it as a playground to put others down, and the fact that someone does not ask a perfect question the first time round should not lead to them being told they have asked the wrong question, or that they are stupid, or any one of a hundred other things guaranteed to put people off CP.
The beauty of the forums, is that if someone doesn't ask a perfect question, or more information is needed, the thread view easily allows for that expansion of the idea so that people can see how questions evolve to their answers, and this can be an invaluable aid. Saying that, the forums aren't perfect, and there is a place for QA - and I admire people like yourself and OG for continuing to fight the good fight over it. (BTW - as to the creation of QA, I remember the bitter arguments Luc had with Chris when QA came into existence - QA being part of the reason, I believe, that Luc left our little fold).
|
|
|
|
|
BillWoodruff wrote: my esteemed colleague Dave K
"Esteemed colleague"?? Crap, now I have to act respectable.
Great job on the answer!
|
|
|
|
|
Uhh, homie, nah, man: respectable ? ... I ain't down 'wid that. I got to throw my old bones to some dawg, because they creakin' mighty on me; ain't hardly no use in 'em nowadays. You be a grand organ, man, playing formal to kinky pushin' and pullin' all yo' stops: thass yo' thang.
bill
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
|
|
|
|
|
protected void textBox1_TextChanged(object sender, EventArgs e)
{
if(textBox1.Text.Length > 0)
{
textBox1.Text = textbox1.Text.TrimStart(' ', '');
}
}
|
|
|
|
|
The problem with your answer is that it's not reusable and doesn't account for other whitespace characters that may not be acceptable, like Tab.
If you wanted to do this for multiple textboxes, you would have to add this code for each and every textbox. It's FAR better just to make your own TextBox that has this functionality.
|
|
|
|
|
You could place this code in the TextChanged event or OnKeyDown event (or you could use it whenever you want)
string myString = textBox1.Text.TrimStart()
or even straight to the point
textBox1.Text = textBox1.Text.TrimStart()
|
|
|
|
|
smh1392 wrote: I want to not allow at Space the First of TextBox Talk about a time-waster.
Not worth the money nor the effort. Especially not if it becomes a dirty hack that causes more pain to the user than it's bringing back in benefits.
If you "need" the functionality, then "correct" the data when saving, not when the user is editing.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hello!
I realized that MC did not create any Sound-Management Class, so
I don't know how to check which sound-output device is currently activated [standard-device, Not standardcommunication-device].
Are there extern libraries / classes that support my asked feature?
|
|
|
|
|
|
urgent need of online hotel managment project in .net if anybody have online hotel managment projectin .net then send me on following email id : chundavatteena@gmail.com pls guys send me project urgent chiye
|
|
|
|
|
- We're volunteers
- It's not urgent to me
- Nobody is going to "give away" complete projects
- Posting your mail address on a board is an invitation for spam bots
- Don't use text-speak
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
urgent - need 100 million dollars.
Send me that and I will send you the hotel management project.
|
|
|
|
|
I'll do it for $995000 USD! Although I won't be quite as urgent.
|
|
|
|
|
I'll do it for $995450, but I also offer a free iFad
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hah, I'll do it for peanuts, farm it out to elance/rentacode/whoever. The OP gets what they deserve and I get something to nibble on with my beer.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Try something and then post your questions here.
|
|
|
|
|
Quick now: send me the database of the hotel's bookings of the last five-years: type of room, floor, room number, and, per booking: nationality of guests, cost per night, how many nights, number and type of items consumed from in-room refrigerator, room-service bills, phone bills, etc.
And, send me the detailed architectural design plans for the hotel. And, the database on elevator usage, maintenance, and repair costs, per elevator for the last five years. I will also need video of activity in the parking lot(s) of the hotel for at least two years.
And, the database for the last five years of hotel employees with title, length of service, type of occupation, compensation per month, bonuses, days off, sick-leave days, taxes withheld, etc.
And the database for the operational costs of the hotel exclusive of employee salaries: supplies, advertising, maintenance and refurbishing, insurance coverage ... for at least five years.
I estimate I can have your project for you in three hours.
bill
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
|
|
|
|
|
What no restaurant and catering!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|