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. c# button control

c# button control

Scheduled Pinned Locked Moved C#
csharpquestion
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.
  • R Offline
    R Offline
    reshsilk
    wrote on last edited by
    #1

    hello, i'm working on a .NET windows form. i have programmatically created a column of buttons using the following code: for (int j = 0; j < farmData.Tables["plate"].Rows.Count; j++) { Button viewBtn = new Button(); viewBtn.Text = "View"; viewBtn.Name = "viewBtn" + j.ToString(); viewBtn.UseVisualStyleBackColor = true; viewBtn.Click += new System.EventHandler(this.viewBtn_Click); tbl.Controls.Add(viewBtn, 0, j + 2); } when i push a button, and the viewBtn_Click method is called, how do i get the button name so that i know exactly which button was pushed? Thanks in adavance for any insight! RC

    L 1 Reply Last reply
    0
    • R reshsilk

      hello, i'm working on a .NET windows form. i have programmatically created a column of buttons using the following code: for (int j = 0; j < farmData.Tables["plate"].Rows.Count; j++) { Button viewBtn = new Button(); viewBtn.Text = "View"; viewBtn.Name = "viewBtn" + j.ToString(); viewBtn.UseVisualStyleBackColor = true; viewBtn.Click += new System.EventHandler(this.viewBtn_Click); tbl.Controls.Add(viewBtn, 0, j + 2); } when i push a button, and the viewBtn_Click method is called, how do i get the button name so that i know exactly which button was pushed? Thanks in adavance for any insight! RC

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You should be able to cast the sender parameter to Button type: Button button = (Button)sender; regards

      R 1 Reply Last reply
      0
      • L Lost User

        You should be able to cast the sender parameter to Button type: Button button = (Button)sender; regards

        R Offline
        R Offline
        reshsilk
        wrote on last edited by
        #3

        that did the trick. thank you!

        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