Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to access this down_time variable in usercontrol click event;

MainForm
public partial class MainForm : Form
   {
      public MainForm()
       {
           InitializeComponent();

       }

       public int down_time;

   }



Usercontrols

public partial class Machine_Running : UserControl
    {
 
        private void btn_Click(object sender, EventArgs e)
        {
            lable1.text = // this is where i wanna assign it 
        }

    }


What I have tried:

I tried to used this.Parent in UserControl to get the parent form but no luck. please help
Posted
Updated 26-Mar-19 12:54pm

Your UserControl code should not be doing ANYTHING AT ALL with controls in the containing form.

The code in the UserControl should ONLY be concerned with the controls in its own design surface.

If you want to tell the containing for to show some data, your UserControl should expose an Event that the containing for subscribes to tell it there is some data it may be interested in. It's then up to the containing form code to determine what to do with that data.

Google: C# usercontrol custom events[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900