Quantcast
Channel: C#タグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 8901

C# - ちょー雑な方法でFormのアイコンを生成する (Windows)

$
0
0

画面キャプチャ

image.png

サンプルコード

usingSystem;usingSystem.Drawing;usingSystem.Windows.Forms;//using System.Runtime.InteropServices;classIconMakeTest:Form{//  class NativeMethods//  {//      [DllImport("user32.dll", CharSet = CharSet.Auto)]//      public extern static bool DestroyIcon(IntPtr handle);//  }IconMakeTest(){GetHiconExample();}staticstring[]iconDot=newstring[]{"................",".###...##...##..","..#...#..#.#..#.","..#...#....#..#.","..#...#....#..#.","..#...#....#..#.","..#...#....#..#.","..#...#....#..#.","..#...#....#..#.","..#...#....#..#.","..#...#....#..#.","..#...#....#..#.","..#...#....#..#.","..#...#..#.#..#.",".###...##...##..","................",};voidGetHiconExample(){using(Bitmapbmp=newBitmap(16,16)){using(Graphicsg=Graphics.FromImage(bmp)){g.Clear(Color.White);}for(inty=0;y<16;y++){for(intx=0;x<16;x++){if(iconDot[y][x]=='#'){bmp.SetPixel(x,y,Color.Black);}}}IntPtrHicon=bmp.GetHicon();IconnewIcon=Icon.FromHandle(Hicon);this.Icon=newIcon;//NativeMethods.DestroyIcon(newIcon.Handle);}}[STAThread]staticvoidMain(string[]args){Application.Run(newIconMakeTest());}}

参考サイト


Viewing all articles
Browse latest Browse all 8901

Trending Articles