最近项目中需要实现在虚拟打印时,自动添加文件名
找了好多主要有两种方案
一:隐藏print操作中的自带的SaveFileDialog,自己创建一个,通过设置FileName实现,但是这种实现方式是在低版本的framework,winform中实现。
二: 通过FindWindow找到界面上的文件另存为界面,再通过层层FindWindowEx,找到你要修改值的control,最后通过sendmessage实现值的修改。
第一种方案:
我未能隐藏printDialog.PrintDocument操作中弹出来的文件另存为的框,不能实现我想要的效果
DialogResult userResp = printDialog.ShowDialog();
if (userResp == DialogResult.OK)
{
if (printDialog.PrinterSettings.PrinterName == "Microsoft Print to PDF")
{ // force a reasonable filename
string basename = Path.GetFileNameWithoutExtension(myFileName);
string directory = Path.GetDirector