VB.Net by API/System.Drawing/Pen
Содержание
New Pen(Brush brush1, Int Width)
<source lang="vbnet"> Imports System Imports System.Drawing Imports System.Windows.Forms Imports System.Drawing.Text Public Class MainClass
Shared Sub Main() Dim myform As Form = New FrmDrawing() Application.Run(myform) End Sub " Main
End Class Public Class FrmDrawing
Inherits System.Windows.Forms.Form Public Sub New() MyBase.New() Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.BackColor = System.Drawing.SystemColors.AppWorkspace Me.ClientSize = New System.Drawing.Size(472, 157) End Sub Protected Overrides Sub OnPaint(ByVal paintEvent As PaintEventArgs) Dim graphicsObject As Graphics = paintEvent.Graphics Dim rectangle1 As Rectangle = New Rectangle(15, 35, 80, 80) Dim brush1 As SolidBrush = New SolidBrush(Color.Firebrick) Dim pen1 As Pen = New Pen(brush1, 1) Dim brush2 As SolidBrush = New SolidBrush(Color.DarkBlue) Dim pen2 As Pen = New Pen(brush2, 1) " start at 0 and sweep 360 degrees graphicsObject.DrawRectangle(pen1, rectangle1) graphicsObject.DrawArc(pen2, rectangle1, 0, 360) End Sub " OnPaint
End Class " FrmDrawing
</source>
New Pen(Color c, Int width)
<source lang="vbnet"> Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms public class DrawCircle
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 a As Graphics = e.Graphics Dim mypen As Pen Dim myrect As RectangleF mypen = New Pen(System.Drawing.Color.Red, 6) a = Me.CreateGraphics a.Clear(Me.BackColor) a.DrawEllipse(mypen, 100, 100, 50, 50) a.DrawEllipse(mypen, 75, 75, 100, 100) a.DrawEllipse(mypen, 25, 25, 200, 200) a.DrawEllipse(mypen, 0, 0, 250, 250) myrect.X = 300 myrect.Y = 10 myrect.Width = 250 myrect.Height = 100 a.DrawEllipse(mypen, myrect) myrect.X = 400 myrect.Y = 10 myrect.Width = 100 myrect.Height = 250 a.DrawEllipse(mypen, myrect)
a.Dispose() mypen.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>
Pen.CompoundArray
<source lang="vbnet"> Imports System Imports System.Collections Imports System.ruponentModel Imports System.Windows.Forms Imports System.Data Imports System.Configuration Imports System.Resources Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Drawing.Imaging Imports System.Diagnostics Public Class MainClass
Shared Sub Main() Dim myform As Form = New CompoundForm() Application.Run(myform) End Sub
End Class Public Class CompoundForm
Inherits System.Windows.Forms.Form
- 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 = "CompoundForm" End Sub
- End Region
Private Sub CompoundForm_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles MyBase.Paint Dim g As Graphics = e.Graphics Dim pen As Pen = New Pen(Color.Black, 20) pen.rupoundArray = New Single() {0.0, 0.25, 0.45, 0.55, 0.75, 1.0} g.DrawRectangle(pen, New Rectangle(20, 20, Me.ClientRectangle.Width - 40, Me.ClientRectangle.Height - 40)) End Sub
End Class
</source>
Pen.CustomEndCap
<source lang="vbnet">
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class CustomLineCapLine
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 pts() As Point = { _ New Point(0, 0), _ New Point(2, 2), _ New Point(0, 0), _ New Point(2, -2) _ } Dim cap_path As New GraphicsPath cap_path.AddLines(pts) " Make the CustomLineCap. Dim x_cap As New CustomLineCap(Nothing, cap_path) " Draw some lines with x_cap. Dim the_pen As New Pen(Color.Black, 1) the_pen.CustomStartCap = x_cap the_pen.CustomEndCap = x_cap the_pen.Width = 20 e.Graphics.DrawLine(the_pen, 50, 200, 200, 200) 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>
Pen.CustomStartCap
<source lang="vbnet">
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class CustomLineCapLine
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 pts() As Point = { _ New Point(0, 0), _ New Point(2, 2), _ New Point(0, 0), _ New Point(2, -2) _ } Dim cap_path As New GraphicsPath cap_path.AddLines(pts) " Make the CustomLineCap. Dim x_cap As New CustomLineCap(Nothing, cap_path) " Draw some lines with x_cap. Dim the_pen As New Pen(Color.Black, 1) the_pen.CustomStartCap = x_cap the_pen.CustomEndCap = x_cap the_pen.Width = 20 e.Graphics.DrawLine(the_pen, 50, 200, 200, 200) 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>
Pen.DashCap
<source lang="vbnet"> Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms public class LineDashCap
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.DashStyle = DashStyle.DashDotDot blackPen.DashPattern = New Single() {10} blackPen.DashCap = DashCap.Triangle g.DrawLine(blackPen, 20, 10, 500, 10) blackPen.DashCap = DashCap.Flat g.DrawLine(blackPen, 20, 30, 500, 30) blackPen.DashCap = DashCap.Round g.DrawLine(blackPen, 20, 50, 500, 50) 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>
Pen.DashPattern
<source lang="vbnet"> Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms public class LineDashCap
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.DashStyle = DashStyle.DashDotDot blackPen.DashPattern = New Single() {10} blackPen.DashCap = DashCap.Triangle g.DrawLine(blackPen, 20, 10, 500, 10) blackPen.DashCap = DashCap.Flat g.DrawLine(blackPen, 20, 30, 500, 30) blackPen.DashCap = DashCap.Round g.DrawLine(blackPen, 20, 50, 500, 50) 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>
Pen.DashStyle
<source lang="vbnet"> Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Windows.Forms public class LineDashStyle
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 a As Graphics = e.Graphics Dim mypen As Pen mypen = New Pen(System.Drawing.Color.Red, 6) a = Me.CreateGraphics a.Clear(Me.BackColor) mypen.DashStyle = Drawing.Drawing2D.DashStyle.Custom a.DrawLine(mypen, 10, 10, 200, 10) mypen.DashStyle = Drawing.Drawing2D.DashStyle.Dash a.DrawLine(mypen, 10, 30, 200, 30) mypen.DashStyle = Drawing.Drawing2D.DashStyle.DashDot a.DrawLine(mypen, 10, 50, 200, 50) mypen.DashStyle = Drawing.Drawing2D.DashStyle.DashDotDot a.DrawLine(mypen, 10, 70, 200, 70) mypen.DashStyle = Drawing.Drawing2D.DashStyle.Dot a.DrawLine(mypen, 10, 90, 200, 90) mypen.DashStyle = Drawing.Drawing2D.DashStyle.Solid a.DrawLine(mypen, 10, 110, 200, 110) a.Dispose() mypen.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>