Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. which textbox is entered?

which textbox is entered?

Scheduled Pinned Locked Moved C#
graphicsquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    melanieab
    wrote on last edited by
    #1

    Hi, I'm trying to use the same event for different textboxes - the only difference being the textbox name. Is there a way to determine which textbox the mouse has entered in a MouseEnter event, and then be able to do things with it like Graphics g = txtBox.CreateGraphics(); SizeF size = g.MeasureString(txtBox.Text,fontsmal); ? Thanks so much again!!! Mel

    J A 2 Replies Last reply
    0
    • M melanieab

      Hi, I'm trying to use the same event for different textboxes - the only difference being the textbox name. Is there a way to determine which textbox the mouse has entered in a MouseEnter event, and then be able to do things with it like Graphics g = txtBox.CreateGraphics(); SizeF size = g.MeasureString(txtBox.Text,fontsmal); ? Thanks so much again!!! Mel

      J Offline
      J Offline
      J4amieC
      wrote on last edited by
      #2

      Yes, the sender paarameter in the event handler is the textbox that sent the event

      private void AllTextBoxes_MouseEnter(object sender, MouseEventArgs e)
      {
         TextBox tb = sender as textBox;
         if(tb != null)
         {
             // A textbox raised this event
         }
      }
      
      M 1 Reply Last reply
      0
      • J J4amieC

        Yes, the sender paarameter in the event handler is the textbox that sent the event

        private void AllTextBoxes_MouseEnter(object sender, MouseEventArgs e)
        {
           TextBox tb = sender as textBox;
           if(tb != null)
           {
               // A textbox raised this event
           }
        }
        
        M Offline
        M Offline
        melanieab
        wrote on last edited by
        #3

        Awesome. Thanks!

        1 Reply Last reply
        0
        • M melanieab

          Hi, I'm trying to use the same event for different textboxes - the only difference being the textbox name. Is there a way to determine which textbox the mouse has entered in a MouseEnter event, and then be able to do things with it like Graphics g = txtBox.CreateGraphics(); SizeF size = g.MeasureString(txtBox.Text,fontsmal); ? Thanks so much again!!! Mel

          A Offline
          A Offline
          anandss
          wrote on last edited by
          #4

          The first argument to MouseEnter event "(object sender, EventArgs e)", sender is the control that triggered that event.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups