Interactive drawn controls (hittest questions)

  • Thread starter Thread starter Brian Henry
  • Start date Start date
B

Brian Henry

Hello,

I am trying to make a user control that is interactive. What I am doing is
drawing a set of bars on a control similar to a gantt chart and allowing a
user to place the mouse over them to see a tool tip, or if you click on them
to open a form associated with data tied behind them.

What I can't figure out how to do (I have been looking at a few very complex
examples and it's hard to pull out how they did it) is how do you create a
control like this, draw any number of these objects on it then do this hit
test. the first one I pretty much have figured out, each bar item on the
chart will be a instanciation of a LineBar class which is stored in an
arraylist of other bars in the control then the OnPaint method calls each
item's render method I created to draw that item. (I believe thats how I
should do it?) anyways, the part I can not figure out is how to do an
effective hit test on the objects. How do you figure out which one had mouse
interaction, and what type of mouse interaction occured? I'm looking for a
simple example that is explained relatively good so I can fully understand
it. All the examples I have looked at had tons of unrelated code mixed into
them so discerning between the hit test code and the unrelated code is hard.
Thanks everyone!
 
Brian said:
Hello,

I am trying to make a user control that is interactive. What I am
doing is drawing a set of bars on a control similar to a gantt chart
and allowing a user to place the mouse over them to see a tool tip,
or if you click on them to open a form associated with data tied
behind them.

Basically you need to capture mouse events of whatever container you're
drawing the bars on, and use the mouse coordinates to determine yourself
over which bar the mouse is positioned.
 
yes that part i get, but how do i determain which bar i drew on the screen
is the one that the mouse had interaction with
 
Use an array of Rectangle objects and use the rectangles Contains method.

'-- Sample
Dim r As New Rectangle(1, 10, 20, 40)

If r.Contains(e.Y, e.Y) then
'-- I'm hit
End If


Brian said:
yes that part i get, but how do i determain which bar i drew on the screen
is the one that the mouse had interaction with
 
Hello,

I think this may be my problem here. Each bar is it's own class, because it
holds other data like start date, end date, number of people working on
project, etc. The class has its own render method which is called from the
controls OnPaint event as it goes through each bar object (I have an array
list of bar objects which the OnPaint method goes through and calls their
render method) to draw it on the control. Now, please tell me if I am doing
this incorrectly, is this how I should do it? if so how would i create an
array of rectangles in the main control to look for the bar objects? Here's
an example of the Bar class (simplified version with just data and the
render stub)

Public Class BarObject
Private d_StartDate as date
Private d_EndDate as date
Private i_WorkerCount as integer

public property GetStartDate...
public property GetEndDate...
public property GetWorkerCount...

Public Sub Render(byval e as PaintEventArgs)
'/// Do Rendering of bar here on control
e.graphics.drawrectangle....
End Sub

thats a quick example...

now what I want to do is have the control when the user places the mouse
over a bar show a tooltip that says the worker count, start, and end date.
all the rendering I know how to do on my own. it's just the mouse
interaction that is getting me. I did see somewhere on vbacellerator (one of
the outlook style listbar classes) that they created an IMouseObject
implementation that had MouseOver MouseMove.. stuff like that and
implemented it in their object...

I guess what I need to see is example code... all the code I have loooked at
has so much else in it (like the outlook bar on vbacellerator) that just
distracts my thinking...



End Class
yEaH rIgHt said:
Use an array of Rectangle objects and use the rectangles Contains method.

'-- Sample
Dim r As New Rectangle(1, 10, 20, 40)

If r.Contains(e.Y, e.Y) then
'-- I'm hit
End If
 
Hi Brian,

I reviewed the thread and found that there is a similar post in the
newsgroup.
Subject: Hit Test example
Newsgroups: microsoft.public.dotnet.languages.vb

Now we have posted a reply to that issue, you may go and have a check.


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top