现在使用控件, 更喜欢继承
2013-07-24 13:20
218 查看
以前写代码, 总是把主单元弄得满满当当; 现在更喜欢把控件比较独立的功能写成一个单元, 改写属性、重载方法...哪怕只有一点点和默认不同, 也喜欢独立出来.
刚刚用到 TListBox, 需要能拖动元素、双击删除.
测试:
刚刚用到 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;
相关文章推荐
- 现在使用控件, 更喜欢继承(覆盖控件已有的函数,很奇怪的一种使用方式)
- 现在使用控件, 更喜欢继承
- listview控件的使用(2)-------继承自ListActivity的普通listview
- 演练:使用 Visual C# 从 Windows 窗体控件继承
- 唤醒控件曾经拥有的能力(重新继承是可以使用的.)
- 一个 Qt 显示图片的控件(继承QWidget,使用QPixmap记录图像,最后在paintEvent进行绘制,可缩放)
- 安卓控件使用系列29:TabHost卡片的使用方法2不继承TabActivity、TabHost控件、一个布局文件
- 使用新的控件时,要注意他的继承关系
- 使用 Visual Basic 从 Windows 窗体控件继承
- 安卓控件使用系列30:TabHost卡片的使用方法3不继承TabActivity、TabHost控件、多个布局文件
- 最简单的方法在DataGrid中自定义样式列(通过继承可以在Datagrid中使用下拉列表框,日期控件等)
- 控件属性中使用继承TypeConverter对Color[]与string进行转换
- 继承于抽象类的控件不能使用设计器
- MFC中使用Tab Control从CTabCtrl控件类继承自己的类(CTabSheet)来处理。
- 本人在代码中经常使用到两种控件 highchart 和highstock。现在分享一下两种控件互换方法
- android控件——继承AdapterView的控件无法使用addView方法
- 如何正确使用控件的方法——使用“继承”思想的重要性
- 自定义控件 继承View 使用OnMeasure定义控件宽高
- 使用My97DatePicker插件(现在基本使用前端框架自带的时间控件)