I'm trying to make my own gauges that interface with x plane 11. So far i have managed to figure out how to get the values into my program such as speed. I then created a second form which consists of 2 png images, the background and the needle. I want to rotate the needle to display the relevant value.
Ive looked at this How do I rotate a picture in WinForms but the solutions seem to save the new image and non of them work as is and its beond my current scope with out any good understanding on image manipulation. What im looking for is a simple process to rotate the needle by say 1 degree for example:
Rotationfunction(picturebox2, 1)
In terms of the gauge itself there isnt much code so far:
private void airspeed_Load(object sender, EventArgs e)
{
pictureBox1.Controls.Add(pictureBox2);
pictureBox2.BackColor = Color.Transparent;
}
Now i have used one of the examples and got it to work however it is behaving strangley. the images show whats happening best.
https://i.stack.imgur.com/39IH2.jpg
Thanks to taw for finding this:
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 );
}
}
however i dont know how to implement it into my code? ive added the trackbap and the label but noting happens when i move the trackbar.