#In Form Draw & In WndProc Event
#In Form Draw & In WndProc Event
#In Form Draw & In WndProc Event
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;
namespace ConsoleForm
{
public class ____ConsoleDraw : Form
{
private const int WM_KEYDOWN = 0x0100;
private const int WM_PAINT = 0x000F;
static int toggle=0;
static int index=0;
public ____ConsoleDraw()
{
//
}
protected override void WndProc(ref Message m) //해당 overrride 메소드에서 그래픽관련 핸들을 얻어야 합니다.
{
base.WndProc(ref m);
index++;
Console.Write("Window Message Event:" + index.ToString("000000") + "/" + m.Msg + "/");
Console.WriteLine("0x"+Convert.ToString(m.Msg, 16) + "/");
switch(m.Msg)
{
case WM_PAINT:
if(toggle==0)
{
this.Size = new Size(800,600);
this.Text = "HatchStyle Window Information";
toggle=100;
}
break;
case WM_KEYDOWN :
Console.WriteLine("WM_KEYDOWN");
if (m.Msg == WM_KEYDOWN)
{
Keys keyCode = (Keys)m.WParam & Keys.KeyCode;
switch (keyCode)
{
case Keys.F1:
case Keys.F2:
MessageBox.Show("Control.PreProcessMessage: '" +
keyCode.ToString() + "' pressed.");
break;
}
if(Keys.F1 == keyCode)
{
Application.Exit();
}
if(Keys.F2 == keyCode)
{
Console.WriteLine("F2 Key Pressed!!");
Graphics graphics = CreateGraphics();
Pen pen = new Pen(Color.Black);
graphics.DrawLine(pen,10,10,50,10);
graphics.DrawLine(pen,50,10,50,50);
graphics.Dispose(); //이 Graphics에서 사용하는 리소스를 모두 해제합니다.
}
if(Keys.F3 == keyCode)
{
Graphics graphics = CreateGraphics();
Font font = new Font("고딕", 12, FontStyle.Bold);
//1.
for (int h = 0; h <= 52; h++)
{
HatchStyle hs = (HatchStyle)h;
Brush hb = new HatchBrush(hs, Color.White);
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);
}
//2.
Brush brush = new SolidBrush(Color.Green);
graphics.FillRectangle(brush, new Rectangle(500, 20, 50, 20));
graphics.DrawString("SolidBrush - Green", font, Brushes.Green, 550, 20);
//3.
Brush tb = new TextureBrush(image);
graphics.FillRectangle(tb, new Rectangle(500, 40, 50, 20));
graphics.DrawString("TextureBrush - myimage", font, Brushes.Green, 550, 40);
}
}
break;
}
}
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new ____ConsoleDraw());
}
}//end of class
}//end of namespace
'c# 언어' 카테고리의 다른 글
WndProc(ref Message m)를 이용시에, WM_MESSAGE정의 (0) | 2021.07.01 |
---|---|
m.WParam.ToInt32()를 이용시에 VK_KEY_NUMBER정의 (0) | 2021.07.01 |
form hexa created by console(WndProc) (0) | 2021.06.24 |
SendMessage by User Forced & When F1 KeyDown, Process ex (0) | 2021.06.17 |
WndProc & Message(WM_MOVE) 예제 (0) | 2021.06.16 |