Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

Themed textbox keypress event not working

Hi, when using no theme the following code works properly to only allow number input to textbox:

Code
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
    if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) &&
        (e.KeyChar != '.'))
    {
            e.Handled = true;
    }

    // only allow one decimal point
    if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
    {
        e.Handled = true;
    }
}

Code
this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(textBox1_KeyPress);

But when I use a theme with the exact same code (textBox1) replaced with proper name, it does not work and the user can input any character. How can I fix this?
Did you set the property event to the themed-textbox?

Simply changing the event name over to the themed textbox's name will not work.
(Jul 25, 2016 05:12 PM)CoderEX Wrote:  Did you set the property event to the themed-textbox?

Simply changing the event name over to the themed textbox's name will not work.

The modified code looks like this and these are the only changes I've made:

Code
private void themedTextBox1_KeyPress(object sender, KeyPressEventArgs e)
{
//...
}

Code
this.themedTextBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(themedTextBox1_KeyPress);
Most of those themed TextBoxes are just regular TextBoxes inside of a parent container. Once you focus the child textbox, the parent events are ignored. You need to handle this event inside of the "ThemedTextBox" class. Alternatively, you could look into MintUI which themes an actual TextBox control and doesn't use some hacky workaround.

https://github.com/CodeRail/MintUI


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by agoSwitchDec 27, 2021 08:53 AM 6 298 Dec 27, 2021 08:53 AM
Last Post: oje28830
[.NET] by InterGalacticMar 11, 2019 02:44 AM 6 282 Mar 11, 2019 02:44 AM
Last Post: InterGalactic
[.NET] by ChristmasNoobJan 28, 2019 03:21 PM 1 165 Jan 28, 2019 03:21 PM
Last Post: HeadHoncho