I added now start point end point and mouse x and mouse y variables i want to use them to draw points on the chart control when clicking with the mouse on the left button.
But i want that the points to be draw only on the chart area and also only when the mouse is inside a square area in the chart so it will not draw a point on the squares borders lines or outside the chart control area.
And also to display when moving the mouse in the squares in the chart to show me the axis X and axis Y values on labels.
The left axis 1 to 120 present time and bottom axis 1 to 30 present days. So if i move the mouse in the first square area it should show me Day 1 Time 112 or Day 2 Time 33.
That's why i'm also not sure that the spaces in the axis X and axis Y are right. It should be 1 to 120 and 1 to 30 but i think every square should present inside 3 days and 120 time but in jumps of 1 steps of 1 so when i move with the mouse i can see in the first squares Day 1 Time 3 or Day 3 Time 66 The next row of squares will present days 4 to 6.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
namespace Test
{
public partial class Form1 : Form
{
private Point startPoint = new Point();
private Point endPoint = new Point();
private int mouseX = 0;
private int mouseY = 0;
public Form1()
{
InitializeComponent();
}
private void chart1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseX = System.Windows.Forms.Cursor.Position.X;
mouseY = System.Windows.Forms.Cursor.Position.Y;
chart1.Invalidate();
}
}
private void chart1_Paint(object sender, PaintEventArgs e)
{
Graphics g1 = this.CreateGraphics();
Pen linePen = new Pen(Color.Green, 1);
Pen ellipsePen = new Pen(Color.Red, 1);
startPoint = new Point(mouseX, mouseY);
endPoint = new Point(mouseX, mouseY);
g1.DrawLine(linePen, startPoint, endPoint);
g1.DrawEllipse(ellipsePen, mouseX - 2, mouseY - 2, 4, 4);
linePen.Dispose();
ellipsePen.Dispose();
g1.Dispose();
}
}
}
The way the code is now, the points it's drawing are far out of the Chart control area.