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 / Windows Forms / WinForm General / January 2005

Tip: Looking for answers? Try searching our database.

missing click event for image

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Frederik - 14 Jan 2005 13:16 GMT
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
Bob Powell [MVP] - 14 Jan 2005 14:09 GMT
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.

Signature

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.

> Hi all,
>
[quoted text clipped - 7 lines]
> Thank you for your time and help,
> Frederik
Frederik - 14 Jan 2005 15:14 GMT
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

> "Bob Powell [MVP]" wrote...
> 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.

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.