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

  • Home
  • SEARCH
  • 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 7700403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:42:00+00:00 2026-05-31T22:42:00+00:00

I’m learning C# and what I need is to access control on a Form

  • 0

I’m learning C# and what I need is to access control on a Form from other class (the same namespace).

I know there is a lot of posts on this topic here but didn’t find complete solution ‘for dumbs’ so I write here what I figured out and please tell me – is this the correct way ?

Background: I have some ‘debugging’ form in my app and I need all other forms to be able to log their activity into this form. There is some ListBox control where all the logs from other forms are written. When I (or one of my tester-friends without Visual Studio) play around with app and something bad happens, I can look on that debug-form to see all detailed logs what happened just before that ‘moment of error‘.

My main form of the app (frmMain):

namespace myNamespace {

public partial class frmMain : Form {

private frmDebug debug;  // frmDebug is declared in other class
                         // we will hold reference to frmDebug form in 'debug'

public frmMain() {         // constructor of the main form 'frmMain'
  InitializeComponent();
  debug = new frmDebug();  // we create new instance of frmDebug immediately when
}                          // our main form is created (app started) and whole time
                           // of running this app we can access frmDebug from
                           // within frmMain through 'debug' variable


// clicking button 'btnLoggingTest', the log is written 
// in the 'frmDebug' form even if it is closed (not visible)
private void btnLoggingTest_Click(object sender, EventArgs e) {
  debug.Log("log this text for me please");
}

// Click handler of the button 'btnShowDebug' :
private void btnShowDebug_Click(object sender, EventArgs e) {
  debug.ShowDialog();    // here we can show frmDebug (in 'modal' style)
}                        // just to see what log-information is written there


} // frmMain class

} // namespace

And here is the code of class frmDebug itself :
(there is only one Listbox placed on the form)

namespace myNamespace {
public partial class frmDebug : Form {

public frmDebug() {
  InitializeComponent();
}

public void Log(string txt) {    // this is the actual 'Log' function (or method)
  this.listBox1.Items.Add(txt);
  Application.DoEvents();        // if the logging takes place in some 
}                                // computing-intensive 'loop' or function,
                                 // (or in my case FTP login and upload process)
                                 // 'DoEvents' ensures every log appears immediately
                                 // after the 'Log()' was called. Otherwise all logs
                                 // would appear together at once, as soon as the 
                                 // computing-intensive 'loop' is finished

} // class frmDebug

} // namespace

I have a strange feeling in my stomach I’m doing it all wrong so please tell me how to do it properly 🙂
If it’s OK, hope it helps somebody like me.

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-31T22:42:02+00:00Added an answer on May 31, 2026 at 10:42 pm

    Your application has probably a class called “Program”. There you will find the code

    var mainForm = new frmMain();
    Application.Run(frmMain);
    

    Create a static property for the debugging form in this class

    public static frmDebug DebuggingForm { get; private set; }
    

    Change the startup code like this

    DebuggingForm = new frmDebug();
    var mainForm = new frmMain();
    Application.Run(frmMain);
    

    From other classes you can access this form like this

    Program.DebuggingForm.Log("log this text for me please");         
    Program.DebuggingForm.Show();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I have a bunch of posts stored in text files formatted in yaml/textile (from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but

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.