Results 1 to 7 of 7

Thread: Difference between two shapes?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2010
    Posts
    22

    Difference between two shapes?

    Hey,
    Is there any way I can 'filter' a kind of difference between two shapes, kind of like this:
    Name:  inkscape-difference-operation-1.png
Views: 151
Size:  5.6 KB
    Thanks!

  2. #2
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: Difference between two shapes?

    For circle and 2nd square.

    MsgBox Square2.Left - (Circle1.Left + Circle1.Width)

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jun 2010
    Posts
    22

    Re: Difference between two shapes?

    Quote Originally Posted by Max187Boucher View Post
    For circle and 2nd square.

    MsgBox Square2.Left - (Circle1.Left + Circle1.Width)
    I don't know if you understand my question. What I was asking is how to replicate the effect shown in the image. How would just using a messagebox let me change the way a shape looks? I'm not looking for the difference in distance, I'm looking for a way to actually make the effect shown in the image happen.

  4. #4
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: Difference between two shapes?

    http://msdn.microsoft.com/en-us/libr...(v=vs.80).aspx

    do some research before asking easy questions
    also describe your problem more clearly next time

  5. #5
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: Difference between two shapes?

    Now I am going to post this simple solution (hopefully I won't get too much flack for it's simplicity from the REAL VB-coders out there).
    But what I did for you is simply put four shapes on a form, along with a command button. First I brought shape1 (circle) 'forward' of shape 2 (green square) using the Format option in the IDE. Then, I did the same thing with both shapes 3 and 4 (these are SOLID backgrounds/no border).
    I set the visible property for shapes 3 and 4 to false in the IDE.

    I loaded the form and you will see your green rectangle with the red circle (both with black borders) in the bottom right of the rectangle. Then, when you click the command button, it changes the fillcolor of shape1 to the same color as the form (and shapes 3 and 4), and turns the visibility of shapes 3 and 4 to true. This essentially HIDES 3/4 of the circle's border, leaving 1/4 shown 'in' the green square.

    I don't play with shapes much (which will be obvious to the experts), so I had no other clue how to put a black border around the resulting green 'shape' without doing it this way.

    Well, anyway, here is the code:

    Code:
    Private Sub Form_Load()
        Shape1.Top = 700  'circle
        Shape1.Left = 700
        Shape1.Height = 1200
        Shape1.Width = 1200
        Shape1.Shape = vbShapeCircle
        Shape1.BorderColor = vbBlack
        Shape1.FillColor = vbRed
        Shape1.FillStyle = vbSolid
        
        Shape2.Top = 0 'rectangle
        Shape2.Left = 0
        Shape2.FillColor = vbGreen
        Shape2.FillStyle = vbSolid
        Shape2.BorderColor = vbBlack
        Shape2.Height = 1400
        Shape2.Width = 1400
        
        'next two shapes simply to hide the border of the circle outside the square
        Shape3.BackColor = Form1.BackColor
        Shape3.Left = Shape2.Left + Shape2.Width
        Shape3.Top = Shape2.Top
        Shape3.Height = Shape2.Height + Shape1.Height
        Shape3.BorderStyle = vbTransparent
        
        Shape4.BackColor = Form1.BackColor
        Shape4.Top = Shape2.Top + Shape2.Height
        Shape4.Left = Shape2.Left
        Shape4.BorderStyle = vbTransparent
        Shape4.Height = Shape1.Height
        Shape4.Left = Shape4.Left
        Shape4.Width = Shape2.Width + Shape1.Width
    
    End Sub

  6. #6
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Difference between two shapes?

    Quote Originally Posted by bowiz2 View Post
    Hey,
    Is there any way I can 'filter' a kind of difference between two shapes, kind of like this:
    Name:  inkscape-difference-operation-1.png
Views: 151
Size:  5.6 KB
    Thanks!
    I do not understand the question. You need to do a better job of explaining what you want to do. Your second picture shows only the area of the square that is not overlapped by the circle which I certainly would not describe as the difference between two objects. Or are you trying to say that the red and green is one object and the green is another meaning that the difference is the circle?

    Whatever the case may be you have to give a clear description before anyone can give you the answer you seek.

  7. #7
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,176

    Re: Difference between two shapes?

    Hey DM....in post #3, he kinda did, I think:
    What I was asking is how to replicate the effect shown in the image.
    And using a simplistic approach, I did that. Working with shapes, lines, pixels, etc, is not my bag of tea....don't see too much use for that stuff in what I do. So what I posted may seem like a VB beginner's approach.

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