using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void DrawRectangle()
{
using (Graphics g = this.CreateGraphics())
using (Pen p = new Pen(Color.Black))
using (SolidBrush b = new SolidBrush(Color.LightBlue))
{
Rectangle rec = new Rectangle(20, 20, 300, 300);
p.Width = 10;
p.DashStyle = DashStyle.Solid;
g.DrawRectangle(p, rec);
g.FillRectangle(b, rec);
}
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
DrawRectangle();
}
}
}
文章內注意事項
沒有留言:
張貼留言