event BeforeDrawPart (Part as DrawPartEnum, hDC as Long, X as Long, Y as Long, Width as Long, Height as Long, Cancel as Boolean)
Occurs just before drawing a part of the control.

 TypeDescription 
   Part as DrawPartEnum A Part being painted.  
   hDC as Long A long expression that specifies the handle of the device context where you can perform your own draw.  
   X as Long (by reference) A long expression that specifies the left coordinate of the rectangle where the paint should occur. You can change the X parameter during the handler, to define the new left coordinate for the default painting.   
   Y as Long (by reference) A long expression that specifies the top coordinate of the rectangle where the paint should occur. You can change the Y parameter during the handler, to define the new top coordinate for the default painting.  
   Width as Long (by reference) A long expression that specifies the width of the rectangle where the paint should occur. You can change the Width parameter during the handler, to define the new width for the default painting.  
   Height as Long (by reference) A long expression that specifies the height of the rectangle where the paint should occur. You can change the Height parameter during the handler, to define the new width for the default painting.  
   Cancel as Boolean (by reference) A Boolean expression that specifies whether the default painting is canceled or not    
The BeforeDrawPart and AfterDrawPart events occur when different parts of the control requires to be drawn. Use the BeforeDrawPart and AfterDrawPart events to add your custom drawing to be shown in the component. Use the BeforeDrawPart event to perform your own drawing before the default drawing, canceling the default drawing, or changing the area being assigned to the part part when painting. Use the AfterDrawPart event to perform your own drawing after default painting occurs. The /NET Assembly provides instead hDC and (X,Y,Width,Height) parameters a Graphics object and a Rectangle object, the last being passed by reference. Use the HistogramBoundsChanged event to notify your application when the left part of the histogram is resized, so inside controls must be re-positioned.

The following VB sample changes the Y and the Height parameters, and paints the "Histogram" text inside the histogram as shown bellow in the screen shot:

Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type
Private Const DT_SINGLELINE = &H20
Private Const DT_CENTER = &H1
Private Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long


Private Sub G2antt1_BeforeDrawPart(ByVal Part As EXG2ANTTLibCtl.DrawPartEnum, ByVal hdc As Long, X As Long, Y As Long, Width As Long, Height As Long, Cancel As Boolean)
    If (Part = exDrawLeftHistogram) Or (Part = exDrawRightHistogram) Then
    
        Dim h As Long
        h = 16
        
        If ((Part = exDrawRightHistogram)) Then
            Dim r As RECT
            r.Left = X + 2
            r.Right = r.Left + Width - 4
            r.Top = Y + 1
            r.Bottom = r.Top + h - 2
            
            DrawText hdc, "Histogram", 9, r, DT_SINGLELINE + DT_CENTER
        End If

        Y = Y + h
        Height = Height - h
    End If
End Sub


Send comments on this topic.
© 1999-2012 Exontrol.COM, Software. All rights reserved.