VB.Net Tutorial/2D Graphics/LineCap styles

Материал из VB Эксперт
Версия от 15:55, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

All LineCap styles

<source lang="vbnet">Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms public class LineCapsDemo

  public Shared Sub Main
       Application.Run(New LineCapsForm)
  End Sub

End class Public Class LineCapsForm

   Inherits System.Windows.Forms.Form
  1. Region " Windows Form Designer generated code "
   Public Sub New()
       MyBase.New()
       "This call is required by the Windows Form Designer.
       InitializeComponent()
       "Add any initialization after the InitializeComponent() call
   End Sub
   "Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
       If disposing Then
           If Not (components Is Nothing) Then
               components.Dispose()
           End If
       End If
       MyBase.Dispose(disposing)
   End Sub
   "Required by the Windows Form Designer
   Private components As System.ruponentModel.IContainer
   "NOTE: The following procedure is required by the Windows Form Designer
   "It can be modified using the Windows Form Designer.  
   "Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
       components = New System.ruponentModel.Container()
       Me.Text = "LineCapsForm"
       Me.ClientSize = New System.Drawing.Size(352, 600)
   End Sub
  1. End Region
   Private Sub LineCapsForm_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles MyBase.Paint
       Dim g As Graphics = e.Graphics
       Dim capNames As String() = System.Enum.GetNames(GetType(LineCap))
       Array.Sort(capNames)
       Dim x As Integer = 0
       Dim y As Integer = 0
       Dim width As Integer = Me.ClientRectangle.Width / 2
       Dim height As Integer = Me.ClientRectangle.Height / capNames.Length
       Dim capName As String
       For Each capName In capNames
           Dim pen As Pen = New Pen(Color.Black, 12)
           pen.EndCap = CType(System.Enum.Parse(GetType(LineCap), capName), LineCap)
           If pen.EndCap <> LineCap.AnchorMask Then
               g.DrawLine(pen, x, CInt(y + height * 2 / 3), CInt(x + width * 2 / 3), CInt(y + height * 2 / 3))
               g.DrawString(capName, Me.Font, Brushes.Black, x, y)
               y = y + height
           End If
       Next
   End Sub

End Class</source>

Get Line CapStyles

<source lang="vbnet">Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms public class GetCapStyles

  public Shared Sub Main
       Application.Run(New Form1)
  End Sub

End class public class Form1

 Inherits System.Windows.Forms.Form
 Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
       Dim g As Graphics = Me.CreateGraphics()
       g.Clear(Me.BackColor)
       Dim blackPen As New Pen(Color.Black, 10)
       blackPen.StartCap = LineCap.Triangle
       blackPen.EndCap = LineCap.Triangle
       g.DrawLine(blackPen, 20, 10, 200, 10)
       blackPen.StartCap = LineCap.Square
       blackPen.EndCap = LineCap.Square
       g.DrawLine(blackPen, 20, 30, 200, 30)
       blackPen.StartCap = LineCap.ArrowAnchor
       blackPen.EndCap = LineCap.ArrowAnchor
       g.DrawLine(blackPen, 20, 50, 200, 50)
       blackPen.StartCap = LineCap.DiamondAnchor
       blackPen.EndCap = LineCap.DiamondAnchor
       g.DrawLine(blackPen, 20, 70, 200, 70)
       blackPen.StartCap = LineCap.Flat
       blackPen.EndCap = LineCap.Flat
       g.DrawLine(blackPen, 20, 90, 200, 90)
       blackPen.StartCap = LineCap.Round
       blackPen.EndCap = LineCap.Round
       g.DrawLine(blackPen, 20, 110, 200, 110)
       blackPen.StartCap = LineCap.RoundAnchor
       blackPen.EndCap = LineCap.RoundAnchor
       g.DrawLine(blackPen, 20, 130, 200, 130)
       blackPen.StartCap = LineCap.Square
       blackPen.EndCap = LineCap.Square
       g.DrawLine(blackPen, 20, 150, 200, 150)
       blackPen.StartCap = LineCap.SquareAnchor
       blackPen.EndCap = LineCap.SquareAnchor
       g.DrawLine(blackPen, 20, 170, 200, 170)
       blackPen.StartCap = LineCap.Flat
       blackPen.EndCap = LineCap.Flat
       g.DrawLine(blackPen, 20, 190, 200, 190)
       " Dispose
       blackPen.Dispose()
       g.Dispose()
 End Sub
 Public Sub New()
  
   MyBase.New()
   Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
   Me.ClientSize = New System.Drawing.Size(292, 273)
   Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
 End Sub

End Class</source>

LineCap.NoAnchor, LineCap.Round, LineCap.RoundAnchor, LineCap.Square, LineCap.SquareAnchor, LineCap.Triangle

<source lang="vbnet">Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms public class LineCapAllStyles

  public Shared Sub Main
       Application.Run(New Form1)
  End Sub

End class public class Form1

 Inherits System.Windows.Forms.Form
 Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
       Dim x As Integer = 5
       Dim y As Integer = 17
       Dim the_pen As New Pen(Color.Black, 10)
       DrawLine(e.Graphics, x, y, Drawing2D.LineCap.NoAnchor)
       DrawLine(e.Graphics, x, y, Drawing2D.LineCap.Round)
       DrawLine(e.Graphics, x, y, Drawing2D.LineCap.RoundAnchor)
       DrawLine(e.Graphics, x, y, Drawing2D.LineCap.Square)
       DrawLine(e.Graphics, x, y, Drawing2D.LineCap.SquareAnchor)
       DrawLine(e.Graphics, x, y, Drawing2D.LineCap.Triangle)
   End Sub
   Private Sub DrawLine(ByVal gr As Graphics, ByRef x As Integer, ByRef y As Integer, ByVal style As Drawing2D.LineCap)
       Dim the_pen As New Pen(Color.Black, 10)
       the_pen.EndCap = style
       gr.DrawString(style.ToString, Me.Font, Brushes.Black, x, y - 5)
       gr.DrawLine(the_pen, x + 100, y, x + 150, y)
       y += 25
   End Sub
 Public Sub New()
  
   MyBase.New()
   Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
   Me.ClientSize = New System.Drawing.Size(292, 273)
   Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
 End Sub

End Class</source>

LineCap styles: LineCap.AnchorMask, LineCap.ArrowAnchor,LineCap.DiamondAnchor, LineCap.Flat

<source lang="vbnet">Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms public class LineCapAllStyles

  public Shared Sub Main
       Application.Run(New Form1)
  End Sub

End class public class Form1

 Inherits System.Windows.Forms.Form
 Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
       Dim x As Integer = 5
       Dim y As Integer = 17
       Dim the_pen As New Pen(Color.Black, 10)
       DrawLine(e.Graphics, x, y, Drawing2D.LineCap.AnchorMask)
       DrawLine(e.Graphics, x, y, Drawing2D.LineCap.ArrowAnchor)
       DrawLine(e.Graphics, x, y, Drawing2D.LineCap.DiamondAnchor)
       DrawLine(e.Graphics, x, y, Drawing2D.LineCap.Flat)
   End Sub
   Private Sub DrawLine(ByVal gr As Graphics, ByRef x As Integer, ByRef y As Integer, ByVal style As Drawing2D.LineCap)
       Dim the_pen As New Pen(Color.Black, 10)
       the_pen.EndCap = style
       gr.DrawString(style.ToString, Me.Font, Brushes.Black, x, y - 5)
       gr.DrawLine(the_pen, x + 100, y, x + 150, y)
       y += 25
   End Sub
 Public Sub New()
  
   MyBase.New()
   Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
   Me.ClientSize = New System.Drawing.Size(292, 273)
   Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
 End Sub

End Class</source>