现在使用控件, 更喜欢继承(覆盖控件已有的函数,很奇怪的一种使用方式)...
生活随笔
收集整理的這篇文章主要介紹了
现在使用控件, 更喜欢继承(覆盖控件已有的函数,很奇怪的一种使用方式)...
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
以前寫代碼, 總是把主單元弄得滿滿當當; 現在更喜歡把控件比較獨立的功能寫成一個單元, 改寫屬性、重載方法...哪怕只有一點點和默認不同, 也喜歡獨立出來.
剛剛用到 TListBox, 需要能拖動元素、雙擊刪除.
?
unit ListBox2;interfaceusesSystem.Classes, Vcl.Controls, Vcl.StdCtrls, System.Types;typeTListBox2 = class(TCustomListBox)protectedprocedure DragOver(Source: TObject; X: Integer; Y: Integer; State: TDragState; var Accept: Boolean); override;procedure DblClick; override;publicconstructor Create(AOwner: TComponent); override;procedure DragDrop(Source: TObject; X: Integer; Y: Integer); override;end;implementation{ TListBox2 }constructor TListBox2.Create(AOwner: TComponent); begininherited;DragMode := dmAutomatic; end;procedure TListBox2.DblClick; begininherited;Items.Delete(ItemIndex); end;procedure TListBox2.DragDrop(Source: TObject; X, Y: Integer); begininherited;Items.Exchange(ItemIndex, ItemAtPos(Point(X,Y), True)); end;procedure TListBox2.DragOver(Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); begininherited;Accept := True; end;end.
測試:
?
uses ListBox2;procedure TForm1.FormCreate(Sender: TObject); beginwith TListBox2.Create(Self) do beginParent := Self;Align := alLeft;Items.CommaText := 'A,B,C,D,E,F,G';end; end;轉載于:https://www.cnblogs.com/cyzgg/p/10719459.html
總結
以上是生活随笔為你收集整理的现在使用控件, 更喜欢继承(覆盖控件已有的函数,很奇怪的一种使用方式)...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 天猫上线蒂凡尼快闪店 线下门店要晚两周
- 下一篇: HashMap 与 Hashtable