EDN Admin
Well-known member
I have this event in Form1:
<pre class="prettyprint private void trackBar1_Scroll(object sender, EventArgs e)
{
trackbarCounter++;
if (manualDone == true)
{
myTrackPanelss1.trackBar1.Minimum = 0;
myTrackPanelss1.trackBar1.Maximum = _fi.Length - 1; //counter - 1;//list_of_histograms.Count-1;
setpicture(myTrackPanelss1.trackBar1.Value); //myTrackPanelss1.trackBar1.Value);
this.pictureBox1.Refresh();
}
if (automaticDone == true)
{
myTrackPanelss1.trackBar1.Minimum = 0;
myTrackPanelss1.trackBar1.Maximum = fiAutomatic.Length - 1;
long[] tt = list_of_histograms[myTrackPanelss1.trackBar1.Value];
HistogramGraphs1.histogram = tt;
//HistogramGraphs1.histogram = tt;
// histogramControl1.DrawHistogram(tt);
long res = GetTopLumAmount(tt, 1000);
long max = GetHistogramMaximum(tt);
GetHistogramAverage(tt);
setpicture(myTrackPanelss1.trackBar1.Value); this.pictureBox1.Refresh();
}
} [/code]
Now the code of the class HistogramGraphs:
<pre class="prettyprint using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZedGraph;
using Extracting_Frames;
namespace Lightnings_Extractor
{
public partial class Histogram_Graphs : Form
{
public long[] histogram;
public Histogram_Graphs()
{
InitializeComponent();
if (histogram == null)
{
histogram = Form1.GetHistogramValue;
}
this.DoubleBuffered = true;
CreateGraph_GradientByZBars(zedGraphControl1);
}
private void Histogram_Graphs_Load(object sender, EventArgs e)
{
this.Size = new Size(1900, 435);
this.Location = new Point(6, 606);
label2.Text = this.Size.ToString();
}
private void CreateGraph_GradientByZBars(ZedGraphControl z1)
{
GraphPane myPane = z1.GraphPane;
myPane.Title.Text = "Demonstration of Multi-Colored Bars with a Single BarItem";
myPane.XAxis.Title.Text = "Bar Number";
myPane.YAxis.Title.Text = "Value";
myPane.XAxis.Scale.MaxAuto = false;
myPane.XAxis.Scale.Min = 0;
myPane.XAxis.Scale.Max = 256;
myPane.YAxis.Scale.Min = 0;
myPane.YAxis.Scale.MaxAuto = false;
myPane.YAxis.Scale.Max = histogram[0];
PointPairList list = new PointPairList();
// Random rand = new Random();
for (int i = 0; i < histogram.Length; i++)
{
double x = (double)i;
double y = (double)histogram;
double z = 1;
list.Add(x, y, z);
}
BarItem myCurve = myPane.AddBar("Multi-Colored Bars", list, Color.Blue);
Color[] colors = { Color.Red, Color.Yellow, Color.Green, Color.Blue, Color.Purple };
myCurve.Bar.Fill = new Fill(colors);
myCurve.Bar.Fill.Type = FillType.GradientByZ;
myCurve.Bar.Fill.RangeMin = 0;
myCurve.Bar.Fill.RangeMax = 4;
myPane.Chart.Fill = new Fill(Color.White, Color.FromArgb(220, 220, 255), 45);
myPane.Fill = new Fill(Color.White, Color.FromArgb(255, 255, 225), 45);
// Tell ZedGraph to calculate the axis ranges
z1.AxisChange();
}
private void settings()
{
/*myPane.YAxis.Scale.MinAuto = true;
myPane.YAxis.Scale.MaxAuto = true;
myPane.YAxis.Scale.MajorStepAuto = true;
myPane.YAxis.Scale.MinorStepAuto = true;
myPane.YAxis.CrossAuto = true;
myPane.YAxis.Scale.MagAuto = true;
myPane.YAxis.Scale.FormatAuto = true;
myPane.XAxis.Scale.MinAuto = true;
myPane.XAxis.Scale.MaxAuto = true;
myPane.XAxis.Scale.MajorStepAuto = true;
myPane.XAxis.Scale.MinorStepAuto = true;
myPane.XAxis.CrossAuto = true;
myPane.XAxis.Scale.MagAuto = true;
myPane.XAxis.Scale.FormatAuto = true;
myPane.AxisChange();
z1.AxisChange();
z1.Invalidate();
zedGraphControl1.AxisChange();
zedGraphControl1.Invalidate();*/
}
private void Histogram_Graphs_SizeChanged(object sender, EventArgs e)
{
label2.Text = this.Size.ToString();
}
private void Histogram_Graphs_LocationChanged(object sender, EventArgs e)
{
label4.Text = this.Location.ToString();
}
}
}
[/code]
First im checking in the class if the variable histogram is null if so im updating it with one histogram.
Now i want to make that each time i move the trackBar scroll to the right it will update the histogram variable and make the whole process of the class so it will create a new histogram.
Each time i move the scroll of the trackBar ot the right its creating a new histogram and put it in the variable tt(tt is in Form1).
So i want that each time it will create a new histogram in the new class and also will display the new histogram in the ZedGraph.
Now when im moving the trackBar to the right nothing happen. I see the same graph of the first histogram all the time.
Can someone show me how to do it ?
Thanks. <hr class="sig danieli
View the full article
<pre class="prettyprint private void trackBar1_Scroll(object sender, EventArgs e)
{
trackbarCounter++;
if (manualDone == true)
{
myTrackPanelss1.trackBar1.Minimum = 0;
myTrackPanelss1.trackBar1.Maximum = _fi.Length - 1; //counter - 1;//list_of_histograms.Count-1;
setpicture(myTrackPanelss1.trackBar1.Value); //myTrackPanelss1.trackBar1.Value);
this.pictureBox1.Refresh();
}
if (automaticDone == true)
{
myTrackPanelss1.trackBar1.Minimum = 0;
myTrackPanelss1.trackBar1.Maximum = fiAutomatic.Length - 1;
long[] tt = list_of_histograms[myTrackPanelss1.trackBar1.Value];
HistogramGraphs1.histogram = tt;
//HistogramGraphs1.histogram = tt;
// histogramControl1.DrawHistogram(tt);
long res = GetTopLumAmount(tt, 1000);
long max = GetHistogramMaximum(tt);
GetHistogramAverage(tt);
setpicture(myTrackPanelss1.trackBar1.Value); this.pictureBox1.Refresh();
}
} [/code]
Now the code of the class HistogramGraphs:
<pre class="prettyprint using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZedGraph;
using Extracting_Frames;
namespace Lightnings_Extractor
{
public partial class Histogram_Graphs : Form
{
public long[] histogram;
public Histogram_Graphs()
{
InitializeComponent();
if (histogram == null)
{
histogram = Form1.GetHistogramValue;
}
this.DoubleBuffered = true;
CreateGraph_GradientByZBars(zedGraphControl1);
}
private void Histogram_Graphs_Load(object sender, EventArgs e)
{
this.Size = new Size(1900, 435);
this.Location = new Point(6, 606);
label2.Text = this.Size.ToString();
}
private void CreateGraph_GradientByZBars(ZedGraphControl z1)
{
GraphPane myPane = z1.GraphPane;
myPane.Title.Text = "Demonstration of Multi-Colored Bars with a Single BarItem";
myPane.XAxis.Title.Text = "Bar Number";
myPane.YAxis.Title.Text = "Value";
myPane.XAxis.Scale.MaxAuto = false;
myPane.XAxis.Scale.Min = 0;
myPane.XAxis.Scale.Max = 256;
myPane.YAxis.Scale.Min = 0;
myPane.YAxis.Scale.MaxAuto = false;
myPane.YAxis.Scale.Max = histogram[0];
PointPairList list = new PointPairList();
// Random rand = new Random();
for (int i = 0; i < histogram.Length; i++)
{
double x = (double)i;
double y = (double)histogram;
double z = 1;
list.Add(x, y, z);
}
BarItem myCurve = myPane.AddBar("Multi-Colored Bars", list, Color.Blue);
Color[] colors = { Color.Red, Color.Yellow, Color.Green, Color.Blue, Color.Purple };
myCurve.Bar.Fill = new Fill(colors);
myCurve.Bar.Fill.Type = FillType.GradientByZ;
myCurve.Bar.Fill.RangeMin = 0;
myCurve.Bar.Fill.RangeMax = 4;
myPane.Chart.Fill = new Fill(Color.White, Color.FromArgb(220, 220, 255), 45);
myPane.Fill = new Fill(Color.White, Color.FromArgb(255, 255, 225), 45);
// Tell ZedGraph to calculate the axis ranges
z1.AxisChange();
}
private void settings()
{
/*myPane.YAxis.Scale.MinAuto = true;
myPane.YAxis.Scale.MaxAuto = true;
myPane.YAxis.Scale.MajorStepAuto = true;
myPane.YAxis.Scale.MinorStepAuto = true;
myPane.YAxis.CrossAuto = true;
myPane.YAxis.Scale.MagAuto = true;
myPane.YAxis.Scale.FormatAuto = true;
myPane.XAxis.Scale.MinAuto = true;
myPane.XAxis.Scale.MaxAuto = true;
myPane.XAxis.Scale.MajorStepAuto = true;
myPane.XAxis.Scale.MinorStepAuto = true;
myPane.XAxis.CrossAuto = true;
myPane.XAxis.Scale.MagAuto = true;
myPane.XAxis.Scale.FormatAuto = true;
myPane.AxisChange();
z1.AxisChange();
z1.Invalidate();
zedGraphControl1.AxisChange();
zedGraphControl1.Invalidate();*/
}
private void Histogram_Graphs_SizeChanged(object sender, EventArgs e)
{
label2.Text = this.Size.ToString();
}
private void Histogram_Graphs_LocationChanged(object sender, EventArgs e)
{
label4.Text = this.Location.ToString();
}
}
}
[/code]
First im checking in the class if the variable histogram is null if so im updating it with one histogram.
Now i want to make that each time i move the trackBar scroll to the right it will update the histogram variable and make the whole process of the class so it will create a new histogram.
Each time i move the scroll of the trackBar ot the right its creating a new histogram and put it in the variable tt(tt is in Form1).
So i want that each time it will create a new histogram in the new class and also will display the new histogram in the ZedGraph.
Now when im moving the trackBar to the right nothing happen. I see the same graph of the first histogram all the time.
Can someone show me how to do it ?
Thanks. <hr class="sig danieli
View the full article