简体   繁体   中英

Animation Effects in WinForms/C#

I'm pasting an image from the game im building. the matrix of empty cells you see are made of PictureBox[][]. I wan't whenever I drop a coin to one of the columns... I want it to go down but the purple stuff will hide the falling coin and the gray color you see wont hide it. How do I make this effect? please notice that in each PictureBox control I have set the BG Image as you can see 我的游戏截图

Don't do it like that.

Create custom control. In custom control, override Paint, and then draw COIN sprite first, then draw mask over it. Be sure that you use double-buffered painting here.

It will work like a charm, trust me!

And, since you are (I gueess) building 5-in-a-row game here, your custom control will be able to paint occupied slots as well.

By designing custom control, you'll be able to hide all the animation and graphics stuff away from your main form.

I don't think it is possible like that. Controls in WinForms cannot be transparent, that is the problem

I would think in three directions:

  1. Forgetting about controls and painting everything OnPaint event of the form. It is not too complicated (well it would be more complicated to detect some mouse events like you did now, as you wouldn't know which graybox is hit, but rather just mouse coordinates)
  2. Experimenting with coin as a form (forms can be transparent)
  3. Possibly using WPF with same logic you did, as controls can be transparent there

Controls in Windows Forms can be transparent. You need to set the TransparencyKey of the Form to some color that you never plan on using (many people seem to love/hate Magenta for this), and then set the BackgroundColor of each PictureBox to the same color. The result should be a transparent PictureBox with its Image drawn over it. I'm pretty sure this won't work with the BackgroundImage property, mind you- just the Image property.

One potentially unwanted side effect of this method is that you'll be able to see whatever's behind your form (the desktop, other application windows, etc.) through the transparent places in the PictureBox.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM