Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

i'm not lazy i'm just resting before i get tired.
  • *Gurus*
Posted

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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

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

i'm not lazy i'm just resting before i get tired.
Posted

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

i'm not lazy i'm just resting before i get tired.
  • *Gurus*
Posted

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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

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

i'm not lazy i'm just resting before i get tired.
  • *Gurus*
Posted

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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

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

i'm not lazy i'm just resting before i get tired.
  • *Gurus*
Posted

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 :)

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted
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)
i'm not lazy i'm just resting before i get tired.
Posted

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

Posted

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

 

thanks

i'm not lazy i'm just resting before i get tired.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...