【问题标题】:save PrintDialog configuration for next time open保存 PrintDialog 配置以备下次打开
【发布时间】:2023-03-08 03:28:01
【问题描述】:

我打开一个打印对话框,然后使用它设置打印信息;

 DialogResult result = PrintDialog.ShowDialog();

现在,我想在单击“应用”按钮时保存 printDialog 的信息。当我再次打开打印对话框时,以前设置的设置不应该改变。

【问题讨论】:

  • PrinterSettings 类具有 [Serializable] 属性。因此,您可以对其进行序列化以保留设置。或者只是将 PrintDialog.PrinterSettings 属性存储在一个变量中。

标签: c# .net-3.5 apply printdialog


【解决方案1】:

将该信息存储在某个文件中,下次打开应用程序时,检查文件是否包含所需信息,如果包含该信息,则在应用程序中使用该信息,否则从用户那里获取信息

string filename = "file.txt";
        PrintDialog pd = new PrintDialog();
        if (File.ReadAllText(filename).Count() > 0)
        {
            //printer setting should be applied using this file
            //read the filename line by line and apply the setting
            pd.PrinterSettings.PrinterName=""; //line 1 of file..
            .
            .
            .
            .
        }
        else
        {

            DialogResult result = pd.ShowDialog();
            if (result == DialogResult.OK)
            {
                StreamWriter sw = new StreamWriter(filename);
                sw.WriteLine(pd.PrinterSettings.PrinterName);

                .
                .
                .
                .
                sw.Close();
            }
        }

【讨论】:

  • 你能给我看代码示例吗,我看到打印对话框有很多信息要存储。
猜你喜欢
  • 2019-06-10
  • 1970-01-01
  • 1970-01-01
  • 2014-05-11
  • 2018-12-08
  • 1970-01-01
  • 2017-12-19
  • 1970-01-01
  • 2018-06-03
相关资源
最近更新 更多