矢印キーでウインドウの幅と高さを変更します。
Console.WriteLine() で「出力ウインドウ」に印字します。
前田稔(Maeda Minoru)の超初心者のプログラム入門
![]()
![]()
/****************************************************/
/*★ 矢印キーで Window Size を変更する 前田 稔 ★*/
/****************************************************/
using System;
using System.Drawing;
using System.Windows.Forms;
public class MyForm : Form
{
public MyForm()
{
}
protected override void OnKeyDown(KeyEventArgs e)
{
switch(e.KeyCode)
{ case Keys.Escape:
this.Dispose();
break;
case Keys.Down:
Height += 10;
break;
case Keys.Up:
Height -= 10;
break;
case Keys.Right:
Width += 10;
break;
case Keys.Left:
Width -= 10;
break;
}
}
}
class key
{
public static void Main()
{
MyForm mf = new MyForm();
Application.Run(mf);
}
}
|
![]()
/****************************************************/
/*★ 矢印キーで Window Size を変更する 前田 稔 ★*/
/****************************************************/
using System;
using System.Drawing;
using System.Windows.Forms;
public class MyForm : Form
{
public MyForm()
{
}
protected override void OnKeyDown(KeyEventArgs e)
{
switch(e.KeyCode)
{ case Keys.Escape:
Application.Exit();
break;
case Keys.Down:
Top += 10;
break;
case Keys.Up:
Top -= 10;
break;
case Keys.Right:
Left += 10;
break;
case Keys.Left:
Left -= 10;
break;
}
}
protected override void OnMove(EventArgs e)
{
Console.WriteLine("X座標={0}, Y座標={1}, 幅={2}, 高さ={3}", Left, Top, Width, Height);
}
}
class key
{
public static void Main()
{
MyForm mf = new MyForm();
Application.Run(mf);
}
}
|
![]()