Hier noch ein Beispiel das bei mir ohne Flackern läuft:
Public Class Form1
Dim shapes As New List(Of Shape)
Dim actShape As Line = Nothing
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
Me.DoubleBuffered = True
End Sub
Protected Overrides Sub OnPaint(ByVal e As _
System.Windows.Forms.PaintEventArgs)
MyBase.OnPaint(e)
For Each gr As Shape In Me.shapes
gr.draw(e.Graphics)
Next
End Sub
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
actShape = New Line(Pens.Black, e.Location, e.Location)
shapes.Add(actShape)
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
If actShape IsNot Nothing Then
actShape.EndPoint = e.Location
Invalidate()
End If
End Sub
Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
actShape.IsNewLine = False
actShape = Nothing
Invalidate()
End Sub
End Class
Public MustInherit Class Shape
Private _pen As Pen
Public Property Pen() As Pen
Get
Return _pen
End Get
Set(ByVal value As Pen)
_pen = value
End Set
End Property
Public Sub New(ByVal pen As Pen)
_pen = pen
End Sub
Public MustOverride Sub draw(ByRef g As Graphics)
End Class
Public Class Line
Inherits Shape
Private _startPoint As Point
Public Property StartPoint() As Point
Get
Return _startPoint
End Get
Set(ByVal value As Point)
_startPoint = value
End Set
End Property
Private _endPoint As Point
Public Property EndPoint() As Point
Get
Return _endPoint
End Get
Set(ByVal value As Point)
_endPoint = value
End Set
End Property
Private _isNewLine As Boolean
Public Property IsNewLine() As Boolean
Get
Return _isNewLine
End Get
Set(ByVal value As Boolean)
_isNewLine = value
End Set
End Property
Public Sub New(ByVal pen As Pen, ByVal sPoint As Point, ByVal ePoint As _
Point)
MyBase.new(pen)
_isNewLine = True
_startPoint = sPoint
_endPoint = ePoint
End Sub
Public ReadOnly Property Length() As Integer
Get
Return CInt(Math.Sqrt((_endPoint.X - _startPoint.X) ^ 2 + ( _
_endPoint.Y - _startPoint.Y) ^ 2))
End Get
End Property
Public ReadOnly Property CentralPoint() As Point
Get
Dim x As Integer = CInt(((_endPoint.X - _startPoint.X) / 2) + _
_startPoint.X)
Dim y As Integer = CInt(((_endPoint.Y - _startPoint.Y) / 2) + _
_startPoint.Y)
Return New Point(x, y)
End Get
End Property
Public Overrides Sub draw(ByRef g As Graphics)
If _isNewLine Then
g.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
Dim angle As Double = Math.Atan((_endPoint.Y - _startPoint.Y) / ( _
_endPoint.X - _startPoint.X)) / Math.PI * 180
If Length > 5 Then
g.RotateTransform(CSng(angle))
g.TranslateTransform(CentralPoint.X, CentralPoint.Y, _
Drawing2D.MatrixOrder.Append)
g.DrawString(Length.ToString, New Font("Verdana", 8.0F), _
Brushes.Black, 0, 0)
g.ResetTransform()
Else
g.DrawString(Length.ToString, New Font("Verdana", 8.0F), _
Brushes.Black, CentralPoint.X, CentralPoint.Y)
End If
End If
g.DrawLine(MyBase.Pen, _startPoint, _endPoint)
End Sub
End Class mfg
Jonny132
Auf der Suche nach einem Hilfreichen Tutorial? Dann schau vorbei, auf http://tuts4you.de |