一个FORM,一个BUTTON,一个BUTTON点击事件,然后COPY我的代码替换unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TMyListBox = class(TListBox) protected procedure CreateParams(var Params: TCreateParams); override; end; TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TMyListBox.CreateParams(var Params: TCreateParams); begin inherited CreateParams(Params); with Params do begin Style := Style - WS_VSCROLL; end; end;procedure TForm1.Button1Click(Sender: TObject); var i: integer; lb: TMyListBox; begin lb:= TMyListBox.Create(Self); lb.Parent:= Self; lb.SetBounds(10,10,100,100); for i:= 0 to 100 do lb.Items.Add(inttostr(i)) end;end.
正解 也可以直接发消息 设置 ListView 的 sytle
设置listbox的 列数 大于0,则变为左右的滚动条
procedure TForm1.FormCreate(Sender: TObject); begin SetWindowLong(ListBox1.Handle,GWL_STYLE,GetWindowLong(ListBox1.Handle,GWL_STYLE) and not WS_VSCROLL and not WS_HSCROLL); end;
procedure TForm1.FormCreate(Sender: TObject); begin SetWindowLong(ListBox1.Handle,GWL_STYLE,GetWindowLong(ListBox1.Handle,GWL_STYLE) and not WS_VSCROLL and not WS_HSCROLL); end; 其实这个方法是对的。。只是需要多次调用的。。因为LISTBOX的流动条的显示与否是系统动态进行设置的。。 你要再每次重画之前把滚动条用这个方法隐藏条。
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TMyListBox = class(TListBox)
protected
procedure CreateParams(var Params: TCreateParams); override;
end; TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TMyListBox.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
with Params do
begin
Style := Style - WS_VSCROLL;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
lb: TMyListBox;
begin
lb:= TMyListBox.Create(Self);
lb.Parent:= Self;
lb.SetBounds(10,10,100,100);
for i:= 0 to 100 do
lb.Items.Add(inttostr(i))
end;end.
也可以直接发消息 设置 ListView 的 sytle
procedure TForm1.FormCreate(Sender: TObject);
begin
SetWindowLong(ListBox1.Handle,GWL_STYLE,GetWindowLong(ListBox1.Handle,GWL_STYLE) and not WS_VSCROLL and not WS_HSCROLL);
end;
begin
SetWindowLong(ListBox1.Handle,GWL_STYLE,GetWindowLong(ListBox1.Handle,GWL_STYLE) and not WS_VSCROLL and not WS_HSCROLL);
end;
其实这个方法是对的。。只是需要多次调用的。。因为LISTBOX的流动条的显示与否是系统动态进行设置的。。
你要再每次重画之前把滚动条用这个方法隐藏条。