How to convert Text into upper case in textbox? [closed] - c#

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have created a text box which can accept only one character. When the user types anything into the box, I want it converted into upper case.

Set TextBox.CharacterCasing to CharacterCasing.Upper.
textBox1.CharacterCasing = CharacterCasing.Upper;

Right-click your textbox, and then click Properties.
In the Properties window, locate the CharacterCasing property, and then click to select Upper from the list.
(Source: http://support.microsoft.com/kb/818363)

Use KeyDown event and check the input key. Then use String.ToUpper(). For example:
private void YourTextBox_KeyDown(object sender, KeyEventArgs e)
{
YourTextBox.Text = YourTextBox.Text.ToUpper();
}

string lower = "converted from lowercase";
Console.WriteLine(lower.ToUpper());
Take a look at this: How to convert strings to lower, upper, or title (proper) case by using Visual C#

You could either change the textbox's casing to upper case like this:
TextBox.CharacterCasing = CharacterCasing.Upper;
Or you could create an event which is executed when the textbox's text has changed.
TextBox.Text = TextBox.Text.ToString().ToUpper();
And so whenever someone types something inside of the textbox it will be changed to upper case, but I do not think that this is a good idea. I recommend using my first advice.

Related

how can i change the password character of the textbox during runtime [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have my log-in form and under that there's also the "Change Password" my teacher recommended me that if I write my old password in the old password textbox i'll see the characters, but if I leave that textbox and go to the new password textbox the characters should turn into "*".
How can I make that possible ?
Firstly, by convention there's no need to do this. The only reason that happens on mobile devices is that it's very easy to type wrong characters on tiny keyboards with large fingers. Getting a chance to quickly preview the last typed character is highly desirable. On a WinForms app I've never come across that usability. But, if you really want to do it, you'll need to create a custom control. The problem is that the PasswordChar property will mask all characters, not just all but the last one.
You could perhaps inherit from TextBox and add a property called TimedPasswordChar. Then subscribe to the ValueChanged event. In this handler, if TimedPasswordChar is not null or empty then start a Timer object with a 1000ms interval. In the Tick event handler, stop the timer on the first line the convert the last character to the TimedPasswordChar. Bear in mind though that you will need to add each character you switch to the TimedPasswordChar to a private member variable holding the actual password. I'd suggest using System.Security.SecureString given it's a password.
Just before you convert the last char to the TimedPasswordChar then add the entered value with .AppendChar(...).
One point that complicates it though is if the user edits the string. You need to monitor which string has been edited and then use .RemoveAt(...) on the secure string to keep it in sync.

Textbox with specific numbers [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I want to create a TextBox in windows form application in visual studio that contains only specific numbers. for example i want one textbox to be able to contain only numbers between 0 and 1. If its any other value I want a message to appear that says wrong number. The app is in written in C#.
I have seen this example
C# Numeric Only TextBox Control
but it is for numeric and i want specific numeric.
Edit:My mistake i wasn't clear enough. i tried the NumericUpDown but it doesn't work for all examples. In the second box i want to have values from 20 to 340 but only the .5 floating points between (20,20.5,21 etc) and if i use NumericUpDown, if the user inserts 22.6 the cell accepts it and i don't want that. That's why i ask if it's possible to control the value inserted with a Textbox or a MaskedTextBox and if it's eligible then for the user to be able to enter it the box. Hope i am clear enough now.
You should use a NumericUpDown.
You can use it like this;
NumericUpDown control = new NumericUpDown();
control.Minimum = 0;
control.Maximum = 1;
control.DecimalPlaces = 2; // or something you want.
control.Increment = .01; // step is .01
create user control inheriting TextBox and add an event for KeyPress as follows
public class MyTextBox:TextBox
{
List<int> numberstobeallowed = Enumerable.Range(20, 340 - 20).ToList();
public MyTextBox()
{
this.Leave += new EventHandler(MyTextBox_Leave);
}
void MyTextBox_Leave(object sender, EventArgs e)
{
if (numberstobeallowed.Contains(Convert.ToInt32(this.Text)))
this.Text = string.Empty;
}
}
hope this helps

How to allow only valid values in a combobox? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
in C# with DotNet 4 i have a form with a combobox which is filled with values when starting the program.
Now user can dropdown and select one of the values.
But: It is also possible to write something new into the combobox-field.
Question: What can i do that it is NOT possible to write something which is not part of the list?
Thanks
To make the text portion of a ComboBox non-editable, set the DropDownStyle property to "DropDownList".
It can be done by simply assigning a property to combobox .DropDownStyle = ComboBoxStyle.DropDownList. but, this property do not allow to edit text. means you have to select item either by mouse or by up/down arrow key. You cannot filter result by selecting this property. if you wish to filter result but don't allow to accept invalid value then you can do this by writing some code in cmb_Validating event
private void cmb_Validating(object sender, CancelEventArgs e)
{
if (cmb.SelectedValue == null && cmb.Text != string.Empty)
e.Cancel=true;
}

Writing Multiple Fields to one textbox [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Just need a little help with a program i have been working on. basically i work in a call centre and i am going to use this to record my notes during calls, i have everything worked out besides on feature. So i when filling out the fields i need it to show up in a specific textbox, and i need to structure this data to specific lines. I also want to try do this without having to store the data to txt file or a database, i want to try do it all within strings if possible. any help would be greatly appreciated guys.
thanks in advance
So in short.. you just created a button and some fields and have no idea how to proceed.. try selecting one programming language as #TheKingDave suggested. For example, if you go for C#..
try to read up on the below links to get yourself started:
system.windows.controls.textbox
system.windows.controls.combobox
but just, if I understand your question correctly, because let's face it, it's far from clear, you want to grab information you added into several textboxes and comboboxes etc and format them into one multiline textbox? If so...
Create a on_click event for your button in which you want to add stuff like..
string Example1 = this.mytextbox1.text;
string Example2 = this.mytextbox2.text;
string Example3 = this.mycombobox.SelectedItem;
...
afterwards you want to add all these strings together, for example
string MyResult = "Example1: " + Example1 + "\r\n" + "Example2" + ... ;
and then show this in your resulting textbox
this.myresulttextbox.text = MyResult;
Hope this answers your question somewhat but I strongly advise reading up on this before going any further..
What is actually your programming language?
Not sure about your question but if your goal is to concatenate everything into a single string, just read the text value from every *boxes you have and add them into the text value of your destination using a special joker character that is unused in your edited fields like 'ยค' for example to separate every string. It's easy then to process it later. The brutal way is to hard code every copy. A slightly more refined one would be to have a list of interesting components and for the copy to loop on them and according their type, chose the right access method to get the information.

TextBox DateTime format [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Im wondering how to make my textbox format "DD.MM.YYYY" that after load form the textbox will be filled with "__ .__ .__" and those spaces and dots cannot be deleted. Is there any way to do that?
Thanks
Why don't you use a MaskedTextbox? Use the following as mask, you can set the mask either at design time or at form load.
private void Form1_Load(object sender, EventArgs e)
{
maskedTextBox1.Mask = "00.00.0000";
}
You would probably be looking at something like Ajax Masked Edit
Another way to do it would be to use a jquery plugin
You could use a MaskedTextbox that will do exactly what you describe. A DateTimePicker might be better though...

Categories