accessing component from another form

J

J F

Hi all

I'm totally new to Visual Studio, coming from Delphi.
My question, I'm sure is pretty trivial.

I'm using C#

I have a component class (Project/Add Class/Component Class). In this
component class, I drop an ImageList.

Now, in my main form, I put a button. I would like to define the ImageList
property of my button to be the one created in the component class. I can
achive this by code but I want to define visually (at design time) the
property so I can select the ImageIndex property before compiling.

I hope I was clear, English is not my native tongue ...

TIA

J F
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi,

1. Make the ImageList a public property on the created component. The
simplest way is to open the component in the designer and set the
ImageList's Visibility (or Protection, don't remember the exact name)
property to "public".

2. Now, compile the project and add the component to the main form

3. In the form constructor, add the following line after the call to
InitializeComponent:

myButton.ImageList = myComponent.ImageList // Assumes that the component's
property is
// called ImageList.

I'm afraid there's no fully visual way. You can visually initialize control
properties to another controls or components on the same form (given they
are of the appropriate type), but most likely not to their properties.

BTW: This would be a nice VS .NET feature if such initialization would be
possible!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top