#Color class 배열을 이용한 다양한 색상나타내기
#Color class 배열을 이용한 다양한 색상나타내기
#현재 Form에 대한 this 핸들얻기
#현재 Form에 대한 this 핸들얻기
#Color 배열(140개)
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Windows.Input;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Drawing2D;
class Program : Form
{
private const int WM_KEYDOWN = 0x0100;
private const int WM_PAINT = 0x000F;
private const int WM_CREATE = 0x0001;
static Graphics graphics;
static Font font;
static Color [] fogarr = new Color[140]; //배열선언
static int toggle=0;
static int ____index=0;
static Program fi;
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Program());
}
static void __time_tick(object sender, ElapsedEventArgs e)
{
for (int h = 0; h <= 52; h++)
{
HatchStyle hs = (HatchStyle)h;
Brush hb = new HatchBrush(hs, fogarr[____index % 140]);
graphics.FillRectangle(hb, new Rectangle((h/26)*250, (h%26)*20, 50, 20));
graphics.DrawString(hs.ToString(), font, Brushes.DarkGreen, (h/26)*250+50, (h%26)*20);
}
fi.Text = fogarr[____index % 140].ToString();
____index++;
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
switch(m.Msg)
{
case WM_PAINT:
if(toggle==0)
{
this.Size = new Size(800,600);
this.Text = "HatchStyle Window Information";
graphics = this.CreateGraphics();
font = new Font("고딕", 12, FontStyle.Bold);
toggle=100;
}
break;
case WM_CREATE :
fi = new Program();
fi = this;
fogarr[0]= Color.FromArgb(240,248,255); //초기화
fogarr[1]= Color.FromArgb(255,160,122);
fogarr[2]= Color.FromArgb(250,235,215);
fogarr[3]= Color.FromArgb(32,178,170);
fogarr[4]= Color.FromArgb(0,255,255);
fogarr[5]= Color.FromArgb(135,206,250);
/*
,, 자세한 Color.FromArgb List는 c#강의리스트에 올려놓았습니다. 참고부탁드려요.^
*/
fogarr[134]= Color.FromArgb(144,238,144);
fogarr[135]= Color.FromArgb(245,245,245);
fogarr[136]= Color.FromArgb(211,211,211);
fogarr[137]= Color.FromArgb(255,255,0);
fogarr[138]= Color.FromArgb(255,182,193);
fogarr[139]= Color.FromArgb(154,205,50);
break;
case WM_KEYDOWN :
Keys keyCode = (Keys)m.WParam & Keys.KeyCode;
if(keyCode.ToString() == "F1")
{
tm = new System.Timers.Timer();
tm.Interval=100;
tm.Elapsed += new ElapsedEventHandler(__time_tick);
tm.Start();
}
else if(keyCode.ToString() == "F2")
{
if(tm != null) //예외 사항체크
{
tm.Stop();
tm.Elapsed -= __time_tick;
} }
else
{
for (int h = 0; h <= 52; h++)
{
HatchStyle hs = (HatchStyle)h;
Brush hb = new HatchBrush(hs, fogarr[____index % 140]);
graphics.FillRectangle(hb, new Rectangle((h/26)*250, (h%26)*20, 50, 20));
graphics.DrawString(hs.ToString(), font, Brushes.DarkGreen, (h/26)*250+50, (h%26)*20);
}
this.Text = fogarr[____index % 140].ToString();
____index++;
break;
}//end if else
}//end of switch
}//end of method
}//end of class
'c# 언어' 카테고리의 다른 글
Redis Server를 이용한 데이타 저장(Key,Value)과 불러오기(Key) (0) | 2021.07.13 |
---|---|
Color.FromArgb List (0) | 2021.07.09 |
컨트롤에 포커스가 자동으로 안갈 때 (0) | 2021.07.06 |
Tris Form Game by console base(HatchStyle 적용) (0) | 2021.07.06 |
Graphics graphics = CreateGraphics(); (0) | 2021.07.05 |