พอดีผม ลอกcode มาจาก link นี้ครับ
https://www.youtube.com/watch?v=TgnJK3hT1ks
Code (C#)
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;
namespace WindowsFormsApp6
{
public partial class Form1 : Form
{
Graphics g;
Pen p;
Point cursor;
int k = 0;
Point[] points = new Point[50];
public Form1()
{
InitializeComponent();
g = this.CreateGraphics();
p = new Pen(Color.Black, 3);
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
Cursor = this.PointToClient(Cursor.Position);
MouseStatus.Text = "X : " + Cursor.X + "Y : " + Cursor.Y;
}
}
}
ขึ้น Errorแบบนี้ครับ
Member 'Cursor.Position' cannot be accessed with an instance reference; qualify it with a type name instead
'Cursor' does not contain a definition for 'X' and no extension method 'X' accepting a first argument of type 'Cursor' could be found (are you missing a using directive or an assembly reference?)
Tag : .NET, Win (Windows App), C#, VS 2017 (.NET 4.x), Windows
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;
namespace WindowsFormsApp6
{
public partial class Form1 : Form
{
Graphics g;
Pen p;
Point cursor;
int k = 0;
Point[] points = new Point[50];
public Form1()
{
InitializeComponent();
g = this.CreateGraphics();
p = new Pen(Color.Black, 3);
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
MouseStatus.Text = "X : " + e.Location.X + "Y : " + e.Location.Y;
}
}
}
แต่ โชว์ พิกัด point xy เฉพาะใน label ครับ
ถ้าผมอยากให้แสดง พิกัด point xy ของทั้ง form อันนี้ผมต้องแก้ยังไงครับ