VB.Net by API/System.Drawing.Drawing2D/GraphicsPath — различия между версиями

Материал из VB Эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 12:51, 26 мая 2010

GraphicsPath.AddArc

  

Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class GettingGraphicsPathProperties
   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 greenPen As New Pen(Brushes.Green, 3)
        Dim path As New GraphicsPath
        Dim rect As New Rectangle(20, 20, 200, 100)
        path.AddLine(20, 30, 150, 70)
        path.AddArc(10, 10, 100, 50, 0, 180)
        path.AddRectangle(rect)
        g.DrawPath(greenPen, path)
        " Getting GraphicsPath properties
        Console.WriteLine(path.FillMode)
        Console.WriteLine(path.PathData)
        Console.WriteLine(path.PathPoints)
        Console.WriteLine(path.PathTypes)
        Console.WriteLine(path.PointCount)
        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


GraphicsPath.AddBeziers

  
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
Public Class MainClass
    Shared Sub Main()
        Dim myform As Form = New Form1()
        Application.Run(myform)
    End Sub
End Class
Public Class Form1
    Inherits System.Windows.Forms.Form
    Public Sub New()
        MyBase.New()

        "Add any initialization after the InitializeComponent() call
        Me.SetStyle(ControlStyles.ResizeRedraw, True)
        Me.SetStyle(ControlStyles.DoubleBuffer, True)
        Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
    End Sub
    Private Function GetClosedBezierPath(ByVal rect As Rectangle, ByVal points As Point()) As GraphicsPath
        Dim path As GraphicsPath = New GraphicsPath()
        path.AddBeziers(points)
        path.CloseFigure()
        Return path
    End Function
    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles MyBase.Paint
        Dim g As Graphics = e.Graphics
        Dim width As Integer = Me.ClientRectangle.Width
        Dim height As Integer = Me.ClientRectangle.Height
        Dim rect As Rectangle = New Rectangle(10, 10, width - 20, height - 20)
        Dim format As StringFormat = New StringFormat()
        format.Alignment = StringAlignment.Center
        format.LineAlignment = StringAlignment.Center
        Dim path As GraphicsPath = GetClosedBezierPath(rect, New Point() {New Point(25, height - 25), New Point(width - 25, height - 25), New Point(25, 25), New Point(width - 25, 25)})
        g.FillPath(Brushes.Yellow, path)
        g.DrawPath(Pens.Black, path)
    End Sub
End Class


GraphicsPath.AddEllipse

  
Imports System
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Drawing2D

Public Class MainClass
  Shared Sub Main()
     Dim form1 As Form1 = new Form1
     Application.Run(form1)
  End Sub
  
End Class
Public Class Form1
  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()
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(352, 273)
    Me.Name = "Form1"
    Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
    Me.Text = "Form1"
    Me.ResumeLayout(False)
  End Sub
#End Region
   Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
    Dim G As Graphics = Me.CreateGraphics
    Dim R As New Rectangle(20.0F, 20.0F, 100.0F, 100.0F)
    Dim path As New GraphicsPath()
    G.Clear(Color.Gainsboro)
    path.AddEllipse(R)
    G.DrawPath(Pens.Black, path)
    G.SetClip(path)
    Dim F As New Font("Arial", 16)
    G.DrawString("www.vbex.ru", F, Brushes.DeepPink, 15, 25)
  End Sub
End Class


GraphicsPath.AddString

  
Imports System
Imports System.Windows.Forms
Imports System.Drawing.Text
Imports System.Drawing
Imports System.Drawing.Drawing2D
Public Class MainClass
    
    Shared Sub Main(ByVal args As String())
        Dim myform As Form = New Form1()
        Application.Run(myform)
    End Sub
End Class

Public Class Form1
    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        Dim txt As String = "www.vbex.ru"
        Dim graphics_path As New GraphicsPath
        graphics_path.AddString(txt, _
            New FontFamily("Times New Roman"), _
            FontStyle.Bold, 150, _
            New Point(0, 0), _
            New StringFormat)
        e.Graphics.SetClip(graphics_path)
        e.Graphics.FillRectangle(Brushes.White, Me.ClientRectangle)
        Dim rnd As New Random
        Dim x1, y1, x2, y2 As Integer
        For i As Integer = 1 To 800
            x1 = rnd.Next(0, Me.ClientSize.Width - 1)
            y1 = rnd.Next(0, Me.ClientSize.Height - 1)
            x2 = rnd.Next(0, Me.ClientSize.Width - 1)
            y2 = rnd.Next(0, Me.ClientSize.Height - 1)
            e.Graphics.DrawLine(Pens.Black, x1, y1, x2, y2)
        Next i
    End Sub
End Class

<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _
Partial Public Class Form1
    Inherits System.Windows.Forms.Form
    "Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing AndAlso components IsNot Nothing Then
            components.Dispose()
        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()
        Me.SuspendLayout()
        "
        "Form1
        "
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(200, 200)
        Me.Name = "Form1"
        Me.Text = "Title"
        Me.ResumeLayout(False)
    End Sub
End Class