2011-01-19 33 views
1

ラベルを印刷するプログラムがあり、プリンタの設定を保存/保存する必要があります。だから私はこのコードを持っている:Windowsフォームプログラムから印刷設定を保存する方法は?

private void printerToolStripButton_Click(object sender, EventArgs e) 
{ 
    PrintDialog dialog = new PrintDialog(); 
    dialog.ShowDialog(); 
} 

ユーザーは、(用紙サイズ、向きなど)とは、「OK」をクリックし、プリントダイアログ上で「OK」をクリックし、いくつかの変更を行い、プリンタを選択し、[プロパティ]ボタンをクリックします。

私の問題は、それらの変更が覚えていないということです...私はもう一度ボタンをクリックするか、彼らは消えて、アプリケーションを再起動すると...

、誰もがアプリケーションスコープでそれらを永続化する方法を知っていますか?または、アプリケーションスコープが不可能な場合は、システムにそれらを保存する方法(コントロールパネル - >プリンタ - >プリンタ - >環境設定を右クリックすると表示されます)

+0

どうやって、あなたは私のsoutionをまだ試しましたか? –

+0

こんにちは!今週は試してみます:) –

答えて

2

私は自分でinterface-driven serializationを使用できます。 ;)

my-xmlシリアル化プロパティを使用して、インターフェイス駆動シリアル化を拡張できます。ところで、インターフェイス継承を使用しているときは、インターフェイス駆動のシリアル化が便利です);

using System; 
using System.IO; 
using System.Windows.Forms; 

// download at [http://xmlserialization.codeplex.com/] 
using System.Xml.Serialization; 
namespace test 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
     } 

     [XmlRootSerializer("PrinterSettings")] 
     public interface IPrinterSettings 
     { 
      bool PrintToFile { get; set; } 
     } 

     private static readonly string PrinterConfigurationFullName = Path.Combine(Application.StartupPath, "PrinterSettings.xml"); 

     private void Form1_Load(object sender, EventArgs e) 
     { 
      if (File.Exists(PrinterConfigurationFullName)) 
      { 
       XmlObjectSerializer.Load<IPrinterSettings>(File.ReadAllText(PrinterConfigurationFullName), printDialog1); 
      } 
     } 

     private void Form1_FormClosed(object sender, FormClosedEventArgs e) 
     { 
      File.WriteAllText(PrinterConfigurationFullName, XmlObjectSerializer.Save<IPrinterSettings>(printDialog1)); 
     } 

     private void button1_Click(object sender, EventArgs e) 
     { 
      if (printDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) 
      { 
       // do required stuff here... 
      } 
     } 
    } 
} 
+0

私は知っていますが、アプリケーションの再起動の間にこの設定を覚えておく必要があります。それはプリンタのシステム設定に保存することで可能ですが、私はちょうどこれを行う方法がわかりません。 –

+0

いいえ、私はそれに応じて回答を編集します –

+0

さて、それは起動している!準備が整った;)最新のチェンジセットをダウンロードしてください。[http://xmlserialization.codeplex.com/SourceControl/changeset/changes/64484] –

関連する問題