delphi 掌控PageControl中的右上方的左右箭头事件  
官方Delphi 学习QQ群: 682628230(三千人)\n
频道

delphi 掌控PageControl中的右上方的左右箭头事件


unit Unit1;

interface

uses
  Windows, Messages, Classes, ComCtrls;

type
  TLRClickingEvent = procedure(Sender: TObject; var AllowClick: Boolean) of Object;

  TLRPageControl = class(TPageControl)
  private
    IsLeftBtn: Boolean;
    FOnLeftClick, FOnRightClick: TNotifyEvent;
    FOnLRClicking: TLRClickingEvent;
    procedure WMNotify(var Message: TWMNotify); message WM_NOTIFY;
    procedure WMHScroll(var Message: TWMHScroll); message WM_HSCROLL;
    procedure DoLeftClick;
    procedure DoRightClick;
    procedure DoLRClicking(var AllowClick: Boolean);
  published
    property OnLeftClick: TNotifyEvent read FOnLeftClick write FOnLeftClick;
    property OnLRClicking: TLRClickingEvent read FOnLRClicking write FOnLRClicking;
    property OnRightClick: TNotifyEvent read FOnRightClick write FOnRightClick;
  end;

implementation

uses
  CommCtrl;

{ TLRPageControl }

procedure TLRPageControl.DoLeftClick;
begin
  if Assigned(FOnLeftClick) then FOnLeftClick(Self);
end;

procedure TLRPageControl.DoLRClicking(var AllowClick: Boolean);
begin
  if Assigned(FOnLRClicking) then FOnLRClicking(Self, AllowClick);
end;

procedure TLRPageControl.DoRightClick;
begin
  if Assigned(FOnRightClick) then FOnRightClick(Self);
end;

procedure TLRPageControl.WMHScroll(var Message: TWMHScroll);
begin
  inherited;
  if Message.ScrollCode = SB_THUMBPOSITION then
    if IsLeftBtn then DoLeftClick
    else DoRightClick;
end;

procedure TLRPageControl.WMNotify(var Message: TWMNotify);
var
  AllowClick: Boolean;
begin
  inherited;
  with Message do
    if NMHdr^.code = UDN_DELTAPOS then
    begin
      IsLeftBtn := PNMUpDown(NMHdr).iDelta < 0;
      AllowClick := not LongBool(Result);
      DoLRClicking(AllowClick);
      LongBool(Result) := not AllowClick;
    end;
end;

end.

来源:https://blog.csdn.net/gencheng/article/details/1606403
 

推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.11650991439819 seconds