首先加入TOpenDialog,然後在Filter設定為All fies (*.*)|*.*。
接著新增一個TMainMenu
然後在其底下新增一個Name=d1, Caption=檔案 (&F)
Name=N1, Caption=開啟 (&O), ShortCut=Ctrl+O, 事件Onclick連點(未來用)
Name=N2, Caption=結束 (&C), ShortCut=Ctrl+C, 事件Onclick連點(未來用)
Name=N3, Caption=-, Visible=false
Name=N1name1, Caption=&1 name, Visible=false, 事件Onclick = N1name1Click(以後會有這個事件)
Name=N2name1, Caption=&2 name, Visible=false, 事件Onclick = N1name1Click(以後會有這個事件)
Name=N3name1, Caption=&3 name, Visible=false, 事件Onclick = N1name1Click(以後會有這個事件)
Name=N4name1, Caption=&4 name, Visible=false, 事件Onclick = N1name1Click(以後會有這個事件)
Name=N5name1, Caption=&5 name, Visible=false, 事件Onclick = N1name1Click(以後會有這個事件)
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
d1: TMenuItem;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
N1name1: TMenuItem;
N2name1: TMenuItem;
N3name1: TMenuItem;
N4name1: TMenuItem;
OpenDialog1: TOpenDialog;
N5name1: TMenuItem;
procedure N1name1Click(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure N1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.N1Click(Sender: TObject);
var
s: string;
i, k: Integer;
begin
if OpenDialog1.Execute then
begin
if not N3.Visible then
N3.Visible := True; { Make separator visible }
k := d1.IndexOf(N1name1);
for i := d1.Count - 1 downto k + 1 do
begin { Move current filenames down one position }
s := d1.Items[i - 1].Caption;
s[2] := Chr(Ord('0') + (i - k + 1)); { Alt-Shortcut }
d1.Items[i].Caption := s;
d1.Items[i].Visible := d1.Items[i - 1].Visible;
end;
N1name1.Caption := '&1 ' + OpenDialog1.Filename;
N1name1.Visible := True;
ShowMessage('Adding: ' + OpenDialog1.Filename);
end;
end;
procedure TForm1.N1name1Click(Sender: TObject);
var
Filename: string;
begin
Filename := TMenuItem(sender).Caption;
System.Delete(Filename, 1, 2);
ShowMessage('Selected: ' + Filename);
end;
procedure TForm1.N2Click(Sender: TObject);
begin
close;
end;
end.
沒有留言:
張貼留言