Current location - Trademark Inquiry Complete Network - Futures platform - Winform mouse hover event
Winform mouse hover event
I use ZedGraph to make drawings in the c# winform project.

At the node of the graph, I want to show the details of the node.

I changed the prompt information on the x axis to time format.

When the mouse hovers, the displayed content will change. The value of pt. ToString () is a long string of decimal values.

Here are all the mouse operation skills.

If you still don't understand, please open the event panel.

One by one. There is a Chinese explanation below.

C# code

Private void graph _Load (object sender, EventArgs e)

{

My pane. Title . Text = " test

My pane. XAxis . Title.Text = " time

My pane. YAxis . title . text = " temperature ";

My pane. XAxis . major grid . is visible = true;

My pane. Chart.Fill = new fill (color. White, color. Light gray, 45.0 f);

TextObj text = new TextObj(

"Zoom: mouse wheel \ nMove: middle mouse button \ nMenu: right mouse button",

0.05f, 0.95f, coordinate type. Chart score, Allighan. Left, Allighan. Bottom);

Words. font spec . string alignment = string alignment。 Near;

My pane. GraphObjList.Add (text);

zg 1。 IsShowHScrollBar = true

zg 1。 IsShowVScrollBar = true

zg 1。 IsAutoScrollRange = true

zg 1。 IsScrollY2 = true

zg 1。 IsShowPointValues = true// Mouse hover tip

string[] labelsy = { "0 "," 10 "," 20 "," 30 "," 40 " };

My pane. YAxis . scale . text labels = labelsy;

My pane. ya xis . major grid . is visible = true;

My pane. ya xis . minor grid . is visible = true;

My pane. ya xis . major TIC . is between labels = false;

//Manually add the mouse-over node event.

zg 1。 PointValueEvent += new ZedGraphControl. PointValueHandler(MyPointValueHandler);

zg 1。 Graphpane.yaxis.scaleformatevent+= new coordinate axis. ScaleFormatHandler(YScaleFormatEvent);

}

//Mouse Hover Node Event

Private string MyPointValueHandler (ZedGraph Control sender, GraphPane, CurveItem curve, int iPt)

{

Point pair pt = curve [ipt];

Return the curve. Label.Text+ "is" +pt.y.tostring ("f1")+"\ ntime is"+pt. x . ToString()+" ";

}

Private void button 4_Click (object sender, EventArgs e)

{

string sql = "select H_dataTime,s _ 4 from history log ";

Data table dt = SqlDbHelper. Query (sql). Table [0];

DataRowCollection dr = dt。 Ok;

Int count = dt. Number of rows. Count;

for(int I = 0; I < count; i++)

{

double x =(double)new XDate(DateTime。 Parse(dr[i][0]。 ToString()));

Double y = double. Parse(dr[i][ 1]。 ToString());

List. Add(x,y);

}

Lineitem mycurve = mypane。 Addcurve ("temperature",

List, color. Red, symbol type. Diamonds);

My pane. XAxis.Type = AxisType。 Date;

My pane. XAxis . scale . font spec . angle = 15;

zg 1。 axis change();

zg 1。 Refresh ();

}