0

データベースに関するメタデータを表示するレポートをユーザーが作成できるようにするアプリケーションを作成しています。ユーザーは、アプリケーション インターフェイスを介してレポートを作成し、別のアプリケーションで使用するためにいつでも設定をファイルに保存できることが期待されます。

今、私は周りを検索し、アプリケーションの設定などに関する記事を見てきましたが、私の質問 (私は信じています) は何か違うものです:

ユーザーがレポートを作成したいアイテムを選択したとします。プログラムが再度実行されたときにユーザーが設定を開くことができるように、それらの選択 (ラジオ ボタンを使用して作成) を設定ファイルに保存するにはどうすればよいですか?ファイルを作成し、以前の設定を別のレポートに使用できるようにします。また、ユーザーが実行時にレポートのページ レイアウトを構成できるようにし、将来的に他の用途に使用できるように設定ファイルに含めるようにしたいと考えています。

私の説明が適切であることを願っています。タスクを設定した人の言葉遣いが多すぎるため、自分でタスクを理解するのに少し苦労していますが、残念ながら、私たちは持っているものに取り組んでいます!

4

1 に答える 1

2

You can store any serialiable content in your user settings. So just define your user selection class, and your Page layout class, and you can make it persistent like any string or integer.
(you can see how here : Custom enum as application setting type in C#? )

Edit : In this post, you can see that you might use any object in your preferences, including one that you defined yourself in your project. To do that, you have to provide the full class name, including the NameSpace of your project (MyNameSpace.MyPreferenceStorageClass) .

Edit 2 : So i will describe more with little example.
1) you have to define a class that will store your settings. I choose arbitrary names for my example :

Public Class UserChoices
    Public Property DisplayInColor As Boolean = False
    Public Property UseKeyboard As Boolean = True
End Class

Be sure to put a default value. You need to do a successfull compile after writing your class for the class to be inside current namespace.

2) then go into the Settings Window of your project. Add a settings variable with the Name you want.
I called it AppUserChoices. Then choose the type, go to 'Browse', then type MyNameSpace.UserChoices as a type.
(Obviously, replace 'MyNameSpace' by your namespace... ;-) )

3) you're done. I've written a little code to play with the settings (i put it in the Startup event handler of my Application ):

Launch it several times. The first time, it should report that user choices are nothing. Then they will be ok, and the color setting will switch each time beetween color and B&W.

   Private Sub Application_Startup
                   (ByVal sender As System.Object, ByVal e As System.Windows.StartupEventArgs)
        If My.Settings.AppUserChoices Is Nothing Then
            MessageBox.Show("AppUserChoices is nothing")
            My.Settings.AppUserChoices = New UserChoices
            My.Settings.Save()
        Else
            MessageBox.Show("AppUserChoices is  **not** nothing")
            My.Settings.AppUserChoices.DisplayInColor = Not My.Settings.AppUserChoices.DisplayInColor
            My.Settings.Save()
            If My.Settings.AppUserChoices.DisplayInColor Then _
                      MessageBox.Show("show colors") _
                Else _
                      MessageBox.Show("show in B&W")
        End If
    End Sub

4) Note that you might want to have the UserChoices class to implement INotifyPropertyChange, in case you modify them in the code. ( Example : if user changes 'DisplayInColor', you might want to set 'PrintInColor' to the same value. )

5) for the preference the user has for page layout, create also a class to store the Layout preferences and a new item in the Settings in the same way.

6) for binding to a settings value, well, let another StackOverflow post do the job : Bind to a value defined in the Settings

于 2012-08-21T08:34:06.887 に答える