1、Tshape控件使用后鼠标的识别区域为矩形,而内部可以绘制多种形状,如何控制其识别区域呢?
在Form上放个Panel,使用CreatePolygonRgn()这个API,创建出一块多边形区域,然后调用SetWindowRgn(Panel1.Handle,hRgn{CreatePolygonRgn()的返回值},true);将Panel剪切成你想要的形状
SetWindowRgn
The SetWindowRgn function sets the window region of a window. The window region determines the area within the window where the system permits drawing. The system does not display any portion of a window that lies outside of the window region
int SetWindowRgn( HWND hWnd, // handle to window HRGN hRgn, // handle to region BOOL bRedraw // window redraw option );
2、Delphi制作“五星”不规则窗体的思路及代码
http://www.hongkevip.com/bianchengzhishi/Delphi/7907.html
3、绘制椭圆图形
unit Unit1; interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs; type TForm1 = class(TForm) procedure FormPaint(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormPaint(Sender: TObject); const n = 50; var Rgn: HRGN; x1,y1,x2,y2: Integer; begin x1 := n; y1 := n div 2; x2 := ClientWidth - n; y2 := ClientHeight - n; {建立椭圆区域} // Rgn := CreateEllipticRgn(x1, y1, x2, y2); Rgn := CreateEllipticRgnIndirect(Rect(x1,y1,x2,y2)); {目的同上一行, 函数不同} {填充区域} Canvas.Brush.Color := clSilver; Canvas.Brush.Style := bsCross; FillRgn(Canvas.Handle, Rgn, Canvas.Brush.Handle); {绘制区域边界} Canvas.Brush.Color := clRed; Canvas.Brush.Style := bsSolid; FrameRgn(Canvas.Handle, Rgn, Canvas.Brush.Handle, 2, 2); DeleteObject(Rgn); end; end.