Uppercase Method for Metroframework

Asked

Viewed 668 times

2

inserir a descrição da imagem aqui

I need help in TextBox, where I work in c# using Metroframework.

I need to turn all the typed text into TextBox in capital letters. How can I do?

  • Have you tried the method .ToUpper() ?

  • So for all textboxes I use this method ?!

  • One more thing...where do I include this method in my form ? Sorry, I’m new in c#

  • I want all the data included in the registration form , for example " customer registration" already appear higher , when they are typed in the textbox

  • that is, appear in the textbox already uppercase

  • Yes, I’m using Winforms

  • @Rennanhanna, I updated my answer.

Show 2 more comments

3 answers

2

To make life easier and not need to create the method at all Forms, you can create a new control that inherits from this TextBox that you are using and in it you include the method indicated in the response of our friend 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());
    }
}

2

If the Framework were to Xaml/WPF:

In the Xaml where the button is, there is the property CharacterCasing which accepts the following values: Upper, Lower and Normal.

Setting this property to the button directly on xaml

<TextBox  CharacterCasing="Upper" /> 

At the moment the user is typing, the letters already appeared in uppercase.
And when you go to recover the value of TextBox in the codebehind he had already seen in capital letters.

Another way to set it would be in the codebehind:

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

The MetroFrameWorkdoes not really support this property. So go some suggestions:

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

2 - Start using WPF, is more advanced than WinForms, and gives you more freedom to create. Website recommended to start.

3 - In visual studio 2015, you can create apps/programas with metro style already by default, dispensing with use of frameworks. - News story talking about it.

4 - Framework for WPF Mahapps.

5 - I don’t know your level of knowledge, but if you’re starting out, learn how it works and then use frameworks, and start with WPF, because microsoft itself recommends the use, because WinForms is lagging behind.

  • That’s right! There is no Charactercasing in the properties, because I am developing in Metaframework.

  • What is the difference between winforms and wfp Meuchapeu?

  • @Rennanhanna, from a read on this Article of the site Lambda3. He explains well straight, is 2010, but tah valid.

  • I will check, thank you very much Meuchapeu

1

An alternative is to change the event KeyPress of your TextBox to capitalize all letters.

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 thing in your case would be to create a new component that inherits the MetroTextBox, then you can overwrite (override) this function and even create a property with the same intention of CharacterCasing so that it is possible to choose Property window if you want him to be case sensitive or not.

  • What a complication, but, however long it is , I will have to do one by one in all textboxes of all Forms, because I do not know how to do what you suggested ! rs

  • If you do a search for UserControl or custom components you will find much material.

  • I’ll look, thanks Jeferson

Browser other questions tagged

You are not signed in. Login or sign up in order to post.