Uppercase Method for Metroframework

2

IneedhelpwithTextBox,whereIworkonc#using Metroframework .

I need to turn all typed text into TextBox into uppercase. How can I do it?

    
asked by anonymous 06.08.2015 / 21:14

3 answers

2

If the Framework were for Xaml/WPF :

In%% of where the button is, there is the Xaml property that accepts the following values: CharacterCasing , Upper and Lower .

Setting this property to button directly on Normal

<TextBox  CharacterCasing="Upper" /> 

At the time the user type, the letters have already been capitalized. And when you retrieve the value of xaml in TextBox it will already be capitalized.

Another way to set it would be in codebehind :

public MainWindow()
{
    InitializeComponent();
    NomeTextBox.CharacterCasing = CharacterCasing.Upper;
}

codebehind does not really support this property. Here are some suggestions:

1 - You can use MetroFrameWork , to capitalize the letters before throwing the data to ToUpper() .

2 - Start using BD , is more advanced than WPF , and gives you more freedom to create. Site recommended to get started.

3 - In visual studio 2015, you can create WinForms with style meter already by default, without using apps/programas . - News

06.08.2015 / 21:31
1

To make life easier and not having to create the method in all Forms , you can create a new control that inherits from that TextBox you are using and in it you include the method indicated in our friend's < in> jbueno . Example:

class TextBoxEx : TextBox 
{
    protected override void OnKeyPress(KeyPressEventArgs e)
    {
        base.OnKeyPress(e);

        if (char.IsLetter(e.KeyChar))
            e.KeyChar = Convert.ToChar(e.KeyChar.ToString().ToUpper());
    }
}
    
07.05.2017 / 19:55
1

An alternative is to change the KeyPress event of your TextBox to turn all the letters in uppercase.

private void textBox_KeyPress(object sender, KeyPressEventArgs e)
{
    if (Char.IsLetter(e.KeyChar))
        e.KeyChar = Convert.ToChar(e.KeyChar.ToString().ToUpper());
} 

Perhaps the most viable in your case would be to create a new component that inherits MetroTextBox , so you can overwrite ( override ) this function and even create a property with the same purpose of CharacterCasing to which you can choose from in property window if you want it to be case sensitive .     

07.08.2015 / 14:20