Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / Extensibility / April 2006

Tip: Looking for answers? Try searching our database.

How do I add to a form's ImageList from an add-in?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
slush_puppy - 20 Apr 2006 15:07 GMT
I have a package that needs to add a set of images to an ImageList on a
form in the current project.  This would involve updating the
InitializeComponent() section of the form in the *.designer.cs file and
also adding the image data to the form's *.resx file.  Is there a way
to do this programmatically, or do I have to manually update these
files directly using edit points?  I don't see any way to do it using
the code model and it would be a nightmare trying to update the
ImageStream properties directly.
Carlos J. Quintero [VB MVP] - 20 Apr 2006 15:15 GMT
Hi,

See my articles:

HOWTO: Add a control to a Windows form from a Visual Studio add-in
http://www.mztools.com/Articles/2006/MZ016.htm

HOWTO: Manipulating controls of Windows forms from Visual Studio .NET
add-ins
http://www.mztools.com/articles/2005/MZ001.htm

Signature

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com

>I have a package that needs to add a set of images to an ImageList on a
> form in the current project.  This would involve updating the
[quoted text clipped - 4 lines]
> the code model and it would be a nightmare trying to update the
> ImageStream properties directly.
slush_puppy - 20 Apr 2006 17:05 GMT
Thanks Carlos, those are both great articles.  Your whole collection of
articles is very impressive.

The suggestions got me 90% of the way there.  When I get to the
ImageList's Images property descriptor, it's value is of type
System.Windows.Forms.Design.ImageListDesigner.  This must be private or
internal class because there's no way to declare a variable of that
type (I get an "inaccessible due to its protection level" error when
compiling).

So I've gotten to the property, I just can't get or set the value.
Here's my code:

// get the Windows Form designer
designerHost =
(System.ComponentModel.Design.IDesignerHost)designerHostObj;
// get the designer's control container
container = designerHost.Container;
// iterate over the components
foreach (IComponent component in container.Components)
{
   // check if we've got the image list
   if (component is ImageList)
   {
       PropertyDescriptorCollection pdc =
TypeDescriptor.GetProperties(component);
       PropertyDescriptor pd = pdc["Images"];
       string x = pd.GetValue(component).ToString();
   }
}

It finds the image list and at the end if the if block, x =
"System.Windows.Forms.Design.ImageListDesigner+OriginalImageCollection"

Any idea where to go from here?  Thanks again for the great help!
slush_puppy - 20 Apr 2006 17:50 GMT
Well, I made a little more progress here.  I'm able to cast the value
to an IList.  It's reporting the image count correctly, so that worked.
However, when I try to add an image, it throws an exception reporting:

System.ArgumentException was unhandled
Message: Parameter must be of type ImageListImage

Unfortunately, ImageListImage looks like another one of those private
or internal classes.  I'm so close I can taste it!  Any ideas?
Carlos J. Quintero [VB MVP] - 21 Apr 2006 10:39 GMT
For the internal classes / properties that are not accesible outside the
designer, try using Reflection. You can use Reflector .NET
(http://www.aisto.com/roeder/dotnet/) to see the internal implementation of
the designers to know what to send and why exceptions are raised.

Signature

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com

> Well, I made a little more progress here.  I'm able to cast the value
> to an IList.  It's reporting the image count correctly, so that worked.
[quoted text clipped - 5 lines]
> Unfortunately, ImageListImage looks like another one of those private
> or internal classes.  I'm so close I can taste it!  Any ideas?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.