如何从单击修改为双击?谁能帮助我,对不起我的英语。
private void pbGraph_MouseClick(object sender, MouseEventArgs e)
{
// recorder
string tmpToRecord = "";
//initialize default brush and pen for drawing
//pen for making lines, brush to fill the region
Pen p = new Pen(Color.Blue,1);
SolidBrush brush = new SolidBrush(Color.Red);
//event triggered when left click
if (e.Button == MouseButtons.Left)
{
//limit nodes to 5 only
if (count < 100)
{
int currentNodeLocation = whereLocationIs(e.X, e.Y, 10, 10);
if (currentNodeLocation == 0)
{
//add mouse click position to the arraylist
//increase count everytime a node is created
count++;
//store coordinates temporarily
tmpToRecord = "0," + count.ToString() + "," + e.X.ToString() + "," + e.Y.ToString();
//store the coordinates based on event click to the array
arrayForNode[count] = new LocationNodes(e.X, e.Y);
//get graphics object for picturebox
Graphics.FromImage(pbGraph.Image).TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
//draw rectangle nodes
Graphics.FromImage(pbGraph.Image).FillEllipse(brush, arrayForNode[count].returnRectangle());
//draw numbers aside nodes
Graphics.FromImage(pbGraph.Image).DrawString(count.ToString(), new Font("Verdana", 8), brush, (float)e.X + 12, (float)e.Y + 12);
//give status report
labelStatus.Text = "Status: Node created " + count;
//dahSaveKe = false;
this.Changes = true;
}
}
else
{
MessageBox.Show("Maximum number of nodes reached");
}
}
//event triggered when right click
else if (e.Button == MouseButtons.Right)
{
//x denotes the location of node
int x = whereLocationIs1(e.X, e.Y);
if (x != 0)
{
if (firstNodeChecked == 0)
{
firstNodeChecked = x;
labelStatus.Text = "Selected Node: " + x.ToString();
}
else
{
if (firstNodeChecked == x)
{
firstNodeChecked = 0;
return;
}
labelStatus.Text = "Arc is created from " + firstNodeChecked.ToString() + " to " + x.ToString();
//FormArcValue fav = new FormArcValue();
//DialogResult dr = fav.ShowDialog(this);
//if (dr == DialogResult.OK)
//{
//limiter for drawing arc
if (count < (count * count))
{
AdjustableArrowCap bigArrow = new AdjustableArrowCap(5, 5);
p.CustomEndCap = bigArrow;
//draw line as arc to connect between 2 nodes
Graphics.FromImage(pbGraph.Image).DrawLine(p,
(arrayForNode[firstNodeChecked]._X + 5), (arrayForNode[firstNodeChecked]._Y + 5),
(arrayForNode[x]._X + 5), (arrayForNode[x]._Y + 5));
Point fa = writeStringInMiddleArcLine(new Point((arrayForNode[firstNodeChecked]._X),
(arrayForNode[firstNodeChecked]._Y)), new Point((arrayForNode[x]._X), (arrayForNode[x]._Y)));
//determine which distribution is selected, then
//generate random numbers
switch (comboCustomer1.Text)
{
case "Johnson SB":
cost = RandomNumber(costMin, costMax);
demand = RandomNumber(demandMin, demandMax);
break;
case "Uniform":
cost = RandomNumber(costMin, costMax);
demand = RandomNumber(demandMin, demandMax);
break;
}
//write cost and demand for arc
Graphics.FromImage(pbGraph.Image).DrawString("(" + demand.ToString("N2") + " , " +
cost.ToString("N2") +
") " + displayCount.ToString(), new Font("Verdana", 8), new SolidBrush(Color.Blue), fa.X, fa.Y);
matrixCost[x, firstNodeChecked] = cost;
matrixCost[firstNodeChecked, x] = cost;
matrixDemand[x, firstNodeChecked] = demand;
matrixDemand[firstNodeChecked, x] = demand;
//add count and assign demand to the temp matrix
matrixDemandDisplay[displayCount] = demand;
// put already linked nodes in here
linkedNodes[firstNodeChecked, x] = true;
linkedNodes[x, firstNodeChecked] = true;
// string to record the path
tmpToRecord = "1," + x.ToString() + "," + arrayForNode[x]._X.ToString() + "," + arrayForNode[x]._Y.ToString() +
"," + firstNodeChecked.ToString() + "," + arrayForNode[firstNodeChecked]._X.ToString() + "," +
arrayForNode[firstNodeChecked]._Y.ToString() + "," + demand.ToString() + "," + cost.ToString() + "," +
displayCount.ToString();
//increase counter
displayCount = displayCount + 1;
//this.Changes = true;
}
firstNodeChecked = 0;
//dahSaveKe = false;
}
//else if (dr == DialogResult.Cancel)
//{
// firstNodeChecked = 0;
//}
//labelStatus.Text = "Left click to draw node and right click to link a node";
//fav.Dispose();
}
}
if (!(tmpToRecord == ""))
{
if (!(recordPath == ""))
recordPath += "|";
recordPath += tmpToRecord;
}
pbGraph.Refresh();
}
谁能帮我?