首页 > 新闻动态 >  

新闻动态
NEWS

如今应用控件, 更喜好持续

添加时间:2013-7-25 点击量:


以前写代码, 老是把主单位弄得满满当当; 如今更喜好把控件斗劲自力的功能写成一个单位, 改写属性、重载办法...哪怕只有一点点和默认不合, 也喜好自力出来.



方才用到 TListBox, 须要能拖动元素、双击删除.



unit ListBox2;

interface

uses
System.Classes, Vcl.Controls, Vcl.StdCtrls, System.Types;

type
TListBox2 = class(TCustomListBox)
protected
procedure DragOver(Source: TObject; X: Integer; Y: Integer; State: TDragState; var Accept: Boolean); override;
procedure DblClick; override;
public
constructor Create(AOwner: TComponent); override;
procedure DragDrop(Source: TObject; X: Integer; Y: Integer); override;
end;

implementation

{ TListBox2 }

constructor TListBox2.Create(AOwner: TComponent);
begin
inherited;
DragMode := dmAutomatic;
end;

procedure TListBox2.DblClick;
begin
inherited;
Items.Delete(ItemIndex);
end;

procedure TListBox2.DragDrop(Source: TObject; X, Y: Integer);
begin
inherited;
Items.Exchange(ItemIndex, ItemAtPos(Point(X,Y), True));
end;

procedure TListBox2.DragOver(Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);
begin
inherited;
Accept := True;
end;

end.




测试:



uses ListBox2;

procedure TForm1.FormCreate(Sender: TObject);
begin
with TListBox2.Create(Self) do begin
Parent := Self;
Align := alLeft;
Items.CommaText := A,B,C,D,E,F,G;
end;
end;

无论对感情还是对生活,“只要甜不要苦”都是任性而孩子气的,因为我们也不完美,我们也会伤害人。正因为我们都不完美,也因为生活从不是事事如意,所以对这些“瑕疵”的收纳才让我们对生活、对他人的爱变得日益真实而具体。—— 汪冰《世界再亏欠你,也要敢于拥抱幸福》
分享到: