//声明: CreatePen( Style, Width: Integer; {样式与笔宽} Color: COLORREF {颜色} ): HPEN; {返回笔句柄} //Style 参数可选值: PS_SOLID = 0; {实线} PS_DASH = 1; {段线; 要求笔宽<=1} PS_DOT = 2; {点线; 要求笔宽<=1} PS_DASHDOT = 3; {线、点; 要求笔宽<=1} PS_DASHDOTDOT = 4; {线、点、点; 要求笔宽<=1} PS_NULL = 5; {不可见} PS_INSIDEFRAME = 6; {实线; 但笔宽是向里扩展}
//举例: procedure TForm1.FormPaint(Sender: TObject); var PenStyle: Integer; {Pen 样式} PenHandle: HPEN; {Pen 句柄} begin PenStyle := RadioGroup1.ItemIndex; PenHandle := CreatePen(PenStyle, 1, clRed); Canvas.Pen.Handle := PenHandle; Rectangle(Canvas.Handle, 20, 20, 96,160); DeleteObject(PenHandle); end; procedure TForm1.RadioGroup1Click(Sender: TObject); begin Self.Refresh; end;
//效果图:
//测试 PS_SOLID 与 PS_INSIDEFRAME 的区别 procedure TForm1.FormPaint(Sender: TObject); var PenHandle: HPEN; begin PenHandle := CreatePen(PS_SOLID, 20, clRed); Canvas.Pen.Handle := PenHandle; Rectangle(Canvas.Handle, 20, 20, 96,132); PenHandle := CreatePen(PS_INSIDEFRAME, 20, clRed); Canvas.Pen.Handle := PenHandle; Rectangle(Canvas.Handle, 120, 20, 196,132); PenHandle := CreatePen(PS_SOLID, 1, clRed); Canvas.Pen.Handle := PenHandle; Rectangle(Canvas.Handle, 220, 20, 296,132); DeleteObject(PenHandle); end;
//效果图: