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

293

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

rectangle = new Rectangle(100, 170, 220, 120);

}

private void HitTesting_Paint(object sender,

System.Windows.Forms.PaintEventArgs e) {

Graphics g = e.Graphics;

// Vẽ shape dựa trên phần chọn hiện tại.

if (inPath) {

g.FillPath(highlightBrush, path);

g.FillRectangle(defaultBrush, rectangle);

}else if (inRectangle) {

g.FillRectangle(highlightBrush, rectangle);

g.FillPath(defaultBrush, path);

}else {

g.FillPath(defaultBrush, path);

g.FillRectangle(defaultBrush, rectangle);

}

g.DrawPath(Pens.Black, path);

g.DrawRectangle(Pens.Black, rectangle);

}

private void HitTesting_MouseMove(object sender,

System.Windows.Forms.MouseEventArgs e) {

Graphics g = this.CreateGraphics();

// Thực hiện "hit testing" với hình chữ nhật.

if (rectangle.Contains(e.X, e.Y)) {

if (!inRectangle) {