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. Generic forms call back?

Generic forms call back?

Scheduled Pinned Locked Moved C#
question
3 Posts 2 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.
  • D Offline
    D Offline
    dino2094
    wrote on last edited by
    #1

    I need to set the text on various form controls(textbox,label,buttons, etc) across threads. Right now, I have one method per control. Below is my SetButtonText method. private delegate void SetButtonTextCallback(System.Windows.Forms.Button tBox, string text); private void SetButtonText(System.Windows.Forms.Button tBox, string text) { if (tBox.InvokeRequired) { SetButtonBoxCallback d = new SetButtonTextCallback(SetButtonText); this.Invoke(d, new object[] { tBox, text }); } else { tBox.Text = text; } }Is it possible to have a generic method that I can pass the control and the text. So the call would look like: SetControlText(button1,"foo"); or SetControlText(label3,"bar");

    Steve EcholsS 1 Reply Last reply
    0
    • D dino2094

      I need to set the text on various form controls(textbox,label,buttons, etc) across threads. Right now, I have one method per control. Below is my SetButtonText method. private delegate void SetButtonTextCallback(System.Windows.Forms.Button tBox, string text); private void SetButtonText(System.Windows.Forms.Button tBox, string text) { if (tBox.InvokeRequired) { SetButtonBoxCallback d = new SetButtonTextCallback(SetButtonText); this.Invoke(d, new object[] { tBox, text }); } else { tBox.Text = text; } }Is it possible to have a generic method that I can pass the control and the text. So the call would look like: SetControlText(button1,"foo"); or SetControlText(label3,"bar");

      Steve EcholsS Offline
      Steve EcholsS Offline
      Steve Echols
      wrote on last edited by
      #2

      Just use System.Windows.Forms.Control instead of System.Windows.Forms.Button. Every Control has a Text property.


      - S 50 cups of coffee and you know it's on!

      • S
        50 cups of coffee and you know it's on!
        Code, follow, or get out of the way.
      D 1 Reply Last reply
      0
      • Steve EcholsS Steve Echols

        Just use System.Windows.Forms.Control instead of System.Windows.Forms.Button. Every Control has a Text property.


        - S 50 cups of coffee and you know it's on!

        D Offline
        D Offline
        dino2094
        wrote on last edited by
        #3

        Wow! So easy easy, I missed it! Thanks!

        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