大家帮帮忙

s_delhpi 2003-10-18 01:36:18
unit TestCombobox;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,Grids;

type
TTestCombobox = class;
TMyComboBox=class(TStringGrid)
private
FEdit:TTestCombobox;
protected
procedure CreateParams(var params:TCreateParams);override;
procedure WMSetFocus(var Msg:TWMSetFocus);message WM_SETFOCUS;

public
constructor Create(AOwner:TComponent);override;
{procedure OnSelectCell(Sender: TObject; ACol, ARow: Longint;
var CanSelect: Boolean);}

end;

TTestCombobox = class(TCustomEdit)
private
FMyComboBox:TMyComboBox;
FDowned:Boolean;
procedure ShowCombobox;
procedure HideComboBox;
procedure WM_KeyDown(var Msg:TWMKey);message WM_KEYDOWN;
//procedure OnSelectCell(Sender: TObject; ACol, ARow: Longint;
// var CanSelect: Boolean);
protected
procedure CMCancelMode(var Msg:TCMCancelMode);message CM_CANCELMODE;
procedure WM_LButtonDown(var Msg:TWMMouse);message WM_LBUTTONDOWN;
public
Constructor Create(AOwner:TComponent);override;
destructor Destroy;override;
published
{ Published declarations }
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('XP', [TTestCombobox]);
end;

{ TTestCombobox }

procedure TTestCombobox.WM_KeyDown(var Msg: TWMKey);
begin
case Msg.CharCode of
VK_UP,VK_Down,VK_LBUTTON,VK_Right,VK_Left://你想发送给下拉Grid的按键;
begin
if FDowned then
begin
SendMessage(FMyCombobox.Handle,Msg.Msg,Msg.CharCode,Msg.KeyData);
end
else
Inherited;
//Text:=FMyComboBox.Cells[1,1];
end;
VK_Return:
begin

//Text:='OK'; //FMyComboBox.Cells;
HideComboBox;

end;
else
Inherited;
end;
end;


procedure TTestCombobox.CMCancelMode(var Msg: TCMCancelMode);
begin
inherited;
if FDowned then
begin
HideComboBox;
end;
end;

constructor TTestCombobox.Create(AOwner: TComponent);
Var
i,j : Integer;
begin
inherited Create(AOwner);
FMyComboBox:=TMyComboBox.Create(self);
FMyCombobox.FixedCols := 0;
FMyCombobox.FixedRows := 0;
FDowned:=false;
//*******************//
for i:=0 to 4 do
begin
for j:=0 to 4 do
begin
FMyCombobox.Cells[i,j] := InttoStr(i)+IntToStr(j);
end;
end;
//*******************//
end;

destructor TTestCombobox.Destroy;
begin
FMyComboBox.Free;
FMyComboBox:=nil;
inherited Destroy;
end;

procedure TTestCombobox.HideComboBox;
begin
ShowWindow(FMyCombobox.handle,SW_HIDE);
FDowned:=not FDowned;
end;

procedure TTestCombobox.ShowCombobox;
var
Point:TPoint;
begin
Point.x:=Left;
Point.y:=top+Height;
Point:=Parent.ClienttoScreen(Point);
SetWindowPos(FMyComboBox.Handle,HWND_TOP,Point.x,Point.y,0,0,SWP_NOACTIVATE or SWP_HideWindow or SWP_NOSIZE); ShowWindow(FMyComboBox.Handle,SW_SHOW);
FDowned:=not FDowned;
end;

procedure TTestCombobox.WM_LButtonDown(var Msg: TWMMouse);
begin
if not FDowned then
begin
ShowComboBox;
end
else
begin
HideCombobox;
end;
end;

{ TMyComboBox }

constructor TMyComboBox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FEdit:=TTestCombobox(AOwner);

ControlStyle:=ControlStyle + [csNoDesignVisible, csReplicatable,
csAcceptsControls];


Width:=134;
Height:=130;

ColCount:=2;
RowCount:=5;
FixedCols:=0;

ScrollBars:=ssNone;

Visible := False;
Parent:=TWinControl(AOwner);
//Parent:=TCustomEdit(TTestCombobox).Parent;
//ScrollBars:=ssNone;
end;

procedure TMyComboBox.CreateParams(var params: TCreateParams);
begin
inherited CreateParams(params);
with Params do
begin
Style:=style or ws_popup;
EXStyle:=EXStyle or WS_EX_CLIENTEDGE or WS_EX_TOOLWINDOW;
end;
end;

procedure TMyComboBox.WMSetFocus(var Msg: TWMSetFocus);
begin
Inherited;
FEdit.SetFocus;
end;

end.
...全文
46 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hkbarton 2003-10-19
  • 打赏
  • 举报
回复
处理wm_KeyDown和WM_LBUTTONDBLCLK消息就可以了
s_delhpi 2003-10-19
  • 打赏
  • 举报
回复
怎么定义一个回车事件,使Stringgrid中选中的cell值赋给Edit.怎么定义一个鼠标双击事件,使Stringgrid中选中的cell值赋给Edit
hkbarton 2003-10-18
  • 打赏
  • 举报
回复
上面的代码有什么问题吗?
s_delhpi 2003-10-18
  • 打赏
  • 举报
回复
大家尽量想想办法好吗?谢谢了
s_delhpi 2003-10-18
  • 打赏
  • 举报
回复
一开始显示的只有Edit,其实这个是组合控件,要完成Combobox的功能,当Edit获得焦点的时候,我显示Stringgrid,然后我可以用鼠标或者上下左右键选取其中的一个Cell,选好以后我按回车或鼠标双击把Cell的值赋给Edit,同时StringGrid Hide,然后把焦点转到下一个控件。。。

大家能不能看看怎么改代码,实现这样的功能
不需要开发,0行代码写接口服务,sql编程,只要会sql就会写接口服务,让后端变得更简单,简单4步短短5分钟,立马上手,java小白也可以写接口。订阅课程后可以免费获取发布版进行使用和测试。 0行代码写服务的需要来源案例一,当时有个项目,有400张表,都是管理系统,单表维护的内容较多,当时的项目团队是13人,前后端都写,那时候还没有springboot,用的是ssm,mybatis刚出来,有了替代hibernate的趋势,ifelse写了一堆又一堆,实体类也是,当时的后端分了7层☒,天天加班干这活,复制粘贴,很容易犯错,实体类多人引用修改,真的是废了很大的劲……案例二,也是一个比较大的项目,两千万多万那种,当时为了拿项目,需要快速实现原型给客户看,要求比较高,虽说是原型但是数据全部需要实时,这时候就需要大量编写数据接口,同样编写接口这件事难度倒是不大,但是量大,编写过程手写很容易出错……案例三,以前管理的团队主要做移动端开发,里面的项目会涉及到推送,管理系统,数据采集与同步,总之很多内容,需要前后端通吃,我不仅需要出方案,设计原型,设计数据库,出报价,沟通需求,还要写后端框架,数据接口与数据采集,开发前端(web端),移动端,管理所有项目,但是那时候招的人只会写移动端,实在是忙不过来,我就想能不能有个框架让不会写java的人能写接口,因为写移动端sqlite总是会用的,也就是说写sql不是难点……基于以上三点需求的积累,我利用业余时间写了一个后端框架,完成了这样的需求,刚开始是需要写三行代码完成一个接口,经过后面优化,现在不写代码也可以实现……  本框架涉及的知识点比较多,目前提供最基础版供大家学习和使用,后期逐步推出框架具体的教程和功能内容,下期我们讲如何在实际项目中通过部署版如何完成所需要的接口编写,欢迎大家订阅。

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧