如何使组件编辑器在双击时执行原始处理程序?(How to make a component editor perform original handler on double click?)

编程入门 行业动态 更新时间:2024-10-28 09:16:10
如何使组件编辑器在双击时执行原始处理程序?(How to make a component editor perform original handler on double click?)

我已经为我的自定义控件构建了一个自定义组件编辑器( TComponentEditor )。 我正在实现右键单击上下文菜单,这意味着默认情况下,在设计时双击控件会执行第一个上下文菜单项。 但是,双击后,我不希望发生这种情况。 我想创建一个OnClick事件处理程序的原始行为。

覆盖此组件编辑器的Edit过程时,我已尝试使用和不使用inherited 。 如果我包含它,双击将执行上下文菜单中的第一项。 如果我不包含inherited ,则双击控件时根本不会发生任何事情。 在添加此组件编辑器之前,双击将自动生成OnClick事件处理程序,而不执行任何我自己的操作。

{ TFontButtonEditor } type TFontButtonEditor = class(TComponentEditor) private FForm: TfrmFontButtonEditor; FBtn: TFontButton; procedure ExecEditor; protected procedure ExecuteVerb(Index: Integer); override; function GetVerb(Index: Integer): String; override; function GetVerbCount: Integer; override; public constructor Create(AComponent: TComponent; ADesigner: IDesigner); override; destructor Destroy; override; procedure Edit; override; end; constructor TFontButtonEditor.Create(AComponent: TComponent; ADesigner: IDesigner); begin inherited; FBtn:= TFontButton(AComponent); //Reference instance of control FForm:= TfrmFontButtonEditor.Create(nil); //Create editor form instance end; destructor TFontButtonEditor.Destroy; begin FForm.Free; inherited; end; procedure TFontButtonEditor.Edit; begin //Executed on double-click, but I don't want to... //inherited; end; procedure TFontButtonEditor.ExecEditor; begin FForm.FFont.Assign(FBtn.Image.Font); FForm.ImageChar:= FBtn.Image.Text; //More assignments case FForm.ShowModal of mrOK: begin FBtn.Image.Font.Assign(FForm.FFont); FBtn.Image.Text:= FForm.ImageChar; //More assignments end; else begin //Cancelled end; end; end; procedure TFontButtonEditor.ExecuteVerb(Index: Integer); begin case Index of 0: begin ExecEditor; //Also executed on double-click, don't want it to... end; 1: begin MessageDlg('Font Button Control - XXXXX', mtInformation, [mbOK], 0); end; end; end; function TFontButtonEditor.GetVerb(Index: Integer): String; begin case Index of 0: Result:= '&Edit Font Button'; 1: Result:= '&About Font Button'; end; end; function TFontButtonEditor.GetVerbCount: Integer; begin Result:= 2; end;

如何使用组件编辑器双击此自定义控件来执行旧式OnClick事件处理程序而不是尝试执行组件编辑器?

I've built a custom component editor (TComponentEditor) for a custom control of mine. I am implementing the right-click context menu, which means by default, double-clicking the control in design-time executes the first of the context menu items. However, upon double-click, I do not wish for this to happen. I would like the original behavior of creating an OnClick event handler.

When overriding the Edit procedure of this component editor, I have tried both with and without inherited. If I include it, double-clicking executes the first item in the context menu. If I don't include inherited, then nothing happens at all when double-clicking the control. Before adding this component editor, the double-click would automatically generate an OnClick event handler without any implementation of my own.

{ TFontButtonEditor } type TFontButtonEditor = class(TComponentEditor) private FForm: TfrmFontButtonEditor; FBtn: TFontButton; procedure ExecEditor; protected procedure ExecuteVerb(Index: Integer); override; function GetVerb(Index: Integer): String; override; function GetVerbCount: Integer; override; public constructor Create(AComponent: TComponent; ADesigner: IDesigner); override; destructor Destroy; override; procedure Edit; override; end; constructor TFontButtonEditor.Create(AComponent: TComponent; ADesigner: IDesigner); begin inherited; FBtn:= TFontButton(AComponent); //Reference instance of control FForm:= TfrmFontButtonEditor.Create(nil); //Create editor form instance end; destructor TFontButtonEditor.Destroy; begin FForm.Free; inherited; end; procedure TFontButtonEditor.Edit; begin //Executed on double-click, but I don't want to... //inherited; end; procedure TFontButtonEditor.ExecEditor; begin FForm.FFont.Assign(FBtn.Image.Font); FForm.ImageChar:= FBtn.Image.Text; //More assignments case FForm.ShowModal of mrOK: begin FBtn.Image.Font.Assign(FForm.FFont); FBtn.Image.Text:= FForm.ImageChar; //More assignments end; else begin //Cancelled end; end; end; procedure TFontButtonEditor.ExecuteVerb(Index: Integer); begin case Index of 0: begin ExecEditor; //Also executed on double-click, don't want it to... end; 1: begin MessageDlg('Font Button Control - XXXXX', mtInformation, [mbOK], 0); end; end; end; function TFontButtonEditor.GetVerb(Index: Integer): String; begin case Index of 0: Result:= '&Edit Font Button'; 1: Result:= '&About Font Button'; end; end; function TFontButtonEditor.GetVerbCount: Integer; begin Result:= 2; end;

How can I make double-clicking this custom control with a component editor to do the old-fashion OnClick event handler rather than trying to execute the component editor?

最满意答案

从TDefaultEditor而不是TDefaultEditor下降。

(TDefaultEditor通过调用OnCreate , OnChange或OnClick属性的Edit方法或其找到的第一个事件属性来替换Edit方法。该属性的Edit方法使用Designer.CreateMethod在TMethodProperty.SetValue创建事件处理TMethodProperty.SetValue有关继承表格,现有名称等的几项检查......)

Descend from TDefaultEditor instead of TComponentEditor.

(TDefaultEditor replaces the Edit method with your wishes by invoking the Edit method of the OnCreate, OnChange or OnClick property, or otherwise the first event property it finds. The Edit method of that property creates the eventhandler in TMethodProperty.SetValue with Designer.CreateMethod along with several checks concerning inherited forms, existing names, etc...)

更多推荐

本文发布于:2023-08-04 04:21:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1411765.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:双击   编辑器   组件   原始   程序

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!