タイトル : 画面のちらつきを抑えたい 投稿日 : 2009/09/02(Wed) 09:55 投稿者 : 健
時計を描画するプログラムを作っているのですが、画面の更新時にちらつきが生じてしまいます。 何か防ぐ方法はありますでしょうか。 VB2008EEです。 == Imports System.Drawing.Drawing2D Public Class Form1 Private Sub Form1_Paint(ByVal sender As Object, _ ByVal e As System.Windows.Forms.PaintEventArgs) _ Handles MyBase.Paint Dim g As Graphics = e.Graphics g.TranslateTransform(ClientSize.Width / 2, ClientSize.Height / 2, MatrixOrder.Append) Const pai As Double = Math.PI Dim center As Point = New Point(0, 0) Dim time As DateTime = Now Dim secAng As Double = 2.0 * pai * time.Second / 60.0 Dim minAng As Double = 2.0 * pai * (time.Minute + time.Second / 60.0) / 60.0 Dim hourAng As Double = 2.0 * pai * (time.Hour + time.Minute / 60.0) / 12.0 Dim r As Integer = Math.Min(ClientSize.Width, ClientSize.Height) / 2 - 5 Dim secHandLength As Integer = CType(0.7 * r, Integer) Dim minHandLength As Integer = CType(0.9 * r, Integer) Dim hourHandLength As Integer = CType(0.5 * r, Integer) Dim secHand As Point = New Point(CType(secHandLength * Math.Sin(secAng), Integer), _ CType(-secHandLength * Math.Cos(secAng), Integer)) Dim minHand As Point = New Point(CType(minHandLength * Math.Sin(minAng), Integer), _ CType(-minHandLength * Math.Cos(minAng), Integer)) Dim hourHand As Point = New Point(CType(hourHandLength * Math.Sin(hourAng), Integer), _ CType(-hourHandLength * Math.Cos(hourAng), Integer)) Dim RedPen As Pen = New Pen(Color.Red, 2) g.DrawLine(RedPen, center, secHand) Dim BlackPen As Pen = New Pen(Color.Black, 5) g.DrawLine(BlackPen, center, minHand) 'Dim BlackPen As Pen = New Pen(Color.Black, 5) g.DrawLine(BlackPen, center, hourHand) Dim gaiwaku As Pen = New Pen(Color.Black, 5) Dim gaiwaku2 As Pen = New Pen(Color.Black, 3) g.DrawEllipse(gaiwaku, -r, -r, r * 2, r * 2) For i As Integer = 1 To 60 Dim ang As Double = 2.0 * pai * i / 60.0 Dim r2 As Integer = 0.9 * r If i Mod 5 <> 0 Then r2 += (r - r2) / 2 End If Dim p1 As Point = New Point(CType(r * Math.Sin(ang), Integer), _ CType(-r * Math.Cos(ang), Integer)) Dim p2 As Point = New Point(CType(r2 * Math.Sin(ang), Integer), _ CType(-r2 * Math.Cos(ang), Integer)) If i Mod 5 = 0 Then g.DrawLine(gaiwaku, p1, p2) Else g.DrawLine(gaiwaku2, p1, p2) End If Next 'Me.Refresh() End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Timer1.Tick Me.Refresh() End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles MyBase.Load Me.SetBounds(Me.Left, Me.Top, 301, 301, _ BoundsSpecified.Size) Dim path As New System.Drawing.Drawing2D.GraphicsPath() Me.Top = 0 Me.Left = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width - Me.Width '丸を描く path.AddEllipse(New Rectangle(21, 30, 258, 260)) '真ん中を丸くくりぬく 'path.AddEllipse(New Rectangle(100, 100, 100, 100)) Me.Region = New Region(path) End Sub End Class |