Reputation: 1
I have made a user control with a pic box and a blank label. How do I expose the label so I can update the text value from my main .net application. I have not written any c# code in about 10 years, and was just thrown a project. All I have for code is:
namespace RHeader1
{
public partial class RHeader : UserControl
{
public RHeader()
{
InitializeComponent();
}
}
}
Please for give my stupidity. I know I need to do a get/set but?????
Upvotes: 0
Views: 1478
Reputation: 50
if you haven't delclared the label:
label1 = new label();
then
label1.text = "some text";
where you can replace "Some text" with any string value.
Upvotes: 0
Reputation: 655
You could change the Label's modifier property to public, this will result in the labels properties been visible from the UC's property window and also allow you to do something like
uc.label.Text = "foo";
Upvotes: 0
Reputation: 5194
I presume you mean because controls are not public, the proper way to access them are via a property (which I agree with) - so you can just expose a property which updates the label directly - I'm presuming this is winforms
public string Label
{
get { return label1.Text; }
set { label1.Text = value; }
}
Upvotes: 1
Reputation: 252
Use this:
Label lbl= (Label)myUserControl.FindName("yourlabelname");
This way you can find and update your label control settled in the UserControl
.
Upvotes: 0