Hi @BenTam-3003 , Welcome to Microsoft Q&A,
What you want and what you asked are not the same in the previous question.
I have carefully analyzed your current problem. You need to add a textchange event in the textbox to change the case. The specific code is as follows:
using System;
using System.Windows.Forms;
namespace xxxx
{
public partial class MyTextBox : TextBox
{
private bool allCapsText;
public MyTextBox()
{
InitializeComponent();
this.TextChanged += MyTextBox_TextChanged;
}
private void MyTextBox_TextChanged(object sender, EventArgs e)
{
if (AllCapsText)
{
int selectionStart = this.SelectionStart;
int selectionLength = this.SelectionLength;
this.Text = this.Text.ToUpper();
this.SelectionStart = selectionStart;
this.SelectionLength = selectionLength;
}
}
public bool AllCapsText
{
get { return allCapsText; }
set { allCapsText = value; }
}
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
}
}
}
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.