Coverting C# System.Delegate.Combine

Super Dave

New member
Joined
Jul 3, 2009
Messages
4
Programming Experience
3-5
I'm trying to convert a C# project to vb CodeProject: Image Thumbnail Viewer with .NET 2.0. Free source code and programming help

The one thing that has me stumped is the conversion of a routine to add thumbnails to a layout panel.

A global event is declaired

Public Event OnImageSizeChanged As ThumbnailImageEventHandler

Then a section where each thumbnail image image is added with a size changed event for when a slider control is moved.

It looks like just a big multicast delegate where each image control is chained to the slider. So any change in the size slider changes each thumbnail image controls size.

C# original code:

this.OnImageSizeChanged += new ThumbnailImageEventHandler(imageViewer.ImageSizeChanged);


I assume that the += is shorthand for the System.Delegate.Combine

The problem is any attempt to have OnImageSizeChanged equal anything shows an error that says I must use a raiseevent.

How should this be changed to work in vb?


Regards,

Super Dave

Original C#

private void AddImage(string imageFilename)
{
// thread safe
if (this.InvokeRequired)
{
this.Invoke(m_AddImageDelegate, imageFilename);
}
else
{
int size = ImageSize;

ImageViewer imageViewer = new ImageViewer();
imageViewer.Dock = DockStyle.Bottom;
imageViewer.LoadImage(imageFilename, 256, 256);
imageViewer.Width = size;
imageViewer.Height = size;
imageViewer.IsThumbnail = true;

imageViewer.MouseClick += new MouseEventHandler(imageViewer_MouseClick);

this.OnImageSizeChanged += new ThumbnailImageEventHandler(imageViewer.ImageSizeChanged);

this.flowLayoutPanelMain.Controls.Add(imageViewer);
}
}
 
Addhandler

If you just want to add one yes, but what it is doing I think is adding a handler to the list not replacing the last one. This is used for browsing images. As each image is added a a listing in the event is added. The method of System.Delegate.Combine is the way to chain this all together. I just can't figure out how to use it in this context.
 
I don't believe so, when you combine delegates you would have to pass 2 event handlers, hence combine. It appears there are giving each image an event - use the sender object in each event and that is the image you currently working with. They all share the same code format/behavior - if you will.
 
Coversion

Thanks for the reply. I used Reflector to covert the project and for some reason it changed the signature of one of the events.

AddHandler imageViewer.MouseClick, AddressOf imageViewer_MouseClick
AddHandler Me.OnImageSizeChanged, AddressOf imageViewer.ImageSizeChanged

works correctly now and Addhandler will concatenate the event list.
 

Latest posts

Back
Top