请问怎样改变Edit和Memo这类的控件的边框颜色,Ctrl3D=false? ( 积分: 40 )

  • 主题发起人 主题发起人 hjp0214
  • 开始时间 开始时间
H

hjp0214

Unregistered / Unconfirmed
GUEST, unregistred user!
就是设置控件为平面(Ctrl3D=false)的时候,边框颜色是黑色的,我想改成其他颜色的,谢谢!
 
就是设置控件为平面(Ctrl3D=false)的时候,边框颜色是黑色的,我想改成其他颜色的,谢谢!
 
TXXEdit = class(TEdit)
private
FBorderColor: TColor;
procedure ReDrawBorder;
procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
procedure SetBorderColor(const Value: TColor);
public
constructor Create(AOwner: TComponent); override;
published
property BorderColor: TColor read FBorderColor write SetBorderColor
default BORDER_COLOR;
end;


{ TXXEdit }

constructor TXXEdit.Create(AOwner: TComponent);
begin
inherited;
FBorderColor := BORDER_COLOR;
ParentCtl3D := False;
Ctl3D := False;
end;

procedure TXXEdit.ReDrawBorder;
var
DC: HDC;
Rect: TRect;
BorderBrush: HBRUSH;
begin
if Ctl3D or (BorderStyle = bsNone) or (FBorderColor = DEF_BORDER_COLOR) then
exit;
DC := GetWindowDC(Handle);
try
if not GetWindowRect(Handle, Rect) then
exit;
OffsetRect(Rect, -Rect.Left, -Rect.Top);
BorderBrush := CreateSolidBrush(ColorToRGB(FBorderColor));
FrameRect(DC, Rect, BorderBrush);
DeleteObject(BorderBrush);
finally
ReleaseDC(Handle, DC);
end;
end;

procedure TXXEdit.SetBorderColor(const Value: TColor);
begin
FBorderColor := Value;
if HandleAllocated then
ReDrawBorder;
end;


procedure TXXEdit.WMPaint(var Message: TWMPaint);
begin
inherited;
ReDrawBorder;
end;
//给分吧,谢谢
 
自绘,可以参考 XPMenu 的实现。
 
修改edit的borderstyle:=bsNone;然后放一个Shape控件放在edit后面,调整shape的大小刚好容纳edit,这是你只要修改shape的边框线的颜色就可以了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
764
import
I
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部