2015-10-05 52 views
1

我打開一個PrintDialog對話框,然後使用此設置打印信息;保存PrintDialog配置下次打開

DialogResult result = PrintDialog.ShowDialog(); 

現在,我想保存printDialog的信息,當我點擊'應用'按鈕。而當我再次打開printDialog框時,顯然設置的設置不應該改變。

+0

PrinterSettings類具有[Serializable]屬性。所以你可以序列化它來保存設置。或者只是將PrintDialog.PrinterSettings屬性存儲在一個變量中。 –

回答

0

存儲在一些文件,下一次當你打開你的應用程序,檢查文件是否包含所需信息,如果它包含的信息,然後利用這些信息在其他應用程序從用戶那裏得到它的信息

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(); 
      } 
     } 
+0

你可以告訴我代碼示例,我看到打印對話框有這麼多的信息存儲。 –