CÁC GIẢI PHÁP LẬP TRÌNH C# - Trang 296

296
Chương 8: Đồ họa, đa phương tiện, và in ấn

lớp

Region

. Cuối cùng, bạn có thể gán

Region

vào thuộc tính

Form.Region

hoặc

Control.Region

.

Ví dụ dưới đây trình bày cách tạo một form có hình dáng bất thường (xem hình 8.3) bằng hai
cung tròn (hai cung này được chuyển thành một figure khép kín bằng phương thức

GraphicsPath.CloseAllFigures

).

Hình 8.3 Form không phải hình chữ nhật

using System;

using System.Windows.Forms;

using System.Drawing;

using System.Drawing.Drawing2D;

public class IrregularForm : System.Windows.Forms.Form {

private System.Windows.Forms.Button cmdClose;

private System.Windows.Forms.Label label1;

// (Bỏ qua phần mã designer.)

private void IrregularForm_Load(object sender, System.EventArgs e) {

GraphicsPath path = new GraphicsPath();

Point[] pointsA = new Point[] {new Point(0, 0),

new Point(40, 60), new Point(this.Width - 100, 10)};

path.AddCurve(pointsA);