200分求此网页所述delphi程序!
此网页:http://www.newasp.net/tech/program/23049.html刚学编程,我用delphi7做不出哦。其中有些步骤不懂,“如首先,我们在...
此网页:http://www.newasp.net/tech/program/23049.html
刚学编程,我用delphi7做不出哦。其中有些步骤不懂,“如首先,我们在Win32面板上选择ImageList组件,设置它的StateImages属性,包括两种状态的图标,一种是选中状态,另一种是未先中状态。”另外编译中提示 ...cFlatUnCheck,
cFlatChecked,
cFlatRadioUnCheck,
cFlatRadioChecked);这些标示符未声明。总之弄不明白单选复选筐是怎样弄上去的。
请高手指教啊 展开
刚学编程,我用delphi7做不出哦。其中有些步骤不懂,“如首先,我们在Win32面板上选择ImageList组件,设置它的StateImages属性,包括两种状态的图标,一种是选中状态,另一种是未先中状态。”另外编译中提示 ...cFlatUnCheck,
cFlatChecked,
cFlatRadioUnCheck,
cFlatRadioChecked);这些标示符未声明。总之弄不明白单选复选筐是怎样弄上去的。
请高手指教啊 展开
展开全部
htOnStateIcon:在某个节点的状态图标上
GetHitTestInfoAt:在Ttreeview里边,它可以确定现在你的鼠标所在的位置,
TreeView在节点前添加复选框的功能我没有使用网上的那个例子来做的.
我自己做了一个简单的不能再简单的程序,但是已经能实现这个功能了.
1.在放置的ImageList中给它加入几个图片.这些图片就是checkbox,RadioBox选中,未被选中的状态
图片.弄清楚他们的Index. 将TreeView的StateImage属性设置为ImageList1.
在这次制作中发现一个问题,当
下面是我的代码.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ImgList, ComCtrls, ToolWin, StdCtrls;
type
TForm1 = class(TForm)
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ImageList1: TImageList;
Memo1: TMemo;
TreeView1: TTreeView;
Button1: TButton;
Edit1: TEdit;
procedure TreeView1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.TreeView1Click(Sender: TObject);
var
P : TPoint;
begin
GetCursorPos(P); //获得鼠标坐标
P := TreeView1.ScreenToClient(P);
if (htOnStateIcon in TreeView1.GetHitTestInfoAt(P.X,P.Y)) then//看开头的定义.判断鼠
标点击的是否是图标位置.这里要加上,不然会出错.
if Treeview1.Selected.StateIndex = 4 then//设置图标,这里是换图标的关键.
TreeView1.Selected.StateIndex := 3
else if Treeview1.Selected.StateIndex = 1 then
Treeview1.Selected.StateIndex := 2
else if Treeview1.Selected.StateIndex = 2 then
Treeview1.Selected.StateIndex := 1
else if Treeview1.Selected.StateIndex = 3 then
Treeview1.Selected.StateIndex := 4
end;
procedure TForm1.FormCreate(Sender: TObject);
var
node: TTreeNode;
i : integer;
begin
with TreeView1 do begin//在代码段手动设置节点.
Items.Add(nil, 'AAA');
Items.Add(nil, 'BBB');
Items.Add(nil, 'CCC');
Items.Add(nil, 'DDD');
Items.Add(nil, 'EEE');
Items.AddChild(Items[4], '111');
Items.AddChild(Items[4], '222');
Items.AddChild(Items[4], '333');
Items.AddChild(Items[4], '444');
end;
for i := 0 to treeview1.Items.Count - 1 do//给这些节点赋一个初始值.
begin
node := Treeview1.Items[i];
if node.Level = 0 then//如果是第一节点,使用图标的Index为4的图标
node.StateIndex := 3//在这里,本来我的这个图片是Index为0的,后来发现在这里加载不了Index为0的图标.所以多加了一个和Index为0一样的图标
else
node.StateIndex := 1;//如果不是,用Index为1的图标
end;
end;
end.
GetHitTestInfoAt:在Ttreeview里边,它可以确定现在你的鼠标所在的位置,
TreeView在节点前添加复选框的功能我没有使用网上的那个例子来做的.
我自己做了一个简单的不能再简单的程序,但是已经能实现这个功能了.
1.在放置的ImageList中给它加入几个图片.这些图片就是checkbox,RadioBox选中,未被选中的状态
图片.弄清楚他们的Index. 将TreeView的StateImage属性设置为ImageList1.
在这次制作中发现一个问题,当
下面是我的代码.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ImgList, ComCtrls, ToolWin, StdCtrls;
type
TForm1 = class(TForm)
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ImageList1: TImageList;
Memo1: TMemo;
TreeView1: TTreeView;
Button1: TButton;
Edit1: TEdit;
procedure TreeView1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.TreeView1Click(Sender: TObject);
var
P : TPoint;
begin
GetCursorPos(P); //获得鼠标坐标
P := TreeView1.ScreenToClient(P);
if (htOnStateIcon in TreeView1.GetHitTestInfoAt(P.X,P.Y)) then//看开头的定义.判断鼠
标点击的是否是图标位置.这里要加上,不然会出错.
if Treeview1.Selected.StateIndex = 4 then//设置图标,这里是换图标的关键.
TreeView1.Selected.StateIndex := 3
else if Treeview1.Selected.StateIndex = 1 then
Treeview1.Selected.StateIndex := 2
else if Treeview1.Selected.StateIndex = 2 then
Treeview1.Selected.StateIndex := 1
else if Treeview1.Selected.StateIndex = 3 then
Treeview1.Selected.StateIndex := 4
end;
procedure TForm1.FormCreate(Sender: TObject);
var
node: TTreeNode;
i : integer;
begin
with TreeView1 do begin//在代码段手动设置节点.
Items.Add(nil, 'AAA');
Items.Add(nil, 'BBB');
Items.Add(nil, 'CCC');
Items.Add(nil, 'DDD');
Items.Add(nil, 'EEE');
Items.AddChild(Items[4], '111');
Items.AddChild(Items[4], '222');
Items.AddChild(Items[4], '333');
Items.AddChild(Items[4], '444');
end;
for i := 0 to treeview1.Items.Count - 1 do//给这些节点赋一个初始值.
begin
node := Treeview1.Items[i];
if node.Level = 0 then//如果是第一节点,使用图标的Index为4的图标
node.StateIndex := 3//在这里,本来我的这个图片是Index为0的,后来发现在这里加载不了Index为0的图标.所以多加了一个和Index为0一样的图标
else
node.StateIndex := 1;//如果不是,用Index为1的图标
end;
end;
end.
展开全部
procedure ToggleTreeViewCheckBoxes(
Node :TTreeNode;
cUnChecked, //CheckBox未选中状态
cChecked, //CheckBox选中状态
cRadioUnchecked, //RadioButtion未选中状态
cRadioChecked :integer); // RadioButtion选中状态
var
tmp:TTreeNode;
begin
if Assigned(Node) then
begin
//如果当前是未选中状态则变为选中状态
if Node.StateIndex = cUnChecked then
Node.StateIndex := cChecked
//如果当前是选中状态则变为未选中状态
else if Node.StateIndex = cChecked then
Node.StateIndex := cUnChecked
else if Node.StateIndex = cRadioUnChecked then
begin
tmp := Node.Parent;
if not Assigned(tmp) then
tmp := TTreeView(Node.TreeView).Items.getFirstNode
else
tmp := tmp.getFirstChild;
while Assigned(tmp) do
begin
if (tmp.StateIndex in
[cRadioUnChecked,cRadioChecked]) then
tmp.StateIndex := cRadioUnChecked;
tmp := tmp.getNextSibling;
end;
Node.StateIndex := cRadioChecked;
end; // if StateIndex = cRadioUnChecked
end; // if Assigned(Node)
end;
procedure TForm1.TreeView1Click(Sender: TObject);
var
P:TPoint;
begin
GetCursorPos(P); //得到光标的位置
P := TreeView1.ScreenToClient(P);
if (htOnStateIcon in
TreeView1.GetHitTestInfoAt(P.X,P.Y)) then
ToggleTreeViewCheckBoxes(
TreeView1.Selected,
cFlatUnCheck,
cFlatChecked,
cFlatRadioUnCheck,
cFlatRadioChecked);
end;
(2)当键盘选择时,代码如下:
procedure TForm1.TreeView1KeyDown(
Sender: TObject;
var Key: Word;
Shift: TShiftState);
begin
if (Key = VK_SPACE) and
Assigned(TreeView1.Selected) then
ToggleTreeViewCheckBoxes(
TreeView1.Selected,
cFlatUnCheck,
cFlatChecked,
cFlatRadioUnCheck,
cFlatRadioChecked);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
BoolResult:boolean;
tn : TTreeNode;
begin
if Assigned(TreeView1.Selected) then
begin
tn := TreeView1.Selected;
BoolResult := tn.StateIndex in
[cFlatChecked,cFlatRadioChecked];
Memo1.Text := tn.Text +
#13#10 +
'Selected: ' +
BoolToStr(BoolResult, True);
//Memo给出所选中的节点和当前的状态
end;
end;
Node :TTreeNode;
cUnChecked, //CheckBox未选中状态
cChecked, //CheckBox选中状态
cRadioUnchecked, //RadioButtion未选中状态
cRadioChecked :integer); // RadioButtion选中状态
var
tmp:TTreeNode;
begin
if Assigned(Node) then
begin
//如果当前是未选中状态则变为选中状态
if Node.StateIndex = cUnChecked then
Node.StateIndex := cChecked
//如果当前是选中状态则变为未选中状态
else if Node.StateIndex = cChecked then
Node.StateIndex := cUnChecked
else if Node.StateIndex = cRadioUnChecked then
begin
tmp := Node.Parent;
if not Assigned(tmp) then
tmp := TTreeView(Node.TreeView).Items.getFirstNode
else
tmp := tmp.getFirstChild;
while Assigned(tmp) do
begin
if (tmp.StateIndex in
[cRadioUnChecked,cRadioChecked]) then
tmp.StateIndex := cRadioUnChecked;
tmp := tmp.getNextSibling;
end;
Node.StateIndex := cRadioChecked;
end; // if StateIndex = cRadioUnChecked
end; // if Assigned(Node)
end;
procedure TForm1.TreeView1Click(Sender: TObject);
var
P:TPoint;
begin
GetCursorPos(P); //得到光标的位置
P := TreeView1.ScreenToClient(P);
if (htOnStateIcon in
TreeView1.GetHitTestInfoAt(P.X,P.Y)) then
ToggleTreeViewCheckBoxes(
TreeView1.Selected,
cFlatUnCheck,
cFlatChecked,
cFlatRadioUnCheck,
cFlatRadioChecked);
end;
(2)当键盘选择时,代码如下:
procedure TForm1.TreeView1KeyDown(
Sender: TObject;
var Key: Word;
Shift: TShiftState);
begin
if (Key = VK_SPACE) and
Assigned(TreeView1.Selected) then
ToggleTreeViewCheckBoxes(
TreeView1.Selected,
cFlatUnCheck,
cFlatChecked,
cFlatRadioUnCheck,
cFlatRadioChecked);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
BoolResult:boolean;
tn : TTreeNode;
begin
if Assigned(TreeView1.Selected) then
begin
tn := TreeView1.Selected;
BoolResult := tn.StateIndex in
[cFlatChecked,cFlatRadioChecked];
Memo1.Text := tn.Text +
#13#10 +
'Selected: ' +
BoolToStr(BoolResult, True);
//Memo给出所选中的节点和当前的状态
end;
end;
参考资料: 源码如上
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询