Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Areas under graphs and overlap areas between circles. 2

Ken01

Programmer
Aug 8, 2014
62
GB
Good Morning, I was wondering if anyone could point me in the direction of finding code that would shade in the overlap areas between circles and also the areas under and between graphs ?
 
>shade in the overlap areas between circles

VB doesn't provide built-in functions/methods to do this. The Win32 API does however. I'v e not got time to post an example just now, but will try to later on.

As for the graph stuff, I think you need to be clearer in what you are trying to achieve
 
Needs a form with a button

Rich (BB code):
Option Explicit

Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function FillRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush As Long) As Long
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long


Private Const RGN_AND = 1

Private Sub Command1_Click()
    Dim hRgn1 As Long
    Dim hRgn2 As Long
    Dim hRgnIntersect As Long
    Dim hBrush As Long
    Dim result As Long
    
    Form1.ScaleMode = vbPixels
    
    '  Our VB circles
    FillStyle = vbSolid
    FillColor = vbGreen
    Circle (200, 200), 100
    FillColor = vbRed
    Circle (350, 200), 100
    
  
    '  Now do the clever GDI stuff
    hRgnIntersect = CreateRectRgn(0, 0, 0, 0)
    hRgn1 = CreateEllipticRgn(100, 100, 300, 300)
    hRgn2 = CreateEllipticRgn(250, 100, 450, 300)
    result = CombineRgn(hRgnIntersect, hRgn1, hRgn2, RGN_AND)
    hBrush = CreateSolidBrush(RGB(255, 255, 0))
    FillRgn Form1.hdc, hRgnIntersect, hBrush

   ' Clean up
    DeleteObject hBrush
    DeleteObject hRgnIntersect
    DeleteObject hRgn2
    DeleteObject hRgn1
End Sub
 
Last edited:
Needs a form with a button

Rich (BB code):
Option Explicit

Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function CreateEllipticRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function FillRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush As Long) As Long
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long


Private Const RGN_AND = 1

Private Sub Command1_Click()
    Dim hRgn1 As Long
    Dim hRgn2 As Long
    Dim hRgnIntersect As Long
    Dim hBrush As Long
    Dim result As Long
    
    Form1.ScaleMode = vbPixels
    
    '  Our VB circles
    FillStyle = vbSolid
    FillColor = vbGreen
    Circle (200, 200), 100
    FillColor = vbRed
    Circle (350, 200), 100
    
  
    '  Now do the clever GDI stuff
    hRgnIntersect = CreateRectRgn(0, 0, 0, 0)
    hRgn1 = CreateEllipticRgn(100, 100, 300, 300)
    hRgn2 = CreateEllipticRgn(250, 100, 450, 300)
    result = CombineRgn(hRgnIntersect, hRgn1, hRgn2, RGN_AND)
    hBrush = CreateSolidBrush(RGB(255, 255, 0))
    FillRgn Form1.hdc, hRgnIntersect, hBrush

   ' Clean up
    DeleteObject hBrush
    DeleteObject hRgnIntersect
    DeleteObject hRgn2
    DeleteObject hRgn1
End Sub
Thank you very much. I will try this over the next few days when I have time.
 

Part and Inventory Search

Sponsor

Back
Top