GUIの作成 2
C1PropertyGridコントロールの切り替え表示処理
氏名のTextBlockコントロールを右クリックすると、C1PropertyGridコントロールの表示プロパティをそのコントロールのプロパティに切り替える処理を作成します。この処理は、ビハインドコードで行います。
すでに、TextBlockコントロールの右クリックのイベントハンドラは作成されていますので、この中のカラーピッカー処理コードと入れ替えます。処理としては、右クリックされたTextBlockコントロールのNameプロパティを取得し、これによってC1PropertyGridコントロールのVisibilityプロパティを切り替えます。
Private Sub TextBlock_MouseRightButtonDown(sender As System.Object, e As System.Windows.Input.MouseButtonEventArgs) Select Case sender.name Case "TextBlock2" C1PropertyGrid1.Visibility = Windows.Visibility.Visible C1PropertyGrid2.Visibility = Windows.Visibility.Hidden C1PropertyGrid3.Visibility = Windows.Visibility.Hidden C1PropertyGrid4.Visibility = Windows.Visibility.Hidden C1PropertyGrid5.Visibility = Windows.Visibility.Hidden C1PropertyGrid6.Visibility = Windows.Visibility.Hidden Case "TextBlock3" C1PropertyGrid2.Visibility = Windows.Visibility.Visible C1PropertyGrid1.Visibility = Windows.Visibility.Hidden C1PropertyGrid3.Visibility = Windows.Visibility.Hidden C1PropertyGrid4.Visibility = Windows.Visibility.Hidden C1PropertyGrid5.Visibility = Windows.Visibility.Hidden C1PropertyGrid6.Visibility = Windows.Visibility.Hidden Case "TextBlock4" C1PropertyGrid3.Visibility = Windows.Visibility.Visible C1PropertyGrid1.Visibility = Windows.Visibility.Hidden C1PropertyGrid2.Visibility = Windows.Visibility.Hidden C1PropertyGrid4.Visibility = Windows.Visibility.Hidden C1PropertyGrid5.Visibility = Windows.Visibility.Hidden C1PropertyGrid6.Visibility = Windows.Visibility.Hidden Case "TextBlock5" C1PropertyGrid4.Visibility = Windows.Visibility.Visible C1PropertyGrid1.Visibility = Windows.Visibility.Hidden C1PropertyGrid2.Visibility = Windows.Visibility.Hidden C1PropertyGrid3.Visibility = Windows.Visibility.Hidden C1PropertyGrid5.Visibility = Windows.Visibility.Hidden C1PropertyGrid6.Visibility = Windows.Visibility.Hidden Case "TextBlock6" C1PropertyGrid5.Visibility = Windows.Visibility.Visible C1PropertyGrid1.Visibility = Windows.Visibility.Hidden C1PropertyGrid2.Visibility = Windows.Visibility.Hidden C1PropertyGrid3.Visibility = Windows.Visibility.Hidden C1PropertyGrid4.Visibility = Windows.Visibility.Hidden C1PropertyGrid6.Visibility = Windows.Visibility.Hidden Case "TextBlock7" C1PropertyGrid6.Visibility = Windows.Visibility.Visible C1PropertyGrid1.Visibility = Windows.Visibility.Hidden C1PropertyGrid2.Visibility = Windows.Visibility.Hidden C1PropertyGrid3.Visibility = Windows.Visibility.Hidden C1PropertyGrid4.Visibility = Windows.Visibility.Hidden C1PropertyGrid5.Visibility = Windows.Visibility.Hidden End Select End Sub
private void TextBlock_MouseRightButtonDown(object sender, MouseButtonEventArgs e) { TextBlock tb = (TextBlock)sender; switch(tb.Name) { case "TextBlock2": C1PropertyGrid1.Visibility = System.Windows.Visibility.Visible; C1PropertyGrid2.Visibility = System.Windows.Visibility.Hidden; C1PropertyGrid3.Visibility = System.Windows.Visibility.Hidden; C1PropertyGrid4.Visibility = System.Windows.Visibility.Hidden; C1PropertyGrid5.Visibility = System.Windows.Visibility.Hidden; C1PropertyGrid6.Visibility = System.Windows.Visibility.Hidden; break; case "TextBlock3": C1PropertyGrid2.Visibility = System.Windows.Visibility.Visible; C1PropertyGrid1.Visibility = System.Windows.Visibility.Visible; C1PropertyGrid3.Visibility = System.Windows.Visibility.Hidden; C1PropertyGrid4.Visibility = System.Windows.Visibility.Hidden; C1PropertyGrid5.Visibility = System.Windows.Visibility.Hidden; C1PropertyGrid6.Visibility = System.Windows.Visibility.Hidden; break; case "TextBlock4": C1PropertyGrid3.Visibility = System.Windows.Visibility.Visible; C1PropertyGrid2.Visibility = System.Windows.Visibility.Hidden; C1PropertyGrid1.Visibility = System.Windows.Visibility.Hidden; C1PropertyGrid4.Visibility = System.Windows.Visibility.Hidden; C1PropertyGrid5.Visibility = System.Windows.Visibility.Hidden; C1PropertyGrid6.Visibility = System.Windows.Visibility.Hidden; break; case "TextBlock5": C1PropertyGrid4.Visibility = System.Windows.Visibility.Visible; C1PropertyGrid2.Visibility = System.Windows.Visibility.Hidden; C1PropertyGrid3.Visibility = System.Windows.Visibility.Hidden; C1PropertyGrid1.Visibility = System.Windows.Visibility.Hidden; C1PropertyGrid5.Visibility = System.Windows.Visibility.Hidden; C1PropertyGrid6.Visibility = System.Windows.Visibility.Hidden; break; case "TextBlock6": C1PropertyGrid5.Visibility = System.Windows.Visibility.Visible; C1PropertyGrid2.Visibility = System.Windows.Visibility.Hidden; C1PropertyGrid3.Visibility = System.Windows.Visibility.Hidden; C1PropertyGrid4.Visibility = System.Windows.Visibility.Hidden; C1PropertyGrid1.Visibility = System.Windows.Visibility.Hidden; C1PropertyGrid6.Visibility = System.Windows.Visibility.Hidden; break; case "TextBlock7": C1PropertyGrid6.Visibility = System.Windows.Visibility.Visible; C1PropertyGrid2.Visibility = System.Windows.Visibility.Hidden; C1PropertyGrid3.Visibility = System.Windows.Visibility.Hidden; C1PropertyGrid4.Visibility = System.Windows.Visibility.Hidden; C1PropertyGrid5.Visibility = System.Windows.Visibility.Hidden; C1PropertyGrid1.Visibility = System.Windows.Visibility.Hidden; break; } }
まとめ
C1PropertyGridコントロールは、このようにウィンドウにレイアウトされたコントロールを、アプリケーション実行時に操作することができるコントロールです。
面倒なダイアログボックス作成・処理なども必要なく、各コントロールへの連結やプロパティリスト作成など、とても簡単にこの機能を実装することが可能です。
インタラクティブなアプリケーションに仕上げたいという場合は、導入を検討されてはいかがでしょうか。