3 Replies - 1785 Views - Last Post: 04 February 2011 - 02:28 PM Rate Topic: -----

#1 PeterH  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 46
  • Joined: 03-September 09

Reading text at Mouse position in PictureBox

Posted 03 February 2011 - 04:44 AM

Hi All,

I have a Picturebox in which I have drawn rectangles with 'Text' values representing Months of the year, i.e. Jan, Feb, etc. etc. I want to show a Tooltip when the user clicks on a Months title. The picturebox control does not have a 'getItemAt' function so how can I read this text.

I am determining the mouse position using mousedown event.


Private Sub periodbox_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PeriodBox.MouseDown
        Dim w, h As Integer
        w = e.X
        h = e.Y
End Sub 


Any Suggestion welcome

Pete

This post has been edited by AdamSpeight2008: 04 February 2011 - 02:34 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Reading text at Mouse position in PictureBox

#2 motcom  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 288
  • View blog
  • Posts: 1,371
  • Joined: 16-June 08

Re: Reading text at Mouse position in PictureBox

Posted 03 February 2011 - 05:31 AM

dude, what item must it get? is it an object? or layer? what do you expect will return from a picture box?

A picture pox displays images, so most probably you can get the color of the pixel at the specific location of your mouse.. but that's it. how must it know even that there is something like a month or a day or whatever in the image???

EDIT: just a hint, forget about the picture box, rather build a custom control, it will be faster to design and will give you better results. (Why re-invent the wheel?)

This post has been edited by motcom: 03 February 2011 - 05:33 AM

Was This Post Helpful? 0
  • +
  • -

#3 _HAWK_  Icon User is online

  • Master(Of Foo)
  • member icon

Reputation: 966
  • View blog
  • Posts: 3,721
  • Joined: 02-July 08

Re: Reading text at Mouse position in PictureBox

Posted 03 February 2011 - 07:30 AM

You can make a custom class that has a rectangle as a member and the text, etc...

Public Class CustomRect
  Public Rect As Rectangle
  Public Text As String
  Public cColor As Color
End Class


Dim myCustomRects As New List(Of CustomRect)
'add the objects that you need


'then in mouse event
For Each cr As CustomRect In myCustomRects
  If cr.Rect.Contains(e.Location) Then
    'cr.Text is text in that rectangle
  End If
Next

This post has been edited by hawkvalley1: 03 February 2011 - 07:30 AM

Was This Post Helpful? 0
  • +
  • -

#4 PeterH  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 46
  • Joined: 03-September 09

Re: Reading text at Mouse position in PictureBox

Posted 04 February 2011 - 02:28 PM

View Postmotcom, on 03 February 2011 - 05:31 AM, said:

dude, what item must it get? is it an object? or layer? what do you expect will return from a picture box?

A picture pox displays images, so most probably you can get the color of the pixel at the specific location of your mouse.. but that's it. how must it know even that there is something like a month or a day or whatever in the image???

EDIT: just a hint, forget about the picture box, rather build a custom control, it will be faster to design and will give you better results. (Why re-invent the wheel?)


Thanks for the replies. I am using the picbox to draw charts, bar/pie etc. etc. and was looking for a way of reading text directly from the screen,similar to that seen when using the debugger and interogating variables.

This is something I have done before in other dev languages, and likened it to 'getting' a datagrid cell value under the mouse pointer. Anyway, I have a solution now using the mousehover event, determining the 'cell' from the mouse position and populating a tooltip.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1