シリアルポートから取得したデータに基づいてゲージを回転させようとしています。シリアル通信はうまく機能していて、ゲージを回転させるのに問題があります。スライダーバーで画像を回転させようとしていますが、まだ運がありません。現在、100ミリ秒ごとにトリガーしてこのコードを実行するタイマーを実装しています。ただし、sliderBarを移動しても、画面上の画像には何も起こりません。私がタイマーを使用している理由は、それが私の最終的な実装に使用するものだからです。Serialイベントの代わりにタイマーを使用してUI更新をトリガーすると、アプリケーションの実行がはるかにスムーズになります。
いつものようにどんな助けでも大歓迎です!
コンストラクターで...
public Form1()
{
InitializeComponent();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
imgpic = (Image)pictureBoxBase.Image.Clone(); // This is storing an image in a picture box...
foreach (int rate in baudRates)
{
brbox.Items.Add(rate);
}
timer.Tick += new EventHandler(timer_Tick);
timer.Interval = 100;
timer.Enabled = true;
timer.Start();
com.DataReceived += new SerialDataReceivedEventHandler(OnReceived);
}
次に、タイマーイベントで...
void timer_Tick(object sender, EventArgs e) // Again it is initially drawing the picture, but it does not rotate with the statusBar
{
Point test = new Point(0, 0);
Image img = new Bitmap(400, 400);
pictureBox1.Image = img;
Graphics g = Graphics.FromImage(pictureBox1.Image);
Matrix mm1 = new Matrix();
mm1.RotateAt((trackBar1.Value),new Point( 0,0),MatrixOrder.Append);
GraphicsPath gp = new GraphicsPath();
gp.Transform(mm1);
gp.AddPolygon(new Point[] { new Point(0, 0), new Point(imgpic.Width, 0), new Point(0, imgpic.Height) });
PointF[] pts = gp.PathPoints;
g.DrawImage(imgpic, test);
pictureBox1.Refresh();
}