急急!!!!!带按钮的DBEDIT控件(100分)

  • 主题发起人 主题发起人 maxim
  • 开始时间 开始时间
M

maxim

Unregistered / Unconfirmed
GUEST, unregistred user!
请各位给小弟看看,我想做个带按钮的DBEDIT编辑框,加上按钮后,按钮没法相应点击事件,请各位大侠帮忙看看。
unit MxDBEditBtn;

interface

uses
Windows, Messages, SysUtils, Classes, Controls, StdCtrls, Mask, DBCtrls,
Buttons,Forms;

type
TMxDBEditBtn = class(TDBEdit)
private
FButton: TSpeedButton;
// FOnBtnClick: TNotifyEvent;
{ Private declarations }
procedure SetEditRect;
function GetMinHeight: Integer;
procedure WMSize (var Message: TWMSize); message WM_SIZE;
// procedure WMPaste (var Message: TWMPaste); message WM_PASTE;
// procedure WMCut (var Message: TWMCut); message WM_CUT;
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner:TComponent);override;
destructor Destroy;override;
published
{ Published declarations }
property Button: TSpeedButton read FButton;
// property OnBtnClick: TNotifyEvent read FOnBtnClick write FOnBtnClick;// stored IsOnClickStored;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('MxDBTools', [TMxDBEditBtn]);
end;

{ TMxDBEditBtn }

constructor TMxDBEditBtn.Create(AOwner: TComponent);
begin
inherited;
FButton := TSpeedButton.Create (Self);
FButton.Parent := Self;
FButton.Width := 22;
FButton.Height := 20;
FButton.Visible := True;
FButton.Transparent:=True;
FButton.Caption:='...';
FButton.OnClick := OnDblClick;
// FButton.Glyph
ControlStyle := ControlStyle - [csSetCaption];
end;

destructor TMxDBEditBtn.Destroy;
begin
FButton := nil;
inherited Destroy;
end;

function TMxDBEditBtn.GetMinHeight: Integer;
var
DC: HDC;
SaveFont: HFont;
SysMetrics, Metrics: TTextMetric;
begin
DC := GetDC(0);
GetTextMetrics(DC, SysMetrics);
SaveFont := SelectObject(DC, Font.Handle);
GetTextMetrics(DC, Metrics);
SelectObject(DC, SaveFont);
ReleaseDC(0, DC);
Result := Metrics.tmHeight + 7;
end;

procedure TMxDBEditBtn.SetEditRect;
var
Loc: TRect;
begin
SendMessage(Handle, EM_GETRECT, 0, LongInt(@Loc));
if BorderStyle=bsNone then
Loc := Rect(0, 0, ClientWidth - FButton.Width - 1, ClientHeight)
else
Loc := Rect(0, 0, ClientWidth - FButton.Width - 3, ClientHeight);
SendMessage(Handle, EM_SETRECTNP, 0, LongInt(@Loc));
SendMessage(Handle, EM_GETRECT, 0, LongInt(@Loc));
end;
procedure TMxDBEditBtn.WMSize(var Message: TWMSize);
var
MinHeight: Integer;
begin
inherited;
MinHeight := GetMinHeight;
{ text edit bug: if size to less than minheight, then edit ctrl does
not display the text }
if Height < MinHeight then
Height := MinHeight
else
if FButton <> nil then
begin
if BorderStyle=bsNone then
FButton.SetBounds(Width - FButton.Width - 2, 0, FButton.Width, Height - 1)
else
FButton.SetBounds(Width - FButton.Width - 5, 0, FButton.Width, Height - 6);
SetEditRect;
end;
end;

end.
 
z自己顶!别沉下去!
 
怎么没有人理睬呀,是问题太幼稚呢还是高手在休息呀![:)]
 
FButton.OnClick := OnDblClick; ??
 
TO:hunterx1
这是我想把DBEDIT的双击事件转给按钮的Click事件。结果是不行!
 
你这样不行的,需要把ondoubleclick事件inherited 后,赋给你自己的事件,再把事件给fbutton.onclick就可以了。
// property OnBtnClick: TNotifyEvent read FOnBtnClick write FOnBtnClick;// stored IsOnClickStored;
这句话可以用的,在你的事件里判断assigned(FOnBtnClick)来触发自己的事件。也可以直接 FOnBtnClick(Self);
大概是这样,你试试先,呵呵。
 
错误提示?FButton.OnClick := OnDblClick(nil);
 
此问题已经解决!感谢各位
 
后退
顶部