Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 仪表指针枢轴点_C#_Winforms - Fatal编程技术网

C# 仪表指针枢轴点

C# 仪表指针枢轴点,c#,winforms,C#,Winforms,我的数学能力不好。我在互联网上搜索过,但没有找到答案 我很难保持速度表式仪表指针的位置 仪表为半圆或180度。针是一个png图像,宽10像素,高164像素 该仪表宽378像素,高226像素 因为我试图旋转一个高矩形,所以必须重新计算针的位置 Point pivotPoint = new Point(gauge.Width / 2, gauge.Height); double degrees = -45; // example where to point the needle 有人能给我一些

我的数学能力不好。我在互联网上搜索过,但没有找到答案

我很难保持速度表式仪表指针的位置

仪表为半圆或180度。针是一个png图像,宽10像素,高164像素

该仪表宽378像素,高226像素

因为我试图旋转一个高矩形,所以必须重新计算针的位置

Point pivotPoint = new Point(gauge.Width / 2, gauge.Height); 
double degrees = -45; // example where to point the needle
有人能给我一些实际的C代码行吗?这些代码将保持指针的正确位置


非常感谢您的帮助。

以下是一些代码,可以将旋转的针图像绘制到带有仪表图像的图片框上

我从轨迹栏获取角度,从0到180

针竖直倒立:

  • 该角度弥补了我们开始时的90°偏移
  • 针的旋转点应与其原点一致
PictureBox.SizeMode设置为自动调整大小

private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
    using (Bitmap needle =  new Bitmap("D:\\needle3.png" )  )
    {
        int angle = trBar_angle.Value;
        label1.Text = angle.ToString("###0°");

        // this is the offset after the translation
        Point targetPoint = new Point(-needle.Width / 2, needle.Width / 2);

        // shortcuts for the sizes
        Size nSize = needle.Size;
        Size pSize = pictureBox1.ClientSize;

        // this is the translation of the graphic to meet the rotation point
        int transX = pSize.Width / 2;
        int transY = pSize.Height - nSize.Width / 2;

        //set the rotation point and rotate
        e.Graphics.TranslateTransform( transX, transY );
        e.Graphics.RotateTransform(angle + 90); 

        // draw on the rotated graphics
        e.Graphics.DrawImage(needle, targetPoint);

        //reset everything
        e.Graphics.RotateTransform( -angle - 90); 
        e.Graphics.TranslateTransform( -transX, -transY );

    }

}
我的针: 结果是:


我希望你的仪表比我做的好;-)

这里有另一个想法->将针的图像(具有透明背景)展开为正方形并旋转。这样你就不必重新计算位置了,它已经在一个透明的背景和一个矩形上了——我已经试过了一个正方形,但仍然没有帮助。谢谢。我的意思是你可以把图像放大,这样针就可以作为半径了。这样,当你旋转它时,中心将保持固定在你想要的位置。我想我现在知道你的意思了——如果我不能使它在数学上工作,我将使用一个大的盒子容器。我不知道为什么有人否决了这个。我还有其他的天赋,只是在努力学习。再次感谢。