WEB开发网
开发学院软件开发Delphi Delphi图象截取编程示例(3) 阅读

Delphi图象截取编程示例(3)

 2006-02-04 13:53:26 来源:WEB开发网   
核心提示: (五)TMainForm的事件和函数 和 TPRinter打印应用// 打印知识[菜单项file\打印] 事件:procedure TMainForm.filePrintItemClick(Sender: TObject);begin {kh1}print;{kh2} Screen.Cursor := crHou
 

(五)TMainForm的事件和函数 和 TPRinter打印应用
////////// 打印知识
[菜单项file\打印] 事件:
procedure TMainForm.filePrintItemClick(Sender: TObject);
begin
  {kh1}print;{kh2}
  Screen.Cursor := crHourglass;
  try
   if MDIChildCount<>0 then
    with ActiveMDIChild as TMDIChild do begin
     with Printer do begin
      BeginDoc;                  //开始打印
      Canvas.Draw(0,0,Image1.Picture.Graphic);  //图形输出
      EndDoc;                   //结束打印
     end;
    end;
  finally
   Screen.Cursor := crDefault;
  end;
end;

[菜单项file\打印设置] 事件:
procedure TMainForm.filePrintSetClick(Sender: TObject);
begin
  Screen.Cursor:=crHourglass;
  PrinterSetupDialog1.Execute ;
  Screen.Cursor:=crDefault;
end;
  
[菜单项edit\Preferences\ToolBar] 事件:
procedure TMainForm.toolbarItemClick(Sender: TObject);
begin
  toolbarItem.Checked := not toolbarItem.Checked ;
  ToolBar2.Visible := toolbarItem.Checked;
end; 
  
[MainMenu1.OnChange] 事件
procedure TMainForm.MainMenu1Change(...);
begin
  filePrintItem.Enabled := MDIChildCount>0;
  DrawItem.Enabled := MDIChildCount>0;
end;

[TMainForm.FormCreate] 事件
procedure TMainForm.FormCreate(Sender: TObject);
begin
  CaptureNum:=0;
  DefaultDirectory:=ExtractFilePath(application.ExeName);
end;
  
[TMainForm.FileOpen] 事件
procedure TMainForm.OpenDialogExecute(Sender: TObject);
begin
  OpenDialog.InitialDir := DefaultDirectory;
  if OpenDialog.Execute then
  begin
   DefaultDirectory:=ExtractFileName(OpenDialog.FileName);
   CreateMDIChild(OpenDialog.FileName,false);
  end;;
end;

[TMainForm.FileSave、TMainForm.FileSaveAs] 事件
procedure TMainForm.FileSave1Execute(Sender: TObject);
begin
  with ActiveMDIChild as TMDIChild do begin
   FileName:=ExtractFileName(caption);
   FileName:=DefaultDirectory+FileName;
   SaveDialog.FileName:=FileName;
   if not SaveDialog.Execute then exit;
   FileName:=SaveDialog.FileName ;
   DefaultDirectory:=ExtractFileName(FileName);
   if FileExists(FileName)then begin
    if MessageDlg(FileName+' 已存在,替换它吗?',mtInformation,[mbYES,mbNO],0)=mrYES then
     DeleteFile(FileName)
    else exit;
   end;
   Image1.Picture.saveToFile(FileName);
   Caption:=FileName;
   StatusBar.SimpleText := FileName;
  end;
end;

Tags:Delphi 图象 截取

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接