是列显示控件,他是需要一行一行的去添加,但你也可以直接用ListBox1.Items.LoadFromFile
方法来加载。他里面是以回车换行来分列。
也可以用ListBox1.Items.SaveToFile
方法直接保存成文件。
opendalog和savedialog的使用就不用多说了吧。
不算难事儿,我写了一下,你看看:unit Unit1
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls
type
TForm1 = class(TForm)
Edit1: TEdit
ListBox1: TListBox
Button1: TButton
procedure Edit1KeyDown(Sender: TObjectvar Key: Word
Shift: TShiftState)
procedure Button1Click(Sender: TObject)
private
{ Private declarations }
public
{ Public declarations }
end
var
Form1: TForm1
implementation
{$R *.dfm}
procedure TForm1.Edit1KeyDown(Sender: TObjectvar Key: Word
Shift: TShiftState)
begin
if key = 013 then
begin
listbox1.Items.Add(edit1.Text)
listbox1.SetFocus
end
end
procedure TForm1.Button1Click(Sender: TObject)
var
i:integer
begin
i:=listbox1.ItemIndex
listbox1.Items.Delete(i)
end
end.
ListBox并不能实现你所要的那样的分列功能的。如果你非只要这个实现只有这样,但是这样并不美观。Function SString(Const HS:String Const L:Integer):String
begin
Result:=Stringofchar(' ',L-Length(Hs))+HS
end
procedure TForm1.Button1Click(Sender: TObject)
var
s1,s2,s: string
begin
s1 := Edit1.Text
s2 := Edit2.Text
S := SString(s1,15) + Sstring(s2,15)
ListBox1.Items.Add(S)
end
procedure TForm1.Button2Click(Sender: TObject)
begin
ListBox1.DeleteSelected
end
结果如何你放到Delphi里试试就知道了。如果不满意再给我发消息。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)