Transparent Graphic on top

bpayne111

Well-known member
Joined
Feb 28, 2003
Messages
326
Location
BFE
im writing a chess program.
when a user grabs a piece, id like to clear that picturebox and draw the piece on the cursors location with transparent borders (so its not a big square)

there are many options here

1. Convert bitmap to cursor or vice-versa
2. Draw Drawing.Graphics object on the form
*ive done this but i can not get the image on TOP!!!
3. make the background of a picturebox actually transparent
*even setting it in code like so doesnt work
picturebox1.backcolor = Form1.TransparencyKey

if anyone could help me accomplish any ONE of these 3 please help. i cant believe this is so difficult

reply in email if possible
bpayne113@aol.com
 
Its difficult because windows are rectangles, purely and simply. You can fake limited transparency but thats just the way it is. You have also made life more difficult for yourself (yet easier in another respect) by using pictureboxes. If you were doing all your drawing manually in the Paint event, this would not be a problem as you could draw with transparency just fine.

If I had to recommend something, it would be that you do all your drawing in the Paint event and dont rely on pictureboxes to display graphics.
 
yes i was aware of that... ive tried using a graphic object but i cannot get it to be on top of other controls on the form.

is thier a way to control what layer the graphic is drawn?

thanks for the reply
 
why not use a panel and override the paint function of that to draw you board etc then you can set the Z-Order whenever you like

Andy
 
well i considered that but it doesnt gain me anything, in the fact that i still have my transparency issue and my grahpics are still on the bottom (if i draw them that way)
also... do you know how to change z-order in a .NET form?
ive been lookign for ways to do this but it doesnt seem as easy as the old days (pre .NET :( )


a true gem would be converting a .cur file to a .bmp during runtime... id be glad to see that one day

thanks for the help
 
Well, it *does* gain you something. You shouldnt be using pictureboxes to display graphics for a game. There is no way of drawing on a different "layer" because they are all different windows.

The solution is to do all your graphics painting on the forms surface, eliminating different windows and allowing you to do effects from transparency to transculency as you wish. I can see no other way of achieving what you want.
 
yes i agree now, i was at work thinking about it at work today and decided it would be very easy to draw the board and add the events with all graphics objects...
However this brings a new questions to mind due to the fact im fairly inexperienced in graphics...

Assuming ive drawn the board and the pieces inside each square.
The user clicks and holds the mouse on a piece (mouse down pickup, mouse up drop the piece). once the piece is grabbed i would hide the cursor.
When i redraw the piece moving on the board will i have to redraw over the area where the piece previously was to hide it?
Will this be a difficult task if so?
Will the graphics be jumpy?

Sorry to throw so many questions in at once, i would just like to get this part over with so i may get to the parts im truly interested in.

thanks for the help
 
The idea of doing your graphics manually means that whenever anything changes, you redraw everything. This may sound like a big deal but it really isnt. Putting all your drawing code in to one place (the Paint event of the form) gains you some performance benefits.

Whenever something changes and you need to redraw, just call the Invalidate() method of the Form and it will raise its Paint event next time its idle. As far as flickering is concerned, since youre doing all painting in the Paint event you can take advantage of Double Buffering to eliminate it. Look up the SetStyle function for how to do this.
 
being that my board will be pure graphics and not a bunch of windows... will this make the painting quicker?

im gonna get started on it soon thanks for all your help

i would have started already but this site is so cool i can pull myself away
 
They wouldnt make it more accurate, and if they made it any faster the difference would be negligible. I cant see a use for clipping regions with what youre doing, unless you really do need to restrict your drawing to one part of the form.

The answer to your previous question is yes, it should make your drawing quicker, although you probably wont notice it as what youre doing wont be taxing the CPU much :)
 
thanks, im working on it as we speak... by the end of the night i should have put it together and found my problems (im hoping i dont have any lol but when does that ever happen)
 
the program that i am working on now has different graphical object over a complete screen. Anytime an item is "mouse-over", I only redraw that region, dont know if it is just me but I get full cpu usage when i invalidate() in the paint event even when using double buffereing.. you can do this by using invalidate(regoin) - this made an enormous difference in speed and cpu usage. Use seperate regions for your chess pieces and just redraw the one that is being moved at the new mouse location.

LiQuiD8
 
i checked my cpu usage and noticed no problems so im just gonna be happy with what i have for now

thanks
 
Back
Top