Re: How to pass more than two parameters in the event handler
- From: dondigitech LaPel <dlapel@xxxxxxxxxxxxxx>
- Date: Wed, 29 Oct 2008 13:31:50 -0700
I am also having a similar problem.I would like to pass in an extra
parameter in my event handler being that I need the information
(curveArray = 2d array where each array has 64 values) to plot graphs on
the user interface. So heress the low down, I have a class called
CurveData that does calculations on data read from a unit via serial
port and returns a 2D array (curveArray) in the method called
initializeIgnComm. That information is passed into the event handler
getCurvesToolStripMenuItem_Click1, sorted to a list, and that list is
used in plotCurves to generate a plot. I don?t know if this is the best
way to go about this but I am unable to think of a way to get this
curveArray data without passing parameters in. So here is the event
handler code in my main form file as well as methods called in the event
handler:
//EVENT HANDLER
private void getCurvesToolStripMenuItem_Click1(object sender, int[,]
curveArray)
{
comm.DisplayWindow = rtbDisplay;
try
{
if (serialPort1.IsOpen)
{
comm.initializeIgnComm(serialPort1);
plotCurves(zedGraphControl1, curveArray);
}
else
{
MessageBox.Show("Error: COM port closed.");
return; // bail out
}
}
catch (System.Exception ex)
{
MessageBox.Show("Error - findIgnButton_Click Exception:
" + ex);
}
}
#endregion
private void plotCurves(ZedGraphControl zgc, int[,] curveArray)
{
GraphPane plotCurve = zgc.GraphPane; //Get a
reference to the GraphPane
// Set the Titles
plotCurve.Title.Text = "DFS726 IGNITION TIMING\n";
plotCurve.XAxis.Title.Text = "RPM(x100)";
plotCurve.YAxis.Title.Text = "Advance Angle(Degrees BTDC)";
PointPairList curve1 = new PointPairList(); //Create
curve1 list
sortData(curveArray); //Sort data into
list for plotting
LineItem ignCurve = plotCurve.AddCurve("WOT Curve 4",
curve1, Color.Red, SymbolType.Diamond);
zgc.AxisChange();
}
#endregion
private PointPairList sortData(int[,] curveArray)
{
int numberOfCurves = 8;
int[,] advDegBTDC = new int[numberOfCurves,8];
int[,] rpmValues = new int[numberOfCurves,8];
int curveNumber = 0;
int arrayIndex = 0;
int genArrayIndex = 0;
// Copy data from rpmArray and advArray into rpmValues and
advDegBTDC arrays used for plots
for (curveNumber = 0; curveNumber < numberOfCurves;
curveNumber++)
{
for (arrayIndex = 0; arrayIndex < 8; arrayIndex++)
{
advDegBTDC[curveNumber,arrayIndex] =
curveArray[0,genArrayIndex];
rpmValues[curveNumber,arrayIndex] =
curveArray[1,genArrayIndex];
genArrayIndex++;
}
}
PointPairList list1 = new PointPairList();
// TEST: Just sending the first curve (8 data points) to
list1 to graph
for (int i = 0; i < 8; i++)
{
list1.Add(rpmValues[0,i], advDegBTDC[0,i]);
}
return list1;
}
I?ve only been using C# for a couple weeks so forgive me if my coding is
not up to proper standards. Thanks in advance!
*** Sent via Developersdex http://www.developersdex.com ***
.
- Follow-Ups:
- Re: How to pass more than two parameters in the event handler
- From: Jeff Johnson
- Re: How to pass more than two parameters in the event handler
- Prev by Date: Re: Inserting hyphens into a string - covering all possibilities.... please help!
- Next by Date: Stop Designer from popping up on a .cs file?
- Previous by thread: Simple way to update ToolTip and/or Caption (Text) of a form?
- Next by thread: Re: How to pass more than two parameters in the event handler
- Index(es):
Relevant Pages
|