missing click event for image

  • Thread starter Thread starter Frederik
  • Start date Start date
F

Frederik

Hi all,

Situation: Windows Forms, DataGrid, CSharp, WinXP Pro, VS 2003

How can I add a click event to an Image?
The Imageis in a DataGrid, drawn with the 'DrawImage' mehtod.
The Image does not seem to have a click event!
[Using a PictureBox instead of an Image resulted in buggy drawings.]

Thank you for your time and help,
Frederik
 
Image is not based on Control. You need to trap the click event of the
datagrid and detect which cell it's in. if it's in a cell with an image,
that's your click.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Thank you very much Bob...
Thanks to your tip I found what I needed (openening a webpage when an icon
is clicked in the datagrid - the url is too long to display).
Here's my code (snippet):

private void FilmGrid_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)
{
DataGrid.HitTestInfo hti;
hti = FilmGrid.HitTest(e.X, e.Y);
// column 0 contains an url, but is not visible (width=0)
// column 1 contains an internet explorer like icon
if (hti.Column == 1 && hti.Type == DataGrid.HitTestType.Cell)
{
// get url
string url = FilmGrid[hti.Row, 0].ToString();
// # must be removed (coming from xml file)
url = url.Substring(1, url.Length - 2);
// start default browser
System.Diagnostics.Process.Start(url);
}
}

Regards,
Frederik
 
Back
Top