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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Painting 'Behind' Something - ie: Layers 1

Status
Not open for further replies.

T0AD

Programmer
Jun 4, 2003
73
GB
Is it possible to draw or paint behind something using GDI+? For example, if I paint a small filled circle, can I then draw a larger filled circle around it - but behind it - so that the first circle is completely visible.





There's a thin line between genius, and insanity!
 
Can you elaborate further? I'm not understanding why you wouldn't draw the larger circle first.
 
You mean like making the smaller circle container "transparent"?
 
What I'm actually trying to do is animate falling pieces. I create a graphics object, draw a filled rectangle and then several rows and columns of white-filled circles.

I want a coloured circle to be drawn in one of the top white circles and fall down through the column. If you've ever played the game Connect-4 it's exactly like that... only on-screen!

So I have three steps of the drawing part: 1. the board, 2. the white-holes, 3. the pieces, in that order.

Clearer?



There's a thin line between genius, and insanity!
 
So you are asking this question because you want it to appear as if the piece is inside the board falling, correct? You can still do this if you draw all the white circles first, then draw the board on over it later.
 
If I draw the white circles first, and then the board - the circles cant be seen as the board covers them...

There's a thin line between genius, and insanity!
 
Yeah, I forgot that the piece is inside the board. So, you could use regions (will take a long time), or you can render two bitmaps in memory. Paste this on a blank form, and put it in a button. It should work. It has a few holes, and a peice partially in one hole. You'll see what I did and can modify it:

Code:
        'Bitmap for piece
        Dim MyBitmap As New Bitmap(Me.Height, Me.Width)
        'Bitmap for board and holes
        Dim MyBitmap2 As New Bitmap(Me.Height, Me.Width)
        'Graphics for piece
        Dim MyGraphics As Graphics = Graphics.FromImage(MyBitmap)
        'Graphics for holes
        Dim MyGraphics2 As Graphics = Graphics.FromImage(MyBitmap2)
        'Board brush
        Dim MyBackBrush As New SolidBrush(Color.Yellow)
        'Transparent brush
        Dim MyHoleBrush As New SolidBrush(Color.Green)
        'Peice Brush
        Dim MyPieceBrush As New SolidBrush(Color.Red)
        'Draw Piece
        MyGraphics.FillEllipse(MyPieceBrush, 60, 25, 25, 25)
        'Draw board and holes
        MyGraphics2.FillRectangle(MyBackBrush, 0, 0, MyBitmap.Width, MyBitmap.Height)
        MyGraphics2.FillEllipse(MyHoleBrush, 10, 10, 25, 25)
        MyGraphics2.FillEllipse(MyHoleBrush, 60, 10, 25, 25)
        MyGraphics2.FillEllipse(MyHoleBrush, 110, 10, 25, 25)
        MyGraphics2.FillEllipse(MyHoleBrush, 10, 60, 25, 25)
        MyGraphics2.FillEllipse(MyHoleBrush, 60, 60, 25, 25)
        MyGraphics2.FillEllipse(MyHoleBrush, 110, 60, 25, 25)
        'Make holes transparent
        MyBitmap2.MakeTransparent(Color.Green)
        'Render piece
        Me.CreateGraphics.DrawImage(MyBitmap, 0, 0)
        'Render board
        Me.CreateGraphics.DrawImage(MyBitmap2, 0, 0)
 
Thanks RiverGuy, just what I need.

T0AD

There's a thin line between genius, and insanity!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top