2018/09/08(Sat) 16:01:51 編集(投稿者)
ありがとうございます。
確かにこのコードだとほとんど残像が気になりませんね。
以下のコードが残像の出るコードです。
フォーム上に
PictureBox1とNumericUpDown1を配置して
ホイールでNumericUpDown1を回していただけますでしょうか?
すると位置が変化するはずのない赤色の中央線がぴくぴく動くことがご確認いただけると思います。
PictureBox1.Invalidate()
を
' PictureBox1.Refresh()
すると少しましにはなるのですが
やはりぴくぴく動いてしまいます。
Public Class Form6
Public YRate As Single
Public ProfilePosition As New XY_Profile
Public Class XY_Profile
Property X_Int As Integer
Property Y_Int As Integer
End Class
Private Sub Form6_Imaging_Load(sender As Object, e As EventArgs) Handles MyBase.Load
PBox1 = PictureBox1.Bounds
With NumericUpDown1
.Minimum = 10
.Maximum = 100
.DecimalPlaces = 0
.Increment = 3
.Value = 100
End With
PictureBox1.SizeMode = PictureBoxSizeMode.Zoom
ProfilePosition.X_Int = CInt((PictureBox1.Width - 3) / 2)
ProfilePosition.Y_Int = CInt((PictureBox1.Height - 3) / 2)
End Sub
Private PBox1 As Rectangle
Private pPen As New Pen(Color.FromArgb(60, Color.Red), 2)
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles PictureBox1.Paint
Dim Pbox As PictureBox = CType(sender, PictureBox)
Dim g As Graphics = e.Graphics
g.DrawLine(pPen, 0, ProfilePosition.Y_Int, Pbox.Width, ProfilePosition.Y_Int)
g.DrawLine(pPen, ProfilePosition.X_Int, 0, ProfilePosition.X_Int, Pbox.Height)
End Sub
Private Sub NumericUpDown1_ValueChanged(sender As Object, e As EventArgs) Handles NumericUpDown1.ValueChanged
YRate = NumericUpDown1.Value / 100
PictureBox1.SetBounds(PBox1.X, PBox1.Top + CInt(PBox1.Height * (1 - YRate) * 0.5), PBox1.Width, CInt(PBox1.Height * YRate))
ProfilePosition.Y_Int = CInt(0.5 * (PictureBox1.Height - 4))
' PictureBox1.Refresh()
PictureBox1.Invalidate()
End Sub
End Class