|
■No88540 (熊さん さん) に返信
> PictureBox1.Invalidate() を呼んでみましたがやはり残像が消えずに残ってしまいます。
現象を再現可能なサンプルを提示することはできますか?
とりあえず当方でも、
PictureBox1.SetBounds(-1, y, -1, h, BoundsSpecified.Y Or BoundsSpecified.Height)
および
PictureBox1.Bounds = New Rectangle(PictureBox1.Left, y, PictureBox1.Width, h)
の 2 パターンで実験コードを書いてみましたが「残像」を確認できませんでした。
※検証環境:.NET Framwork 4.7.2 / VS2017 15.8.2 / Win10 ver1803
Option Strict On
Partial Public Class Form1
Inherits Form
Private WithEvents NumericUpDown1 As New NumericUpDown()
Private WithEvents PictureBox1 As New PictureBox()
Public Sub New()
'説明のため、今回はデザイン時設定をコードで記載しています
'InitializeComponent()
NumericUpDown1.BeginInit()
NumericUpDown1.Tag = "Initializing"
NumericUpDown1.TextAlign = HorizontalAlignment.Right
NumericUpDown1.DecimalPlaces = 2
NumericUpDown1.Increment = 0.01D
NumericUpDown1.Minimum = 0.2D
NumericUpDown1.Value = 1D
NumericUpDown1.Maximum = 1.2D
NumericUpDown1.Font = New Font("Courier New", 21.0F)
PictureBox1.BackColor = Color.White
PictureBox1.BorderStyle = BorderStyle.FixedSingle
PictureBox1.SetBounds(50, 175, 250, 500)
PictureBox1.BackgroundImage = Icon.ToBitmap()
PictureBox1.BackgroundImageLayout = ImageLayout.Zoom
Controls.Add(NumericUpDown1)
Controls.Add(PictureBox1)
NumericUpDown1.EndInit()
NumericUpDown1.Tag = Nothing
Me.Size = New Size(400, 650)
'初期化処理中に ValueChanged が処理されないよう、イベントを手動で割り当てている
ResizePicture()
AddHandler NumericUpDown1.ValueChanged, AddressOf NumericUpDown1_ValueChanged
End Sub
Private Sub ResizePicture()
'PictureBox1.Top = 100 + CInt(500 * (1 - NumericUpDown1.Value) * 0.5)
'PictureBox1.Height = CInt(500 * NumericUpDown1.Value)
Dim y As Integer = 100 + CInt(250D * (1D - NumericUpDown1.Value))
Dim h As Integer = CInt(500 * NumericUpDown1.Value)
'PictureBox1.SetBounds(-1, y, -1, h, BoundsSpecified.Y Or BoundsSpecified.Height)
PictureBox1.Bounds = New Rectangle(PictureBox1.Left, y, PictureBox1.Width, h)
'リサイズされたので再描画を依頼
PictureBox1.Invalidate()
End Sub
Private Sub NumericUpDown1_ValueChanged(sender As Object, e As EventArgs) 'Handles NumericUpDown1.ValueChanged
ResizePicture()
End Sub
'DrawLine による描画処理。背景の塗り直しは行っていない。
Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
Dim r As Rectangle
r = PictureBox1.ClientRectangle 'PictureBox 全体
Using p As New Pen(Brushes.MediumTurquoise, 4)
For y = r.Top To r.Bottom Step Math.Max(r.Height \ 20, 1)
e.Graphics.DrawLine(p, r.Left, y, r.Right, y)
Next
End Using
r = e.ClipRectangle '可視エリアのみ
Using b As New SolidBrush(Color.FromArgb(218, Color.LightPink)), p As New Pen(b, 2)
For y = r.Top To r.Bottom Step Math.Max(r.Height \ 20, 1)
e.Graphics.DrawLine(p, r.Left, y, r.Right, y)
Next
End Using
End Sub
#Region "ClipRectangle が変更されたら再描画"
Private Sub PictureBox1_Resize(sender As Object, e As EventArgs) Handles PictureBox1.Resize
PictureBox1.Invalidate()
End Sub
Private Sub Form1_ResizeEnd(sender As Object, e As EventArgs) Handles Me.ResizeEnd
PictureBox1.Refresh()
End Sub
Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize
PictureBox1.Invalidate()
End Sub
#End Region
End Class
|