我想在面板上畫一條線,因爲我在按住右鍵單擊按鈕的同時移動鼠標。這是我迄今爲止所嘗試的:在移動鼠標並按住右鍵單擊按鈕時繪製線條
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
Point point = panel1.PointToClient(Cursor.Position);
Point cordinatedClikedPoint = new Point(xPanelPosition, yPanelPositon);
DrawPoint((point.X), (point.Y), Color.Navy);
}
public void DrawPoint(int x, int y, Color color)
{
Graphics g = this.panel1.CreateGraphics();
Pen pen = new Pen(color);
g.DrawRectangle(pen, x, y, 3, 3);
}
請標記此問題,WinForms或WPF或Whatever。單獨的C#不會畫線。 –
是否有理由使用'PointToClient(Cursor.Location)'而不是'MouseEventArgs'提供的'e.Location'? – dreamlax