bpayne111 Posted February 28, 2003 Posted February 28, 2003 i'm writing a chess program. when a user grabs a piece, i'd like to clear that picturebox and draw the piece on the cursors location with transparent borders (so it's 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 *i've 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 doesn't work picturebox1.backcolor = Form1.TransparencyKey if anyone could help me accomplish any ONE of these 3 please help. i can't believe this is so difficult reply in email if possible bpayne113@aol.com Quote i'm not lazy i'm just resting before i get tired.
*Gurus* divil Posted February 28, 2003 *Gurus* Posted February 28, 2003 It's difficult because windows are rectangles, purely and simply. You can fake limited transparency but that's 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 don't rely on pictureboxes to display graphics. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
bpayne111 Posted February 28, 2003 Author Posted February 28, 2003 yes i was aware of that... i've 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 Quote i'm not lazy i'm just resting before i get tired.
a_jam_sandwich Posted February 28, 2003 Posted February 28, 2003 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 Quote Code today gone tomorrow!
bpayne111 Posted February 28, 2003 Author Posted February 28, 2003 well i considered that but it doesn't 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? i've been lookign for ways to do this but it doesn't seem as easy as the old days (pre .NET :( ) a true gem would be converting a .cur file to a .bmp during runtime... i'd be glad to see that one day thanks for the help Quote i'm not lazy i'm just resting before i get tired.
*Gurus* divil Posted February 28, 2003 *Gurus* Posted February 28, 2003 Well, it *does* gain you something. You shouldn't 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 form's 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. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
bpayne111 Posted March 1, 2003 Author Posted March 1, 2003 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 i'm fairly inexperienced in graphics... Assuming i've 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 i'm truly interested in. thanks for the help Quote i'm not lazy i'm just resting before i get tired.
*Gurus* divil Posted March 1, 2003 *Gurus* Posted March 1, 2003 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 isn't. 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 it's idle. As far as flickering is concerned, since you're 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. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
bpayne111 Posted March 1, 2003 Author Posted March 1, 2003 being that my board will be pure graphics and not a bunch of windows... will this make the painting quicker? i'm 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 Quote i'm not lazy i'm just resting before i get tired.
bpayne111 Posted March 2, 2003 Author Posted March 2, 2003 would clipping regions make the drawing faster and more accurate? Quote i'm not lazy i'm just resting before i get tired.
*Gurus* divil Posted March 2, 2003 *Gurus* Posted March 2, 2003 They wouldn't make it more accurate, and if they made it any faster the difference would be negligible. I can't see a use for clipping regions with what you're 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 won't notice it as what you're doing won't be taxing the CPU much :) Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
bpayne111 Posted March 3, 2003 Author Posted March 3, 2003 thanks, i'm working on it as we speak... by the end of the night i should have put it together and found my problems (i'm hoping i don't have any lol but when does that ever happen) Quote i'm not lazy i'm just resting before i get tired.
liquid8 Posted March 4, 2003 Posted March 4, 2003 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, don't 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 Quote
bpayne111 Posted March 6, 2003 Author Posted March 6, 2003 i checked my cpu usage and noticed no problems so i'm just gonna be happy with what i have for now thanks Quote i'm not lazy i'm just resting before i get tired.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.