Results 1 to 2 of 2

Thread: ReDraw UserControl

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2005
    Location
    Toronto, Canada
    Posts
    357

    ReDraw UserControl

    I have a user control, but I'd like to change its back color during runtime from another form... How do I do that?

    The code I am using for the usercontrol

    VB Code:
    1. 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
    2. 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
    3.  
    4. 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)
    5.     Dim xs As Integer, ys As Integer, xe As Integer, ye As Integer
    6.     Dim sat As Integer
    7.     sat = (StartAngle - 90) Mod 360
    8.     If (StartAngle >= 360) And (sat = 0) Then
    9.         sat = 360
    10.     End If
    11.     xs = Int(X - (radius * Sin((sat / 180) * 3.14159267)))
    12.     ys = Int(Y - (radius * Cos((sat / 180) * 3.14159267)))
    13.     sat = (EndAngle - 90) Mod 360
    14.     If (EndAngle >= 360) And (sat = 0) Then
    15.         sat = 360
    16.     End If
    17.     xe = Int(X - (radius * Sin((sat / 180) * 3.14159267)))
    18.     ye = Int(Y - (radius * Cos((sat / 180) * 3.14159267)))
    19.     If Abs(EndAngle - StartAngle) < 360 Then
    20.         Arc hdc, X - radius, Y - radius, X + radius, Y + radius, xs, ys, xe, ye
    21.     Else
    22. : Ellipse hdc, X - radius, Y - radius, X + radius, Y + radius
    23.     End If
    24. End Sub
    25.  
    26. Private Sub UserControl_Initialize()
    27.     UserControl.ScaleMode = vbPixels
    28. End Sub
    29.  
    30. Private Sub UserControl_InitProperties()
    31.     UserControl_Resize
    32. End Sub
    33.  
    34. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
    35.     UserControl_Resize
    36. End Sub
    37.  
    38. Private Sub UserControl_Resize()
    39.     Dim intMinSize As Integer
    40.     UserControl.BackColor = UserControl.MaskColor
    41.     UserControl.FillColor = lngColor 'strClickColor
    42.     If UserControl.ScaleWidth <= UserControl.ScaleHeight Then
    43.         intMinSize = UserControl.ScaleWidth \ 2
    44.     Else
    45.         intMinSize = UserControl.ScaleHeight \ 2
    46.     End If
    47.     DrawArc UserControl.hdc, UserControl.ScaleWidth \ 2, UserControl.ScaleHeight \ 2, 0, 360, intMinSize
    48.     UserControl.FillColor = UserControl.MaskColor
    49.     DrawArc UserControl.hdc, UserControl.ScaleWidth \ 2, UserControl.ScaleHeight \ 2, 0, 360, intMinSize \ 2
    50.     Set UserControl.MaskPicture = UserControl.Image
    51.     UserControl.BackColor = lngColor 'strClickColor
    52. End Sub

    The usercontrol is supposed to be a clickwheel
    Hey... If you found this post helpful please rate it.

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: ReDraw UserControl

    Add a public property to the UserControl that maps to the UserControl.BackColor property. The following was generated by the UserControl
    Interface Wizard.

    VB Code:
    1. 'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
    2. 'MappingInfo=UserControl,UserControl,-1,BackColor
    3. Public Property Get BackColor() As OLE_COLOR
    4.     BackColor = UserControl.BackColor
    5. End Property
    6.  
    7. Public Property Let BackColor(ByVal New_BackColor As OLE_COLOR)
    8.     UserControl.BackColor() = New_BackColor
    9.     PropertyChanged "BackColor"
    10. End Property
    11.  
    12. 'Load property values from storage
    13. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
    14.     UserControl.BackColor = PropBag.ReadProperty("BackColor", &H8000000F)
    15. End Sub
    16.  
    17. 'Write property values to storage
    18. Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
    19.     Call PropBag.WriteProperty("BackColor", UserControl.BackColor, &H8000000F)
    20. End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width