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. Get Control from another form

Get Control from another form

Scheduled Pinned Locked Moved C#
helptutorialcsharpquestionlearning
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.
  • T Offline
    T Offline
    T EDY
    wrote on last edited by
    #1

    Hi, i'm having a problem how to get a control from form 1 to form 2..for example: i want gridview name dgvBlaBla from form1 can be access from form 2 ?_? Can Anyone Help Me..I'm sorry i'm beginner in C# Regard, TCim

    M U 2 Replies Last reply
    0
    • T T EDY

      Hi, i'm having a problem how to get a control from form 1 to form 2..for example: i want gridview name dgvBlaBla from form1 can be access from form 2 ?_? Can Anyone Help Me..I'm sorry i'm beginner in C# Regard, TCim

      M Offline
      M Offline
      Michael Sync
      wrote on last edited by
      #2

      #1. Lets say there are two forms (form1, form2) in your application. you put one button called button1 in form2. You wanna get the control (button1) of form2 from form1. Add one public property which is returned the control that you required in form2 eg: public Button Button1 { get { return button1; } } Then, you can access this control from form1. eg: Form2 obj = new Form2(); MessageBox.Show(obj.Button1.Text); There are another way to get the control from other form or assembles. I'm not gonna mention here. If you are interest about this, please "Reflection" class from MSDN or google. Hope it helps.

      Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)

      T 1 Reply Last reply
      0
      • T T EDY

        Hi, i'm having a problem how to get a control from form 1 to form 2..for example: i want gridview name dgvBlaBla from form1 can be access from form 2 ?_? Can Anyone Help Me..I'm sorry i'm beginner in C# Regard, TCim

        U Offline
        U Offline
        Urs Enzler
        wrote on last edited by
        #3

        You've got an answer already, but I'm asking myself why you want to do this? because I think there is a bit of a design problem here (information hiding? encapsulation?)

        -^-^-^-^-^- no risk no funk

        1 Reply Last reply
        0
        • M Michael Sync

          #1. Lets say there are two forms (form1, form2) in your application. you put one button called button1 in form2. You wanna get the control (button1) of form2 from form1. Add one public property which is returned the control that you required in form2 eg: public Button Button1 { get { return button1; } } Then, you can access this control from form1. eg: Form2 obj = new Form2(); MessageBox.Show(obj.Button1.Text); There are another way to get the control from other form or assembles. I'm not gonna mention here. If you are interest about this, please "Reflection" class from MSDN or google. Hope it helps.

          Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)

          T Offline
          T Offline
          T EDY
          wrote on last edited by
          #4

          Thank You It Helps Me solve My problem:) Regard, Tomi

          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