怎么来改变程序中的按钮的样式!比如把常规的方形的改为椭圆的!还就是改变按钮的颜色?比如把speedbutton原来的方形该为椭圆形的UP有分
解决方案 »
- 比较有意思的问题:如何获取另外的 Delphi 程序的某个变量的地址
- 问form1:=Tform1.create(application);和application.createform(Tform1,form1);区别
- web程序开发的问题
- 一段代码,请高手来看看有什么错误没?####问题解决就给分####
- 关于ListBox的问题
- tbitmap与hbitmap有什么区别,现在我想把tbitmap转换成hbitmap,如何做呢?
- 各位,帮我提供吃饭的地方吧!
- 哪位兄弟提示一下:点关闭按钮时出错,打开窗口时,直接关闭窗口也出错.
- 串口通信中CreateFile的问题,送20分!
- [李维文章推荐]delphi原子世界(2)
- 散分 : 庆贺-误删数据 恢复成功
- 讨论短信技术,知道的发表下,不知道的来顶一下!
函数声明分别是:
HRGN CreateRoundRectRgn( int nLeftRect, // x-coordinate of the region's upper-left corner
int nTopRect, // y-coordinate of the region's upper-left corner
int nRightRect, // x-coordinate of the region's lower-right corner
int nBottomRect, // y-coordinate of the region's lower-right corner
int nWidthEllipse, // height of ellipse for rounded corners
int nHeightEllipse // width of ellipse for rounded corners
);int SetWindowRgn( HWND hWnd, // handle to window whose window region is to be set
HRGN hRgn, // handle to region
BOOL bRedraw // window redraw flag
);要在 uses 中使用 shellapi.pas,不然就不好用了。函数的具体的意思可以在SDK中找到。这里就不多说了。
下面是一个例子//函数
procedure RecttoRoundRect(Button:TButton);
var
myRgn:hrgn;
HwndButton:hwnd;
begin
HwndButton:=Button.Handle;
myRgn:=CreateRoundRectRgn(0,0,Button.Width,Button.Height,Button.Height,Button.Width);
setwindowrgn(HwndButton,myRgn,true);
end;//事件
procedure TForm1.Button1Click(Sender: TObject);
begin
RecttoRoundRect(Button1);
end;
函数声明分别是:
HRGN CreateRoundRectRgn( int nLeftRect, // x-coordinate of the region's upper-left corner
int nTopRect, // y-coordinate of the region's upper-left corner
int nRightRect, // x-coordinate of the region's lower-right corner
int nBottomRect, // y-coordinate of the region's lower-right corner
int nWidthEllipse, // height of ellipse for rounded corners
int nHeightEllipse // width of ellipse for rounded corners
);int SetWindowRgn( HWND hWnd, // handle to window whose window region is to be set
HRGN hRgn, // handle to region
BOOL bRedraw // window redraw flag
);要在 uses 中使用 shellapi.pas,不然就不好用了。函数的具体的意思可以在SDK中找到。这里就不多说了。
下面是一个例子//函数
procedure RecttoRoundRect(Button:TButton);
var
myRgn:hrgn;
HwndButton:hwnd;
begin
HwndButton:=Button.Handle;
myRgn:=CreateRoundRectRgn(0,0,Button.Width,Button.Height,Button.Height,Button.Width);
setwindowrgn(HwndButton,myRgn,true);
end;//事件
procedure TForm1.Button1Click(Sender: TObject);
begin
RecttoRoundRect(Button1);
end;另外通过这种方法还可以实现不规则窗体等的一系列的问题。不知道你知不知道桌面动画?其实他就是这么实现的。如果有什么问题可以联系我,而且我也有一个桌面动画可以给你。E-mail:[email protected]
可以写一个组件 以后自己用
加入下面的代码:unit RoundButton;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls, ExtCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Panel1: TPanel;
procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Panel1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
LastY, LastX : Integer;
RegStr : TAtom;
implementation{$R *.DFM}
procedure DrawDownButton(Btnhandle : Hwnd; bDown : boolean);
Const
Border_Width = 5;
var
Rgn : HRGN;
R : TRect;
DC : HDC;
hNewPen : HPen;
begin
windows.GetClientRect(Btnhandle,r);
Rgn := CreateEllipticRgn(0,0,r.right,r.bottom);
SetWindowRgn(Btnhandle,Rgn,True);
DeleteObject(Rgn);
SetWindowText(BtnHandle,'NewButton1');
InvalidateRect(Btnhandle,nil,true);
UpdateWindow(Btnhandle);
DC := GetWindowDC(Btnhandle);
if bDown then
hNewPen := CreatePen(PS_SOLID,Border_Width,clSilver)//clWhite)
else
hNewPen := CreatePen(PS_SOLID,Border_Width,clBlack);
SelectObject(Dc,hNewPen);
Arc(DC,R.Left-Border_Width,R.Top-Border_Width,R.Right-Border_Width,
R.Bottom-Border_Width,R.Left-Border_Width,R.Bottom-Border_Width,
R.Right-Border_Width,r.Top-Border_Width);
Arc(DC,R.Left,R.Top,R.Right,R.Bottom,R.Left,R.Bottom,R.Right,r.Top);
if bDown then
hNewPen := CreatePen(PS_SOLID,Border_Width,clBlack)
else
hNewPen := CreatePen(PS_SOLID,Border_Width,clSilver);
SelectObject(Dc,hNewPen);
Arc(DC,R.Left,R.Top,R.Right,R.Bottom,R.Right,R.Top,R.Left,r.Bottom);
DeleteObject(hNewPen);
end;procedure TForm1.Button1Click(Sender: TObject);
begin
DrawDownButton(Panel1.handle,false);
end;
procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
DrawDownButton(Panel1.handle,True);
end;procedure TForm1.Panel1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
DrawDownButton(Panel1.handle,False);
end;