?? mainform.cs
字號:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms;
namespace UsingPen
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void MainForm_Paint(object sender, PaintEventArgs e)
{
// 四個矩形的顏色
Color[] colors = new Color[]{
Color.Red,
Color.Green,
Color.Blue,
Color.Yellow
};
// 用于計算矩形坐標的值
// initX、initY:最外面的矩形的左上角位置
// initW、initH:最外面的矩形的大小
// incr:矩形之間的距離
int initX = 10, initY = 10;
int initW = 200, initH = 150;
int incr = 20;
// 創建畫筆
Pen p = new Pen(Color.Empty);
for(int i = 0; i < 4; i++)
{
// 改變畫筆的顏色和寬度
p.Color = colors[i];
p.Width = (i + 1) * 3.0f;
// 計算當前矩形的位置和大小
int x = initX + i * incr;
int y = initY + i * incr;
int w = initW - i * incr * 2;
int h = initH - i * incr * 2;
// 繪制矩形
e.Graphics.DrawRectangle(p, x, y, w, h);
}
// 釋放畫筆
p.Dispose();
#if false
// 繪制虛線
using(Pen p2 = new Pen(Color.Black))
{
p2.DashStyle = DashStyle.Dash;
e.Graphics.DrawLine(p2, 0, 0, 200, 200);
}
#endif
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -