|
-
Dec 6th, 2006, 08:06 PM
#1
Thread Starter
Hyperactive Member
Active X Control
Hey everyone,
I am creating this Active X Control... but I want it to be a circle. I am trying to use the code that I use to make a form circular, but it doesn't work in the Actice X Control... Any Idea about how I can do it??...
Also, I have this piece of code, that should only work on the outer ring of the control... I want the centre circle to be inactive... Think of it as a Ipod Click wheel... When the user moves the mouse over the outside circle, the code is executed, whereas when the user moves the mouse over the inner circle, the code doesn't work. So I was wondering, If I can somehow check if the mouse is in a the "area" of a circle. Any guesses??
If you require me to add any additional information, please let me know...
I would really appreciate your help.
Khanjan
Hey... If you found this post helpful please rate it.

-
Dec 6th, 2006, 08:51 PM
#2
-
Dec 6th, 2006, 08:55 PM
#3
Re: Active X Control
Create a new project, add usercontrol in there and try this out:
Code:
Option Explicit
Private Declare Function Arc Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long, ByVal X4 As Long, ByVal Y4 As Long) As Long
Private Declare Function Ellipse Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Public Sub DrawArc(ByVal hdc As Long, ByVal x As Integer, ByVal y As Integer, ByVal StartAngle As Integer, ByVal EndAngle As Integer, ByVal radius As Integer)
Dim xs As Integer, ys As Integer, xe As Integer, ye As Integer
Dim sat As Integer
sat = (StartAngle - 90) Mod 360
If (StartAngle >= 360) And (sat = 0) Then sat = 360
xs = Int(x - (radius * Sin((sat / 180) * 3.14159267)))
ys = Int(y - (radius * Cos((sat / 180) * 3.14159267)))
sat = (EndAngle - 90) Mod 360
If (EndAngle >= 360) And (sat = 0) Then sat = 360
xe = Int(x - (radius * Sin((sat / 180) * 3.14159267)))
ye = Int(y - (radius * Cos((sat / 180) * 3.14159267)))
If Abs(EndAngle - StartAngle) < 360 Then _
Arc hdc, x - radius, y - radius, x + radius, y + radius, xs, ys, xe, ye _
Else _
Ellipse hdc, x - radius, y - radius, x + radius, y + radius
End Sub
Private Sub UserControl_Initialize()
UserControl.ScaleMode = vbPixels
End Sub
Private Sub UserControl_InitProperties()
UserControl_Resize
End Sub
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
UserControl_Resize
End Sub
Private Sub UserControl_Resize()
Dim intMinSize As Integer
UserControl.BackColor = UserControl.MaskColor
If UserControl.ScaleWidth <= UserControl.ScaleHeight Then
intMinSize = UserControl.ScaleWidth \ 2
Else
intMinSize = UserControl.ScaleHeight \ 2
End If
DrawArc UserControl.hdc, UserControl.ScaleWidth \ 2, UserControl.ScaleHeight \ 2, 0, 360, intMinSize
Set UserControl.MaskPicture = UserControl.Image
UserControl.BackColor = vbRed
End Sub
Also you must set BackStyle of the control to Transparent and FillStyle to Solid. And AutoRedraw = True as well.
This method "naturally" allows for any shape.
Edit!
As for clicking, you can create an invisible image where you draw click areas, you can use different colors for that, like blue for some area and green for another. Then when you're clicking on the control you look at the invisible image to see what was actually pushed.
Last edited by Merri; Dec 6th, 2006 at 09:02 PM.
-
Dec 6th, 2006, 09:13 PM
#4
Re: Active X Control
Here is a slight modification: it makes a hole in to the control 
VB Code:
Private Sub UserControl_Resize()
Dim intMinSize As Integer
UserControl.BackColor = UserControl.MaskColor
UserControl.FillColor = vbBlack
If UserControl.ScaleWidth <= UserControl.ScaleHeight Then
intMinSize = UserControl.ScaleWidth \ 2
Else
intMinSize = UserControl.ScaleHeight \ 2
End If
DrawArc UserControl.hdc, UserControl.ScaleWidth \ 2, UserControl.ScaleHeight \ 2, 0, 360, intMinSize
UserControl.FillColor = UserControl.MaskColor
DrawArc UserControl.hdc, UserControl.ScaleWidth \ 2, UserControl.ScaleHeight \ 2, 0, 360, intMinSize \ 2
Set UserControl.MaskPicture = UserControl.Image
UserControl.BackColor = vbRed
End Sub
And as you can see, you can see and click the other controls through the control.
-
Dec 6th, 2006, 09:35 PM
#5
Thread Starter
Hyperactive Member
Re: Active X Control
Sorry for the stupid question... but you want me to create a project, add the UserControl, then paste the code into UserControl1 and then use a UserControl1.Show command to show the usercontrol???
Hey... If you found this post helpful please rate it.

-
Dec 6th, 2006, 10:59 PM
#6
Re: Active X Control
I just made a sample for demonstration purposes so that you can see how it works 
So all you need to do:
- Start a new normal project
- Add empty usercontrol
- Change AutoRedraw = True, BackStyle = Transparent and FillStyle = Solid
- Paste the usercontrol code and close the usercontrol
- Now put a command button or any other control on the form
- Put the usercontrol on the form on top of the command button
- You can see the effect
-
Dec 7th, 2006, 08:10 PM
#7
Thread Starter
Hyperactive Member
Re: Active X Control
Well I am getting an error: "Client site not available"
The error is occuring with the following line:
VB Code:
DrawArc UserControl.hdc, UserControl.ScaleWidth \ 2, UserControl.ScaleHeight \ 2, 0, 360, intMinSize
The error occurs when I try to add the UserControl to the form.
Khanjan
Last edited by khanjan_a2k; Dec 7th, 2006 at 08:20 PM.
Hey... If you found this post helpful please rate it.

-
Dec 7th, 2006, 09:37 PM
#8
Re: Active X Control
Humm, probably my mistake, remove code from UserControl_InitProperties.
-
Dec 7th, 2006, 10:02 PM
#9
Thread Starter
Hyperactive Member
Re: Active X Control
Oh sorry about that, I realized that I hadn't closed the designer window... Its not your fault.. By the way, umm... well the thing is that I want to detect the mouse movement over this control and whether it is clockwise or not. To do this, I need the circle to be divided into two halves, so is there any way I could actually find out about the clockwise or counterclockwise movement, or is there a way to make a semi-circle with this...? Sorry I didn't specify this earlier...
Hey... If you found this post helpful please rate it.

-
Dec 8th, 2006, 01:57 AM
#10
Re: Active X Control
If you only need two halves, then your job is really easy: just check if X or Y is bigger than half in MouseMove. As for clockwise and counterclockwise, you can see what the angle is from the midpoint. You should be able to find a lot of examples over here for calculating angles. Just have one extra variable that holds information about old angle and compare it to the new angle value to know if last movement has been clockwise or counterclockwise.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|