У меня проблема с моим кодом.Я хочу очистить свою гистограмму, которая находится в дочернем классе, и установить новые параметры.Но когда я использую в основном классе FormResult formChild = new FormResult();
, а в следующем formChild.histogram.Series.Clear();
ничего не работает, и я не вижу результатов.
В основном классе:
private void stretchHistogram_Click(object sender, EventArgs e)
{
FormResult formChild = new FormResult();
formChild.histogram.Series.Clear();
formChild.histogram.Show();
}
И дочерний класс:
public partial class FormResult : Form
{
private const int MIN_VALUE = 0;
private const int MAX_VALUE = 255;
private int[] valueHistogram = new int[MAX_VALUE + 1];
public FormResult()
{
InitializeComponent();
}
private void FormResult_Load(object sender, EventArgs e)
{
var mainForm = new APOForm();
FormResult formResult = new FormResult();
formResult.Owner = this;
// Generate PictureBox
pictureBox.Image = Image.FromFile(mainForm.getMyPath());
pictureBox.SizeMode = PictureBoxSizeMode.Zoom;
pictureBox.Show();
// Change image for bitmap array
Bitmap bm = (Bitmap)pictureBox.Image;
// Create table for pixel value for histogram
for(int i=0; i<MAX_VALUE; ++i)
{
valueHistogram[i] = 0;
}
for (int x=0; x<bm.Width; ++x)
{
for(int y=0; y<bm.Height; ++y)
{
Color c = bm.GetPixel(x, y);
valueHistogram[c.R] += 1;
}
}
// ------------ Generate histogram
histogram.ChartAreas[0].AxisX.Minimum = MIN_VALUE;
histogram.ChartAreas[0].AxisX.Maximum = MAX_VALUE;
histogram.ChartAreas[0].AxisY.Minimum = 0;
histogram.Series.Clear();
histogram.Series.Add("S");
histogram.Series["S"].IsVisibleInLegend = false;
int maxAxisY = 0;
for (int i=0; i< MAX_VALUE+1; ++i)
{
if(maxAxisY < valueHistogram[i]) { maxAxisY = valueHistogram[i]; }
histogram.Series["S"].Points.AddXY(i, valueHistogram[i]);
}
histogram.ChartAreas[0].AxisY.Maximum = maxAxisY;
histogram.Show();
}
}