Re: Segments
- From: "Rick Rothstein" <rickNOSPAMnews@xxxxxxxxxxxxxxxxx>
- Date: Thu, 30 Mar 2006 14:55:11 -0500
Within as form I have a sub that draws segments that go to make a pie
chart, The sub has these args:
R As RECT
StartPercent As Single
EndPercent As Single
TheColour As Long
TheHDC As Long
So- if I had the code:
DrawSegment R, 25, 58, vbRed, Me.Hdc - then a red one third segment would
be drawn on the form.
All works well.
Question 1:
How can I find out the X & Y (in pixels) of the two points of the segment
on the diameter of the circle.
Question 2:
I would like to have a tooltip that says what the sement is representing
when the mouse is over the segment. But how would I know when the mouse
cursor is over the segment.
It is not clear how your DrawSegment subroutine works (for example, you do
not seem to need to tell it the center of the pie-shaped wedge), but are you
aware that VB's Circle method can draw pie-shaped wedges? Here is some
example code that I am pretty sure will draw the same wedge your above code
does...
Const TwoPI As Double = 6.28318530717958
Me.DrawWidth = 3
Me.FillColor = vbRed
Me.FillStyle = vbFSSolid
Me.Circle (Cx, Cy), R, vbBlack, -0.25 * TwoPI, -0.58 * TwoPI
where (Cx,Cy) are the coordinates of the center of a wedge that is filled in
with red and outlined in black and your percentage values are converted to
their decimal equivalents and multiplied by the number of radians (PI) that
make up an entire circle. Below is some code showing how to recognize
whether the cursor is inside or outside of the wedge (using the color of the
wedge for the determining this). Start a new project and paste the code
below into the code window.
Dim WedgeColor As Long
Dim Ray1 As Double
Dim Ray2 As Double
Dim Radius As Double
Dim CenterX As Double
Dim CenterY As Double
Const TwoPI As Double = 6.28318530717958
Private Sub Form_Activate()
Ray1 = 25
Ray2 = 58
Radius = 2000
CenterX = 4000
CenterY = 3000
WedgeColor = vbRed
Me.DrawWidth = 3
Me.FillColor = WedgeColor
Me.FillStyle = vbFSSolid
Me.Circle (CenterX, CenterY), Radius, vbBlack, _
-Ray1 * TwoPI / 100, -Ray2 * TwoPI / 100
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
Dim ArcTan As Double
If (X - CenterX) ^ 2 + (Y - CenterY) ^ 2 <= Radius ^ 2 Then
ArcTan = Atn((Y - CenterY) / (X - CenterX)) / TwoPI
If Point(X, Y) = WedgeColor Then
Debug.Print "INSIDE"
Else
Debug.Print "Outside"
End If
Else
Debug.Print "Outside"
End If
End Sub
You should be able to modify the ideas here to fit into your own program.
The only thing I was not clear on is whether you actually need the
coordinates of the ends of the rays (where the radius line hits the
circumference of the circle) or just wanted them in order to do one of the
calculations cover automatically in the above code.
Rick
.
- Follow-Ups:
- Re: Segments
- From: Ivar
- Re: Segments
- References:
- Segments
- From: Ivar
- Segments
- Prev by Date: Re: printer.font.size
- Next by Date: Re: Segments
- Previous by thread: Re: Segments
- Next by thread: Re: Segments
- Index(es):