How to change properties of custom control?

Setting Custom Properties in VB?

  • I have created a custom WinForms control in VS2010. Within the control is a label, and I would like to be able to change the text of that label after placing the control in another application, without having to use the line: <MyControl>.Controls.Item("label1").Te… = "Hello, I'm a label" I figured the best way to go about this was probably to add a new property to the main UserControl that can change the text of the label through simpler code. But how would I do this? Also, a side question: How would I go about changing the toolbox icon of the control? Thanks. P.S.: Sorry if these questions sound a bit 'noobish'... While I have been developing in VB and C# for years, I have barely touched UserControls. And I'd rather not have to make my own components for something like this, since that would probably over-complicate it further.

  • Answer:

    You will want to add a Property to your user control. The Get for the property will return label1.Text. Set will assign Value to label1.Text. See first link. Find the section titled "Adding Properties to Your User Control" To change the toolbox icon, see second link.

Cameron at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.