I'm trying to make an application in C# and when i try relating a control to this.Top it keeps adding the distance between the Form and the Screen's edge. What should i do so I could use the top of the Form as Top?

Part of Code:

 if (Cursor.Position.Y > (this.ClientRectangle.Top + pCsuszka2.Height / 2) && Cursor.Position.Y < (this.Height -  pCsuszka2.Height / 2))
        {

            pCsuszka2.Top = Cursor.Position.Y - (pCsuszka2.Height / 2);

        }
有帮助吗?

解决方案

If you're in one of the mouse event handlers, you can use the MouseEventArgs parameter. It seems to give you relative position on the form.

   private void Form1_MouseUp(object sender, MouseEventArgs e)
    {
        this.Text = e.X.ToString() + ", " + e.Y.ToString();
    }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top