C# Access A Form’s Controls Within A Class

There are a lot of beginner and even intermediate level developers that have no idea how to access/modify a forms objects/methods from within a different class. I’ll show you the easiest practice of this.

First we have to make a reference. We must use the ‘protected’ keyword. I use the same name as the windows form that way it is easy to keep track of variables.

capture2 C# Access A Forms Controls Within A Class

Once that is done you must set each method and object you want to access to public. You do this from the Forms Designer Class.

capture C# Access A Forms Controls Within A Class

And that’s it. With just 2 lines of code you can now access you forms controls and methods.

[Sorry for the images of the code, my code-box plugin is broken]

About Dremation

I'm just a computer programmer/site desinger.
This entry was posted in General, Programming, tips and tagged , , , , , , . Bookmark the permalink.

7 Responses to C# Access A Form’s Controls Within A Class

  1. i’m the beginner so thanks a lot for your help!

  2. adam says:

    thanks for that. helped a lot.

  3. Brandy says:

    Incredible. lifeofajackiass.com is amazing.

  4. Tory says:

    nAd this is the reason I love lifeofajwckass.com. Awesome posts.

    http://videooffish86.blogspot.com/2010/03/felicitare-video-retting.html

  5. Nadia says:

    Nice post. lifeofajackass.com is the shit.

    http://videoapostatel.blogspot.com/

  6. Long time lurker, thought I would say hello! I really dont post much but thanks for the good times I have here. Love this place..

    When I was hurt in that automobile accident my life would be changed eternally. Unfortunately that driver had no car insurance and I was going to be hurting for ever.

    This was not time for me to start and guess what to do. I had to find a good attorney to help me get what I needed. After all, my family was counting on me.

    How terrible was it? I has bedridden for 8 months, I had to have constant care and my clinic bills went through the roof!

    Thank goodness, I found a good referral site to help me.

    I will post more later this week to tell you more about what I have been going through.

    If you need an accident attorney try the guys at http://theaccidentlawyers.org

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>