tsTabs:(默认)选项卡样式tsButtons:按钮样式(经典样式)tsFlatButtons:按钮样式2(经典样式)
TabPosition:选项卡的位置
tpBottom:下面(很奇怪)tpLeft:左面(经典样式)tPRight:右面(经典样式)tpTop:(默认)上面
然后是PageControl中的TabSheet:
1 procedure TForm1.Button1Click(Sender: TObject);2 var3 btn: TButton;4 begin5 btn := TButton.Create();6 //下面是对Button的属性修改7 btn.Caption := '按钮';8 end;
1 procedure TForm1.FileOpenAccept(Sender: TObject); 2 var 3 fName: string; 4 cIndex: Integer; 5 begin 6 Add1.Click(); 7 cIndex := PageControl1.ActivePageIndex; 8 fName := FileOpen1.Dialog.FileName; 9 TMemo(PageControl1.Pages[cIndex].Controls[0]).LoadFromFile(fName);10 end;
1 type2 TRecEdit = class(TMemo)3 protected4 fPath: string; //用于存放通过打开的文件的完整路径5 end;
1 procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);2 begin3 while PageControl1.PageCount > 0 do4 if not ClosePageQuery() then begin5 CanClose := True;6 Exit;7 end;8 end;
for i := 0 to PageControl1.PageCount - 1 do PageControl1.Pages[i].Destroy;
PageControl1.Pages[i].Destroy;
PageControl1.ActivePage.Destroy;
1 while PageControl1.PageCount > 0 do2 if not ClosePageQuery() then3 break;
1 pIndex := PageControl1.ActivePageIndex;2 s := TRecEdit(PageControl1.Pages[pIndex].Controls[0]).fPath;3 if s = '' then begin4 if SaveDialog1.Execute then5 TRecEdit(PageControl1.Pages[pIndex].Controls[0]).Lines.SaveToFile(SaveDialog1.FileName);6 end else7 if TRecEdit(PageControl1.Pages[pIndex].Controls[0]).Modified then8 TRecEdit(PageControl1.Pages[pIndex].Controls[0]).Lines.SaveToFile(s);
1 unit Unit1; 2 3 interface 4 5 uses 6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 7 Dialogs, Menus, StdCtrls, ComCtrls, StdActns, ActnList; 8 9 type 10 TRecEdit = class(TMemo) 11 protected 12 fPath: string; 13 end; 14 15 TForm1 = class(TForm) 16 PageControl1: TPageControl; 17 PopupMenu1: TPopupMenu; 18 Add1: TMenuItem; 19 ClosePage1: TMenuItem; 20 CloseAll1: TMenuItem; 21 ActionList1: TActionList; 22 FileOpen1: TFileOpen; 23 FileSaveAs1: TFileSaveAs; 24 EditCut1: TEditCut; 25 EditCopy1: TEditCopy; 26 EditPaste1: TEditPaste; 27 EditSelectAll1: TEditSelectAll; 28 EditUndo1: TEditUndo; 29 EditDelete1: TEditDelete; 30 MainMenu1: TMainMenu; 31 F1: TMenuItem; 32 E1: TMenuItem; 33 N1: TMenuItem; 34 O1: TMenuItem; 35 S1: TMenuItem; 36 SaveAs1: TMenuItem; 37 Undo1: TMenuItem; 38 N2: TMenuItem; 39 Cut1: TMenuItem; 40 Copy1: TMenuItem; 41 Paste1: TMenuItem; 42 Delete1: TMenuItem; 43 N3: TMenuItem; 44 SelectAll1: TMenuItem; 45 N4: TMenuItem; 46 C1: TMenuItem; 47 L1: TMenuItem; 48 N5: TMenuItem; 49 X1: TMenuItem; 50 SaveDialog1: TSaveDialog; 51 procedure Add1Click(Sender: TObject); 52 procedure FormCreate(Sender: TObject); 53 procedure ClosePage1Click(Sender: TObject); 54 procedure CloseAll1Click(Sender: TObject); 55 procedure FileOpen1Accept(Sender: TObject); 56 procedure N1Click(Sender: TObject); 57 procedure S1Click(Sender: TObject); 58 procedure FileSaveAs1Accept(Sender: TObject); 59 procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); 60 private 61 { Private declarations } 62 function ClosePageQuery(pIndex: Integer): Boolean; overload; 63 function ClosePageQuery(): Boolean; overload; 64 public 65 { Public declarations } 66 end; 67 68 var 69 Form1: TForm1; 70 n: Integer; 71 72 implementation 73 74 {$R *.dfm} 75 76 procedure TForm1.Add1Click(Sender: TObject); 77 var 78 tab: TTabSheet; 79 TeMemo: TRecEdit; 80 begin 81 tab := TTabSheet.Create(PageControl1); 82 tab.PageControl := PageControl1; 83 TeMemo := TRecEdit.Create(tab); 84 TeMemo.Parent := tab; 85 TeMemo.fPath := ''; 86 TeMemo.Align := alClient; 87 TeMemo.ScrollBars := ssVertical; 88 C1.Enabled := True; 89 L1.Enabled := True; 90 end; 91 92 function TForm1.ClosePageQuery(pIndex: Integer): Boolean; 93 var 94 ret: Integer; 95 begin 96 if TRecEdit(PageControl1.Pages[pIndex].Controls[0]).Modified then begin 97 ret := application.MessageBox('当前文件内容已经修改,想保存文件吗?', '保存', 51); //51=48+3 98 case ret of 99 IDYES: FileSave1.Click();100 IDCANCEL: begin101 Result := False;102 Exit;103 end;104 end;105 end;106 PageControl1.Pages[pIndex].Destroy;107 Result := True;108 end;109 110 function TForm1.ClosePageQuery: Boolean;111 begin112 Result := ClosePageQuery(PageControl1.ActivePageIndex);113 end;114 115 procedure TForm1.CloseAll1Click(Sender: TObject);116 begin117 while PageControl1.PageCount > 0 do118 if not ClosePageQuery() then119 break;120 if PageControl1.PageCount = 0 then begin121 C1.Enabled := False;122 L1.Enabled := False;123 end;124 end;125 126 procedure TForm1.ClosePage1Click(Sender: TObject);127 begin128 ClosePageQuery(PageControl1.ActivePageIndex);129 if PageControl1.PageCount = 0 then begin130 C1.Enabled := False;131 L1.Enabled := False;132 end;133 end;134 135 procedure TForm1.FileOpen1Accept(Sender: TObject);136 var137 pIndex: Integer;138 fName: string;139 begin140 Add1.Click;141 pIndex := PageControl1.ActivePageIndex;142 fName := FileOpen1.Dialog.FileName;143 TRecEdit(PageControl1.Pages[pIndex].Controls[0]).Lines.LoadFromFile(fName);144 TRecEdit(PageControl1.Pages[pIndex].Controls[0]).fPath := fName;145 PageControl1.ActivePage.Caption := ExtractFileName(fName);146 //Form1.Caption := fName;147 end;148 149 procedure TForm1.FileSaveAs1Accept(Sender: TObject);150 var151 pIndex: Integer;152 sPath: string;153 begin154 pIndex := PageControl1.ActivePageIndex;155 sPath := FileSaveAs1.Dialog.FileName;156 TRecEdit(PageControl1.Pages[pIndex].Controls[0]).Lines.SaveToFile(sPath);157 TRecEdit(PageControl1.Pages[pIndex].Controls[0]).fPath := sPath;158 end;159 160 procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);161 begin162 while PageControl1.PageCount > 0 do163 if not ClosePageQuery() then begin164 CanClose := True;165 Exit;166 end;167 end;168 169 procedure TForm1.FormCreate(Sender: TObject);170 begin171 n := 1;172 N1.Click;173 end;174 175 procedure TForm1.N1Click(Sender: TObject); //新建176 begin177 Add1.Click;178 PageControl1.ActivePage.Caption := '无标题' + IntToStr(n);179 Inc(n);180 end;181 182 procedure TForm1.S1Click(Sender: TObject); //保存183 var184 s: string;185 pIndex: Integer;186 begin187 with PageControl1 do begin188 pIndex := ActivePageIndex;189 s := TRecEdit(Pages[pIndex].Controls[0]).fPath;190 if s = '' then begin191 if SaveDialog1.Execute then begin192 TRecEdit(Pages[pIndex].Controls[0]).Lines.SaveToFile(SaveDialog1.FileName);193 TRecEdit(Pages[pIndex].Controls[0]).fPath = SaveDialog1.FileName;194 end;195 end else196 if TRecEdit(Pages[pIndex].Controls[0]).Modified then197 TRecEdit(Pages[pIndex].Controls[0]).Lines.SaveToFile(s);198 ActivePage.Caption := ExtractFileName(s);199 end;200 end;201 202 end.
新闻热点
疑难解答