Treeview 简单问题 50分,回答精彩可另加分。(禁止双击展开)(50分)

  • 主题发起人 主题发起人 轻音乐
  • 开始时间 开始时间

轻音乐

Unregistered / Unconfirmed
GUEST, unregistred user!
如何禁止双击展开?
 
可以拦截双击消息!具体代码等会写给你!
 
trap wm_LButtonDblClk message use Window Procedure, like setWindowLong etc...
 
能具体点吗?
 
seek detail code by RichSearch use 'SetWindowLong' as keyword.
 
在展开事件中写
 
谁能具体点说
 
可以拦截双击消息!OnMessage中把它的消息‘吃’了,记得要返回一个nil的给窗口或系统。
 
宝兰很不赞成这种做法,但是这种做法的确是很简单的.喝喝.绝对精采.加分.

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls;

type
TForm1 = class(TForm)
TreeView1: TTreeView;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
FWindowProc:TWndMethod;
procedure ProcWindowProc(var Message: TMessage);
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

{ TForm1 }

procedure TForm1.ProcWindowProc(var Message: TMessage);
begin
if Message.Msg=WM_LBUTTONDBLCLK then
Message.Msg:=WM_LBUTTONUP;
FWindowProc(Message);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
FWindowProc:=TreeView1.WindowProc;
TreeView1.WindowProc:=ProcWindowProc;
end;

end.
 
我想应该在expanding事件里搞定。下面代码并不影响dblclick事件

procedure TForm1.TreeView1Expanding(Sender: TObject; Node: TTreeNode;
var AllowExpansion: Boolean);
var
p:TPoint;
begin
p:=TreeView1.ScreenToClient(Mouse.CursorPos);
AllowExpansion:=htonbutton in TreeView1.GetHitTestInfoAt(p.x,p.Y) ;
end;
 
谢谢大家,aizb和menxin的方法有效。但menxin的方法更好,根据他的方法我还能知道
鼠标是点到item还是其它什么地方,在此表示感谢。
 
后退
顶部