1. 使控件产生圆角的方法(包括Tform)
procedure TfrmMessageDlg.SetBorder(AControl: TWinControl);
const
ConRound = 5;
var
LHrgn: HRGN;
begin
LHrgn := 0;
GetWindowRgn(AControl.Handle, LHrgn);
DeleteObject(LHrgn);
LHrgn := CreateRoundRectRgn(0, 0, AControl.Width, AControl.Height, ConRound, ConRound);
SetWindowRgn(AControl.Handle, LHrgn, True);
end;
procedure TfrmMessageDlg.FormCreate(Sender: TObject);
begin
pnlClient.Width := self.Width-2;
pnlClient.Height := Self.Height -2;
SetBorder(Self);
SetBorder(pnlClient);
end;
设置form的Color为边框颜色,设置pnlClient设置Color为界面颜色
2. 设置非标准窗体标题的panel响应移动事件
procedure TfrmMessageDlg.FormCreate(Sender: TObject);
begin
SetWindowLong(Self.Handle,GWL_STYLE,GetWindowLong(Self.Handle,GWL_STYLE) and not WS_CAPTION);
Height := ClientHeight;
end;
procedure TfrmMessageDlg.pnl4MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
(Self as TWinControl).Perform(WM_SYSCOMMAND,ConDragMove,0);
end;
3. 减少窗体上控件移动闪烁的问题可以用DoubleBuffered=true来解决即,是防闪烁,二还可以提高点效率。
一、CREATE BITMAP OR DC BUFFER
二、DRAW ON BITMAP
三、BITBLT BITMAP ON YOUR WINDOW。
4. 背景透明的图片问题
delphi7下只能用24bit的图片(即没有alpha通道的图片),要背景透明就只能TImage.Transparent := True;
delphi2010就可以支持32bit的图片了,启用alpha通道Image3.Transparent := False;
Image3.Picture.Bitmap.AlphaFormat := afPremultiplied;
5. 渐进色的画法
AHeight: Integer; AFColor, ATColor: TColor;ADirection: Byte);
//ADirection: 0:从左到右 1:从上到下
var
LBmp: TBitmap;
P: PByteArray;
I, J, LFR, LFG, LFB, LTR, LTB, LTG,LR,LB,LG: Integer;
begin
LBmp := TBitmap.Create;
try
LBmp.PixelFormat := pf24bit;
LBmp.Width := AWidth;
LBmp.Height := AHeight;
LFR := GetRValue(ColorToRGB(AFColor));
LFB := GetBValue(ColorToRGB(AFColor));
LFG := GetGValue(ColorToRGB(AFColor));
LTR := GetRValue(ColorToRGB(ATColor));
LTB := GetBValue(ColorToRGB(ATColor));
LTG := GetGValue(ColorToRGB(ATColor));
for I := 0 to LBmp.Height - 1 do
begin
P := LBmp.ScanLine[I];
case ADirection of
0:for J := 0 to LBmp.Width - 1 do
begin
p[J * 3] := LTB + (AWidth - J) * (LFB - LTB) div AWidth;
p[J * 3 + 1] := LTG + (AWidth - J) * (LFG - LTG) div AWidth;
p[J * 3 + 2] := LTR + (AWidth - J) * (LFR - LTR) div AWidth;
end;
1:
begin
LR := LTR + (AHeight - I) * (LFR - LTR) div AHeight;
LB := LTB + (AHeight - I) * (LFB - LTB) div AHeight;
LG := LTG + (AHeight - I) * (LFG - LTG) div AHeight;
for J := 0 to LBmp.Width - 1 do
begin
p[J * 3] := LB;
p[J * 3 + 1] := LG;
p[J * 3 + 2] := LR;
end;
end;
end;
end;
//将缓冲区复制到目标上
//pnlContent.Canvas.Draw(0,0,Lbmp);
BitBlt(ACanvas.Handle,ALeft, ATop, AWidth, AHeight, LBmp.Canvas.Handle, 0,0, SRCCOPY);
finally
FreeAndNil(LBmp);
end;
end;
6. 输出字符的时候设置背景透明:
SetBkMode(ACanvas.Handle,TRANSPARENT);
ACanvas.TextOut(ARect.Left,ARect.Top,AText)