左键点击转化为角度

来源:互联网 发布:win7的c语言编程软件 编辑:程序博客网 时间:2024/05/16 07:05

一段将点击转化为角度的代码。


        private void AquaGauge_MouseClick(object sender, MouseEventArgs e)

        {
            if ( MouseButtons.Left == e.Button)
            {
                int ptx = e.X;
                int pty = e.Y;

                int cx = ((width) / 2) + x;
                int cy = ((height) / 2) + y;

                double theta = Math.Atan((double) (pty - cy)/(ptx - cx));
                double angle = GetTheta(theta);
                double paddingangle = 360.0f + angle;
                if(ptx < cx)
                {
                    paddingangle = 180.0f + angle;
                }
                if (theta < 0.0f)
                {
                    paddingangle = 360.0f + angle;
                }
                if ((ptx < cx) && (cy < pty))
                {
                    paddingangle = 180.0f + angle;
                }
                Value = (float)((MaxValue - MinValue)*((paddingangle - fromAngle)/(toAngle - fromAngle)));
                
            }
        }
原创粉丝点击