前田稔(Maeda Minoru)の超初心者のプログラム入門
![]()
![]()
/***************************************/
/*★ 碁盤の罫線を表示する 前田 稔 ★*/
/***************************************/
using System;
using System.Drawing;
using System.Windows.Forms;
public class MyForm : Form
{
int m_Width, m_Height;
public MyForm()
{
this.Width = 800;
this.Height = 540;
m_Width = this.Width;
m_Height = this.Height;
Paint += new PaintEventHandler(MyHandler);
}
private void MyHandler(object sender, PaintEventArgs e)
{ int ph,pw,i;
Color cor = Color.FromArgb(255, 210, 170, 50);
ph = m_Height / 21;
pw = (ph*43) / 45; //縦45:横43
this.Text = ph + " : " + pw;
Graphics g = e.Graphics;
g.FillRectangle(new SolidBrush(cor), 10, 10, m_Width - 80, m_Height - 60);
for(i=0; i<19; i++)
{
g.DrawLine(new Pen(Color.Black), 25, i * ph + 25, 18 * pw + 25, i * ph + 25);
g.DrawLine(new Pen(Color.Black), i * pw + 25, 25, i * pw + 25, 18*ph+25);
}
}
}
class Draw
{
public static void Main()
{
MyForm mf = new MyForm();
Application.Run(mf);
}
}
|
this.Width = 800;
this.Height = 540;
m_Width = this.Width;
m_Height = this.Height;
|
Color cor = Color.FromArgb(255, 210, 170, 50);
ph = m_Height / 21;
pw = (ph*43) / 45; //縦45:横43
Graphics g = e.Graphics;
g.FillRectangle(new SolidBrush(cor),10,10,m_Width-80,m_Height-60);
for(i=0; i<19; i++)
{
g.DrawLine(new Pen(Color.Black),25,i*ph+25,18*pw+25,i*ph+25);
g.DrawLine(new Pen(Color.Black),i*pw+25,25,i*pw+25,18*ph+25);
}
|
![]()
public MyForm()
{
・・・
Resize += new System.EventHandler(this.FormResize);
}
|
private void FormResize(object sender, EventArgs e)
{
m_Width = this.Width;
m_Height = this.Height;
Invalidate();
}
|
private void MyHandler(object sender, PaintEventArgs e)
{ int ph,pw,width,height,i;
Color cor = Color.FromArgb(255, 210, 170, 50);
ph = m_Height / 22;
pw = (ph*43) / 45; //縦45:横43
width = pw * 20;
height = ph * 20;
Graphics g = e.Graphics;
g.FillRectangle(new SolidBrush(cor), pw/2, ph/2, width, height);
for(i=0; i<19; i++)
{
g.DrawLine(new Pen(Color.Black), pw, (i+1) * ph, pw * 19, (i+1) * ph);
g.DrawLine(new Pen(Color.Black), (i+1) * pw, ph, (i+1) * pw, ph * 19);
}
}
|
![]()
int j, xp, yp;
yp = ph * 4;
for(i=0; i<3; i++)
{
xp = pw * 4;
for (j=0; j<3; j++)
{
g.FillEllipse(new SolidBrush(Color.Black),xp-3,yp-3,6,6);
xp += pw * 6;
}
yp+= ph*6;
}
|
![]()
[Next Chapter ↓] 碁盤に石を置く
※・ ※・