Solved

C# -- Textbox "KeyPress" EVENT on two textboxes

Posted on 2009-07-16
1
1,460 Views
Last Modified: 2013-12-17
I have two textboxes (TextBox1 & TextBox2)

Change below "TextBox1.AppendText.." to
something dynamic so I can use this one
"TextBox_KeyPress" EVENT on both textboxes.
------------------------------------------------------------
    private void TextBox_KeyPress(
      System.Object sender, KeyPressEventArgs e)
    {
      if (Char.IsLetter(e.KeyChar) && Char.IsLower(e.KeyChar)
        || char.IsWhiteSpace(e.KeyChar))
      {
        TextBox1.AppendText(
          Char.ToUpper(e.KeyChar).ToString());
        e.Handled = true;
      }
    }
0
Comment
Question by:finance_teacher
1 Comment
 
LVL 12

Accepted Solution

by:
GuitarRich earned 500 total points
Comment Utility
Use the sender object - that is the control that sent the event. Something like this:
    private void TextBox_KeyPress(

      System.Object sender, KeyPressEventArgs e)

    {

      if (Char.IsLetter(e.KeyChar) && Char.IsLower(e.KeyChar) 

        || char.IsWhiteSpace(e.KeyChar))

      {

        ((TextBox)sender).AppendText(

          Char.ToUpper(e.KeyChar).ToString());

        e.Handled = true;

      }

    }

Open in new window

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now