私はグラフ作成プログラムに取り組んでおり、ユーザーにグラフをすばやく効果的にカスタマイズしてもらいたいと思っています。私は彼らがそれを行うことを可能にするプロパティグリッドを作成しました。グラフのプロパティを入力しましたが、ユーザーにアクセスさせたくない特定の要素を削除しました。たとえば、ユーザーがユーザー補助オプションにアクセスできるようにしたくありません。これまでのところ私が持っているのは
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
magRadioBox.Checked = true;
PropertyGrid propertyGrid1 = new PropertyGrid();
propertyGrid1.CommandsVisibleIfAvailable = true;
propertyGrid1.Text = "Graph and Plotting Options";
propertyGrid1.PropertyValueChanged += propertyGrid1_PropertyValueChanged;
this.Controls.Add(propertyGrid1);
}
private void Form1_Load(object sender, EventArgs e)
{
this.Text = "MY Plot Program";
propertyGrid1.SelectedObject = chart1;
}
private void button1_Click(object sender, EventArgs e)
{//some code that is populating my chart(chart1) with data
.... //chart1 being filled with data
}
private void propertyGrid1_PropertyValueChanged(object s , PropertyValueChangedEventArgs e)
{
//Calling the method that will refresh my chart1
myChart.Invalidate();
}
上記のコードは私のフォーム用です。以下の「MyChart」クラスコードは、プロパティグリッドを設定します。チャートのすべてのプロパティを自動的に取得し、ユーザーに持たせたくないプロパティを「チェリーピック」することができます。[Browsable(false)]
namespace FFT_Plotter
{
[DefaultPropertyAttribute("Text")]
public class MyChart : Chart
{
public event EventHandler PropertyChanged;
private void OnPropertyChanged(object sender, EventArgs e)
{
EventHandler eh = propertyChanged;
if(eh !=null)
{
eh(sender, e);
}
[BrowsableAttribute(false)]
public new System.Drawing.Color BackColor
{
get { return BackColor; }//Here back color is just an example of a property, not necessarily one that I would make non-Browsable
set {
base.BackColor = value;
OnPropertyChanged(this,EventArgs.Empty);
}
}
}
}
上記のクラスでは、グラフのすべてのプロパティを含むプロパティグリッドがあり、適切と思われるプロパティを非表示にすることができます。しかし今、私はchart1
自分のプロパティグリッドに接続する方法を理解するのに行き詰まっています。例として、グリッドからtextプロパティを削除しました。ユーザーには表示されなくなります。BackColor
ここで、グリッドの変化を言うことができるようにしたいと思います。これは、chart1
バックカラーが変化することを意味します。