有多个radiogroup时,如何判断鼠标单击了哪个radiogroup?

yuanlaqin 2014-09-24 12:47:29
我的界面上有多个radiogroup时,如何判断鼠标单击了哪个radiogroup?我不想为没个radiogroup写单击的代码,因为每个radiogroup的单击代码内容大同小异,代码内容与radiogroup的name属性相关,所以想能不能写一个统一的radiogroup 的单击事件代码?菜鸟一个,请指教!
...全文
2988 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
w20ss08 2016-04-08
  • 打赏
  • 举报
回复
android的多个radiogroup呢 怎么获取值
qq_28693037 2015-10-10
  • 打赏
  • 举报
回复
楼主能不能把这点代码给我看看
yuanlaqin 2014-09-24
  • 打赏
  • 举报
回复
看明白了,谢谢2位!
yuanlaqin 2014-09-24
  • 打赏
  • 举报
回复
谢谢sololie ,我没看明白2楼的意思,是要写一个过程吗?然后每个radiogroup调用这个过程?
yuanlaqin 2014-09-24
  • 打赏
  • 举报
回复
谢谢sololie ,我要实现单击某个radiogroup的radio时,提取这个radiogroup的名称,并同时提取该radiogroup的itemsindex这2个参数,也就是说,为上述的事件写一个通用的代码,因为我有好几十个radiogroup要做同样的工作。我总不能为每个radiogroup的click里面写一段代码啊?
sololie 2014-09-24
  • 打赏
  • 举报
回复
引用 4 楼 yuanlaqin 的回复:
回复sololie ,我没说明白,其实就是点击radiogroup里面的radio
如果是这样,处理radiogroup的OnClick事件,2楼说完了
sololie 2014-09-24
  • 打赏
  • 举报
回复
如果是点击radiogroup本身,可以这样

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, AppEvnts;

type
  TForm1 = class(TForm)
    rg1: TRadioGroup;
    rg2: TRadioGroup;
    // 放个TApplicationEvents 控件
    aplctnvnts1: TApplicationEvents;
    procedure aplctnvnts1Message(var Msg: tagMSG; var Handled: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

// 处理TApplicationEvents 的OnMessage事件
procedure TForm1.aplctnvnts1Message(var Msg: tagMSG; var Handled: Boolean);
var
  i: Integer;
  ctr: TWinControl;
begin
  if Msg.message = WM_LBUTTONDOWN then
  begin
    for i := 0 to ControlCount - 1 do
    begin
      if ctr is TWinControl then ctr := Controls[i] as TWinControl;
      if (ctr.ClassNameIs('TRadioGroup')) and (ctr.Handle = Msg.hwnd) then
        ShowMessage(‘点击了’ + ctr.Name);
    end;
  end;
end;

end.
yuanlaqin 2014-09-24
  • 打赏
  • 举报
回复
回复sololie ,我没说明白,其实就是点击radiogroup里面的radio
yuanlaqin 2014-09-24
  • 打赏
  • 举报
回复
mathsfan 能说的详细些吗?这个是做一个过程吗?然后在每个radiogroup的click中调用这个过程?
mathsfan 2014-09-24
  • 打赏
  • 举报
回复
TRadiogroup(Sender).XXX就可以了,然后多个radiogroup关联到同一个事件上。
sololie 2014-09-24
  • 打赏
  • 举报
回复
是点击radiogroup本身,还是要radiogroup容器里面的radio?

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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