private bool mouseInEllipse = false ; // 鼠标是否在圆形中 private Rectangle rectEllipse = new Rectangle( 405 , 259 , 40 , 40 ); // 圆形区域 初始化 #region 初始化private void Examination_Load(object sender, EventArgs e) ...{ fuya(1); } #endregion 判断鼠标是否进入Graphics绘制的图片并计算角度 #region 判断鼠标是否进入Graphics绘制的图片并计算角度private void panel1_MouseMove(object sender, MouseEventArgs e)...{ GraphicsPath vGraphicsPath = new GraphicsPath(); vGraphicsPath.AddEllipse(rectEllipse); // 添加圆形路径 Region vRegion = new Region(vGraphicsPath); mouseInEllipse = vRegion.IsVisible(e.Location); // 判断点是否在圆中 if (mouseInEllipse==true) ...{ double ltx = (e.Location.X - 405 - 20); double lty = (e.Location.Y - 259 - 20); //左边 if (ltx > 0) ...{ //左上 if (lty < 0) ...{ double ltyy = -lty; int va = Convert.ToInt16(Math.Round(Math.Atan2(ltx, ltyy) * (180 / Math.PI), 0)); fuya(va); } //左下 if (lty > 0) ...{ int va =90+Convert.ToInt16(Math.Round(Math.Atan2(lty, ltx) * (180 / Math.PI), 0)); fuya(va); } } //右边 if (ltx < 0) ...{ //右下 if (lty > 0) ...{ int va = 90 + Convert.ToInt16(Math.Round(Math.Atan2(lty, ltx) * (180 / Math.PI), 0)); fuya(va); } //右上 if (lty <0) ...{ int va = 90+ Convert.ToInt16(Math.Round(Math.Atan2(lty, ltx) * (180 / Math.PI), 0)); fuya(va); } } } }#endregion 根据角度绘制图片 #region 根据角度绘制图片 public void fuya(int va) ...{ this.pictureBox4.Visible = false; Graphics graphics = this.panel1.CreateGraphics(); /**/////装入图片 Bitmap image = HealthManage.Properties.Resources.Button_Adjustment1; //获取当前窗口的中心点 Rectangle rect = new Rectangle(0, 0, this.pictureBox4.ClientSize.Width, this.pictureBox4.ClientSize.Height); PointF center = new PointF(this.pictureBox4.Location.X + rect.Width / 2, this.pictureBox4.Location.Y + rect.Height / 2); float offsetX = 0; float offsetY = 0; offsetX = center.X - image.Width / 2; offsetY = center.Y - image.Height / 2; //构造图片显示区域:让图片的中心点与窗口的中心点一致 RectangleF picRect = new RectangleF(offsetX, offsetY, image.Width, image.Height); PointF Pcenter = new PointF(picRect.X + picRect.Width / 2, picRect.Y + picRect.Height / 2); // 绘图平面以图片的中心点旋转 graphics.TranslateTransform(Pcenter.X, Pcenter.Y); graphics.RotateTransform(va); //恢复绘图平面在水平和垂直方向的平移 graphics.TranslateTransform(-Pcenter.X, -Pcenter.Y); //绘制图片并延时 graphics.DrawImage(image, picRect); Thread.Sleep(100); //重置绘图平面的所有变换 graphics.ResetTransform(); }#endregion