For Programmers: Free Programming Magazines  


Home > Archive > C# .NET > April 2004 > accessing component from another form









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author accessing component from another form
J F

2004-04-27, 2:22 am

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
Dmitriy Lapshin [C# / .NET MVP]

2004-04-27, 12:16 pm

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!

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"J F" <jfk_pub@netcourrier.com> wrote in message
news:49fcea0a.0404261908.514d3b48@posting.google.com...
> 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


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com