That’s it. It’s a dumb dumb (embarrassing!) question, but I’ve never used C# before, only C++ and I can’t seem to figure out how to access a Label on my main form from a secondary form and change the text. If anybody can let me know real quick what to do I’d be so grateful!
BTW, I should really clarify. Sorry: I’ve got two separate .cs files that each look about like below. I was using the [Designer] in VS2008 to add in the label in Form1. When I type something like Form1.label1 it doesn’t understand. The dropdown shows a list of methods and properties for Form1, but there’s only about 7, like ControlCollection, Equals, MouseButtons, and a couple others… I can publicly define a variable in Form1 and that shows, but I don’t know how to access the label…
namespace AnotherProgram { public partial class Form1 : Form { public Form1() { InitializeComponent(); } } }
You’ll need a reference to the instance of Form1 – for example, if it’s Form1 which is constructing Form2, you might pass
thisin as a constructor parameter.Then you’ll need to either expose the label of Form1 via a property (or – ick! – a non-private field) or write a method/property which will set the text of the label. For example: