C#WINフォーム
<ショートカット>
F7キーでフォームのソースコードを開く
- コントロールから見た座標を得る方法(MouseMoveイベントを利用)
MouseMoveイベントを利用時、パラメータとして受け取る「MouseEventArgs」からLocationプロパティでマウス位置を得る事ができる
それ以外に以下の方法でも得られるがやらない方が良い
public Point ClientMousePosition
{
get { return PointToClient(Cursor.Position); }
}
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
Point point = Point.Empty;
point.X = ClientMousePosition.X - panel1.Location.X + panel1.HorizontalScroll.Value;
point.Y = ClientMousePosition.Y - panel1.Location.Y + panel1.VerticalScroll.Value;
label1.Text = point.ToString();
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.AcceptButton = this.showbutton;
this.CancelButton = this.closebutton;
}
最終更新:2012年09月07日 12:50