とりあえず、それっぽく動いてるような気がしたので、回答として書いておきます。
Windowsフォームアプリケーションで、ゲームを作るのが主な目的なら、「C# Windows Forms game」等で検索すると良いと思います。
PictureBox的なオブジェクトをどうしても使いたい場合(重い)
C#
1 using System ;
2 using System . Collections . Generic ;
3 using System . ComponentModel ;
4 using System . Data ;
5 using System . Drawing ;
6 using System . Linq ;
7 using System . Runtime . InteropServices ;
8 using System . Text ;
9 using System . Threading . Tasks ;
10 using System . Windows . Forms ;
11
12 namespace TeraPNGTransparent {
13 public partial class Form1 : Form {
14
15 PictureBoxEx [ ] pictureBoxs ;
16 PictureBoxEx pictureBoxN ;
17
18 public Form1 ( ) {
19 InitializeComponent ( ) ;
20
21 this . BackColor = Color . Red ;
22 this . MouseDown += ( s , e ) = > { //左右クリックで移動
23 if ( e . Button == MouseButtons . Left ) pictureBoxN . Left += 50 ;
24 else pictureBoxN . Left -= 50 ;
25 } ;
26
27 pictureBoxs = new PictureBoxEx [ 5 ] ; //3個程度でも結構重い
28
29 for ( int i = 0 ; i < pictureBoxs . Length ; i ++ ) {
30 pictureBoxs [ i ] = new PictureBoxEx ( ) ;
31 pictureBoxs [ i ] . Location = new Point ( 50 * i , 0 ) ;
32 pictureBoxs [ i ] . Size = new Size ( 257 , 300 ) ; //画像と同じサイズ(じゃなくても良い)
33 pictureBoxs [ i ] . ImageLocation = @ "aaa.png" ;
34 pictureBoxs [ i ] . BackColor = Color . Transparent ;
35 pictureBoxs [ i ] . Name = "pictureBox" + ( i + 1 ) ;
36 }
37
38 pictureBoxN = new PictureBoxEx ( ) ;
39 pictureBoxN . Location = new Point ( 70 , 70 ) ;
40 pictureBoxN . Size = new Size ( 197 , 300 ) ; //画像と同じサイズ(じゃなくても良い)
41 pictureBoxN . ImageLocation = @ "bbb.png" ;
42 pictureBoxN . BackColor = Color . Transparent ;
43 pictureBoxN . Name = "pictureBoxN" ;
44
45 foreach ( var px in pictureBoxs ) this . Controls . Add ( px ) ;
46 this . Controls . Add ( pictureBoxN ) ; //先に追加した方が上になる
47 }
48 }
49
50
51 public class PictureBoxEx : PictureBox {
52 protected override void OnMove ( EventArgs e ) {
53 base . OnMove ( e ) ;
54 if ( Parent != null ) {
55 Parent . Invalidate ( ) ;
56 }
57 }
58 //https://stackoverflow.com/questions/36710701/make-picture-boxes-transparent-each-overlapping-the-other-with-a-corner
59 protected override void OnPaintBackground ( PaintEventArgs pe ) {
60 base . OnPaintBackground ( pe ) ;
61 Graphics g = pe . Graphics ;
62 if ( this . Parent != null ) {
63 var index = Parent . Controls . GetChildIndex ( this ) ;
64 for ( var i = Parent . Controls . Count - 1 ; i > index ; i -- ) {
65 var c = Parent . Controls [ i ] ;
66 if ( c . Bounds . IntersectsWith ( Bounds ) && c . Visible ) {
67 using ( var bmp = new Bitmap ( c . Width , c . Height , g ) ) {
68 c . DrawToBitmap ( bmp , c . ClientRectangle ) ; //これを使うとOnPaintBackgroundが呼ばれる。困る。
69 g . DrawImageUnscaled ( bmp , new Point ( c . Left - Left , c . Top - Top ) ) ;
70 }
71 }
72 }
73 }
74 }
75 }
76 }
Formに描画する場合
C#
1 using System ;
2 using System . Collections . Generic ;
3 using System . ComponentModel ;
4 using System . Data ;
5 using System . Drawing ;
6 using System . Linq ;
7 using System . Text ;
8 using System . Threading . Tasks ;
9 using System . Windows . Forms ;
10
11 namespace TeraPNGTransparent2 {
12 public partial class Form1 : Form {
13 Point [ ] picturePoss ;
14 Point picturePosN ;
15 Bitmap [ ] pictures ;
16 Bitmap pictureN ;
17
18 public Form1 ( ) {
19 InitializeComponent ( ) ;
20
21 this . BackColor = Color . Red ;
22 this . DoubleBuffered = true ;
23 this . MouseDown += ( s , e ) = > { //左右クリックで移動
24 if ( e . Button == MouseButtons . Left ) picturePosN . X += 50 ;
25 else picturePosN . X -= 50 ;
26 Invalidate ( ) ; //再描画
27 } ;
28 this . Paint += Form1_Paint ;
29 Graphics g = this . CreateGraphics ( ) ;
30
31 picturePoss = new Point [ 5 ] ;
32 pictures = new Bitmap [ picturePoss . Length ] ;
33 for ( int i = 0 ; i < picturePoss . Length ; i ++ ) {
34 picturePoss [ i ] = new Point ( 50 * i , 0 ) ;
35 pictures [ i ] = new Bitmap ( @ "aaa.png" ) ;
36 pictures [ i ] . SetResolution ( g . DpiX , g . DpiY ) ; //解像度が違う場合必要
37 }
38 picturePosN = new Point ( 70 , 70 ) ;
39 pictureN = new Bitmap ( @ "bbb.png" ) ;
40 pictureN . SetResolution ( g . DpiX , g . DpiY ) ; //解像度が違う場合必要
41 }
42
43 private void Form1_Paint ( object sender , PaintEventArgs e ) {
44 var g = e . Graphics ;
45
46 g . DrawImageUnscaled ( pictureN , new Rectangle ( picturePosN , pictureN . Size ) ) ;
47
48 for ( int i = picturePoss . Length - 1 ; i >= 0 ; i -- ) g . DrawImageUnscaled ( pictures [ i ] , new Rectangle ( picturePoss [ i ] , pictures [ i ] . Size ) ) ;
49 }
50 }
51 }
52