首页 > 编程 > Delphi > 正文

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

2019-11-18 18:12:11
字体:
来源:转载
供稿:网友
 

(五)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;


上一篇:Delphi图象截取编程示例(4)

下一篇:Delphi图象截取编程示例(2)

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
学习交流
热门图片

新闻热点

疑难解答

图片精选

网友关注