procedure TForm1.Button1Click(Sender: TObject);
var
I:Integer;
ItemCaption:String;
begin
for I:=0 to MainMenu1.Items[0].Count-1 do
begin
ItemCaption:=MainMenu1.Items[0].Items [I].Caption ;
Delete(ItemCaption,Pos('&',ItemCaption),1);
if ItemCaption=Trim(Edit1.Text) then
MainMenu1.Items[0].Items[I].Visible:=False;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i,j:integer;
begin
for j:=0 to MainMenu1.items.count-1 do
begin
if MenuItem1.Items[J].Caption := '你想隐藏菜单顶层的名字' then
begin
for i:=0 to MainMenu1.Items[0].Count-1 do
begin
if MainMenu1.Items[0].Items[i].Caption=edit1.Text then
MainMenu1.Items[0].Items[i].Visible:=false;
end;
end;
end;
不会还出错吧?
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin
for i:=0 to MainMenu1.Items[0].Count-1 do
begin
if MainMenu1.Items[0].Items[i].Caption=edit1.Text then
MainMenu1.Items[0].Items[i].Visible:=false;
end;
end;
这个可以吗?
procedure HiddenByName(Name:string;Parent:TMenuItem);
var i:integer;
begin
for i:=0 to Parent.Count-1 do
if CompareText(Parent.Items[i].Caption,Name)=0 then
begin
Parent.Items[i].Visible:=false;
exit;//如果你要把所有和AName相同的都隐藏掉。去掉这个exit就可以了
end;
end;