PDA

Click to See Complete Forum and Search --> : Creating new controls...Help needed badly


hellswraith
May 24th, 2002, 11:16 AM
Hello everyone, I am hoping someone real good with this c# stuff can help me out.

I am trying to create my own control. I am basing it off of the Panel control. What I want to do is have my control take in image paths (on the hard drive), create a thumbnail of it, and display it on a panel object in a vertical or horizontal fashion, whichever the property is set as. I want all this to be self contained, which is the reason I am creating my own control. When the control is clicked, I want to receive that event inside my control, and process which thumbnail was clicked and do the appropriate actions, then call an event so the user of my control can get the index of the thumbnail that was clicked so they can take actions on it accordingly... Hope that makes sense to you...

Anyway, I KIND OF understand I am going to be using delegates and what nots. I think I got the idea of publishing the event to the user, but I have no idea how to receive the event from the initial click on the control which inherits from the panel control.

Can someone create a SUPER simple user control that inherits from another control and takes the click event from the control, process a little code inside the control, then pass on a custom event to the user? I am lost.

Cander
May 24th, 2002, 11:42 AM
ok this is a guess


using System;
using System.Windows.Forms;

public class Simple : Panel {

protected override void Click(object sender, EventArgs e output) {
//do whatever;
}
}




or somethin like that

hellswraith
May 24th, 2002, 11:55 AM
I'll give it a try. I forgot about the override word...lol. Thanks, I will let you know if it works.

hellswraith
May 24th, 2002, 11:56 AM
By the way, are you posting as Cander over in the C-SharpCorner site?

hellswraith
May 24th, 2002, 12:15 PM
Ok, I tried it, but I am getting a compile error. Here is the code for my control so far. Maybe it will help you understand it a bit more and what I am trying to do.


using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace ThumbnailImagePanelLib
{
/// <summary>
/// Summary description for UserControl1.
/// </summary>
public class ThumbnailImagePanel : System.Windows.Forms.Panel
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public ThumbnailImagePanel()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
// TODO: Add any initialization after the InitForm call
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if( components != null )
components.Dispose();
}
base.Dispose( disposing );
}

#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion

public delegate void ImageChangeHandler(object thumbnailimagepanel, ImageArgs imageIndex);
public event ImageChangeHandler OnImageChange;

/*Here is the override you suggested,
it is throwing an error when it tries
to compile.*/
protected override void Click(object sender, EventArgs e)
{
//All I am doing here is passing an index for trial purposes only.
int test;
test = 5;
ImageChanged(test);
}

public void ImageChanged(int Index)
{
ImageArgs imageInfo = new ImageArgs(Index);
if(OnImageChange != null)
{
OnImageChange(this,imageInfo);
}
}
#endregion

}

public class ImageArgs : EventArgs
{
public ImageArgs(int iThumbIndex)
{
this.iThumbIndex = iThumbIndex;
}
public readonly int iThumbIndex;
}
}

Cander
May 24th, 2002, 09:31 PM
yeah the Cander at C# Corner is me :)

hmm what error does it throw you as that looks correct?

hellswraith
May 25th, 2002, 08:54 AM
After searching around a bit more, I don't think the Panel class has a click event to subscribe to anyway, hence the error. It is just a container class. So what I am planning to do is when adding controls to it, I will subscribe to their click events and catch those (this is what I am really after anyway). I don't think I will have a problem doing that...but who knows, I may be back...lol.

Thanks for your inputs, they got me thinking in the right direction.