Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4619944
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:29:36+00:00 2026-05-22T02:29:36+00:00

This should be quite simple really – not sure what the problem is. I

  • 0

This should be quite simple really – not sure what the problem is.

I have a C# Class (Public.cs) and a windows form (Form1.cs). Through a function in Public.cs, I want to get the value of a control on Form1 (without having to use object parameters).

// This code appears in Public.cs
public string MyFunction(int num_val)
{
  if (chk_num.checked == true)
  {
     // Something here...
  }
}

The issue is that my class cannot find the control on my form. Is there some way that I must reference it in C#?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:29:36+00:00Added an answer on May 22, 2026 at 2:29 am

    I would strongly suggest exposing the Checked property via a specific property on Form1 (perhaps with a more meaningful name). This will help to hide the implementation details (i.e. control structure) of the Form1 from it’s caller and instead expose only the logic that is required for other consumers to do their job

    For example:

    public bool IsNumberRequested
    {
        get { return chk_num.Checked; }
    }
    

    Or alternatively, if you still really want to access the control directly, from the designer you can select the control and change it’s Modifier property to public (or something else) enabling you to access the control object using the code you originally wrote above.

    EDIT: (Response based on comment)

    Public.cs will still need a reference to Form1 and then will call the IsNumberRequested property of that object.

    // Public.cs
    public class Public
    {
        private Form1 _ui;
    
        public Public(Form1 ui) { _ui = ui };
    
        public string MyFunction(int num_val)
        {
             if (_ui.IsNumberRequested)
             {
                  // Stuff
             }
             // Else, default Stuff
        }
    }
    

    Alternatively, you could pass the form as a parameter to the MyFunction too rather than using it as an instance variable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Unfortunately, the answer to this question isn't quite as simple as it sounds... but
I am using java and the purpose of my demo application is simple: Update
Maybe an over elaborate title. Basically think of an email inbox. I have a
My Oracle database contains some simple, rarely-changed data (it takes about months or even
If you use the satellite GMapType using this Google-provided example in v3 of the
I've been driving myself crazy trying to make this work. Variations of my attempt
In WPF most controls have MouseUp and MouseDown events (and the mouse-button-specific variations) but
I have a controller that extends Zend_Controller_Action. It contains some actions that I need
So, I've been playin' around with sessions in PHP today, and after procrastinating over
I am having some trouble pulling RSS off of blogger page and publishing it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.