private void Updats_Click(object sender, RoutedEventArgs e) { System.Windows.Forms.OpenFileDialog ofld = new System.Windows.Forms.OpenFileDialog(); ofld.Title = "请选择上传的图片"; //设置筛选的图片格式 ofld.Filter = "图片格式(*.jpg)|*.jpg|图片格式(*.png)|*.png"; //设置是否允许多选 ofld.Multiselect = false; if (ofld.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string text = ofld.FileName; if (text != "" || text != null) { this.tbPath.Text = text; int position = text.LastIndexOf("\\"); string fileName = text.Substring(position + 1); if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + @"Temp\")) { Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + @"Temp\"); } string tempFileName = AppDomain.CurrentDomain.BaseDirectory + @"Temp\" + "logo" + ".png"; try { File.Delete(tempFileName); File.Copy(this.tbPath.Text, tempFileName, true); } catch (Exception) { MessageWindow2.Show("图标文件需要在打印前设置"); } } } }
/// <summary> /// 静态方法 模拟MESSAGEBOX.Show方法 /// </summary> /// <param name="title">标题</param> /// <param name="msg">消息</param> /// <returns></returns> public static bool?Show(string msg) { var msgBox = new MessageWindow2(); msgBox.Message = msg; msgBox.ShowInTaskbar = false; return(msgBox.ShowDialog()); }
//FixedPage public static string SaveXPS(FlowDocument page, bool isSaved, string strType) { string containerName = GetXPSFromDialog(isSaved, strType); if (containerName != null) { try { File.Delete(containerName); } catch (Exception e) { MessageWindow2.Show(e.Message); } XpsDocument _xpsDocument = new XpsDocument(containerName, FileAccess.Write); XpsDocumentWriter xpsdw = XpsDocument.CreateXpsDocumentWriter(_xpsDocument); //xpsdw.Write(page);//写入XPS文件 xpsdw.Write(((IDocumentPaginatorSource)page).DocumentPaginator); _xpsDocument.Close(); } return(containerName); }