请问谁知道怎么实现类似C#的ListBox控件的Items属性的功能?(100分)

  • 主题发起人 主题发起人 crpp_hqx
  • 开始时间 开始时间
C

crpp_hqx

Unregistered / Unconfirmed
GUEST, unregistred user!
请问谁知道怎么实现类似C#的ListBox控件的Items属性的功能,是说跟Items属性一样能弹出
"字符串集合编辑器"对话框来编辑.
 
可以研究一下C#
 
安装CnPack
http://www.cnvcl.org/
专家包的源代码里有怎样注册自己的属性编辑。
 
用代码写进去,也很简单啊
 
renyi,你说和很简单,可是我不懂啦,谁能告诉我怎么写呢??/谢谢
 
>>单元文件
{StrEditor.pas}
unit StrEditor;
interface
uses Windows,Classes, Controls, StdCtrls,Buttons, TypInfo,Forms,ExtCtrls,{$IFDEF VER140}DesignIntf, VCLEditors
{$else
}DsgnIntf{$ENDIF};
type
TStrEditDlg = class(TForm)
Memo: TMemo;
BtnOK: TBitBtn;
BtnCancel: TBitBtn;
Bevel1: TBevel;
BtnAbout: TBitBtn;
Label1: TLabel;
procedure BtnAboutClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure CreateParams(var Param:TCreateParams);override;
end;

type
TCaptionEditor = class(TCaptionProperty)
public
function GetAttributes: TPropertyAttributes;
override;
procedure Edit;
override;
end;

procedure Register;
implementation
{$R *.DFM}
procedure Register;
begin
RegisterPropertyEditor(TypeInfo(TCaption), TObject, 'Caption', TCaptionEditor);
RegisterPropertyEditor(TypeInfo(TCaption), TObject, 'Text', TCaptionEditor);
RegisterPropertyEditor(TypeInfo(string), TObject, 'Hint', TCaptionEditor);
end;
{ Register }
{ THintProperty }
procedure TCaptionEditor.Edit;
var
Comp : TPersistent;
begin
with TStrEditDlg.Create(Application)do
try
Comp := GetComponent(0);
if Comp is TComponent then
Caption := TComponent(Comp).Name + '.' + GetName
else
Caption := GetName;
Memo.Text :=GetStrValue;
Memo.SelectAll;
if ShowModal = mrOk then
SetStrValue(Memo.Text);
finally
Free;
end;
end;
{ TCaptionEditor.Edit }
function TCaptionEditor.GetAttributes: TPropertyAttributes;
begin
Result := inherited GetAttributes + [paDialog];
end;
{ TCaptionEditor.GetAttributes }
procedure TStrEditDlg.BtnAboutClick(Sender: TObject);
begin
MessageBox(Handle,'Copyright (C) Kingron 2002','Info',MB_OK+MB_ICONINFORMATION);
end;
{ TStrEditDlg.BtnAboutClick }
procedure TStrEditDlg.CreateParams(var Param: TCreateParams);
begin
inherited;
Param.WndParent :=GetActiveWindow;
end;

end.

>>窗体文件
{StrEditor.dfm}
object StrEditDlg: TStrEditDlg
Left = 283
Top = 106
BorderStyle = bsDialog
Caption = 'String Editor'
ClientHeight = 221
ClientWidth = 347
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
Position = poDesktopCenter
DesignSize = (
347
221)
PixelsPerInch = 96
TextHeight = 13
object Bevel1: TBevel
Left = 8
Top = 11
Width = 329
Height = 161
Anchors = [akLeft, akTop, akRight, akBottom]
Shape = bsFrame
end
object Label1: TLabel
Left = 17
Top = 20
Width = 139
Height = 13
Caption = 'Press Ctrl+Enter to break line:'
end
object Memo: TMemo
Left = 16
Top = 40
Width = 313
Height = 121
Anchors = [akLeft, akTop, akRight, akBottom]
HideSelection = False
ScrollBars = ssVertical
TabOrder = 0
WantReturns = False
end
object BtnOK: TBitBtn
Left = 176
Top = 188
Width = 75
Height = 25
Anchors = [akLeft, akBottom]
Caption = '&OK'
TabOrder = 1
Kind = bkOK
end
object BtnCancel: TBitBtn
Left = 264
Top = 188
Width = 75
Height = 25
Anchors = [akLeft, akBottom]
Caption = '&Cancel'
TabOrder = 2
Kind = bkCancel
end
object BtnAbout: TBitBtn
Left = 8
Top = 188
Width = 75
Height = 25
Anchors = [akLeft, akBottom]
Caption = '&About'
TabOrder = 3
OnClick = BtnAboutClick
Kind = bkHelp
end
end
 
to crpp_hqx
能否把图片贴出来呀。
 
listBox1.Items.Add("One");
listBox1.Items.Add("Two");
listBox1.Items.Add("Three");
 
谢谢wjh_wy的热心,可是我要的是在C#上实现的功能,请再帮忙想想!!!谢谢!!!!
 
我的代码就是C#的呀,你在form上添加一个listbox和一个button,在button的click事件中
写入如下代码,就行了。
listBox1.Items.Add("One");
listBox1.Items.Add("Two");
listBox1.Items.Add("Three");
 
你们都理解错误啦,我要知道的是在vs.net中怎么实现listBox1.Items的属性?,而不是它的使用方法,希望大家帮想想办法,谢谢!!!!!!
 
看MSDN的帮助按索引查找“属性浏览器”
 

Similar threads

D
回复
0
查看
825
DelphiTeacher的专栏
D
D
回复
0
查看
831
DelphiTeacher的专栏
D
D
回复
0
查看
824
DelphiTeacher的专栏
D
后退
顶部