VB.Net/2D/Smooth — различия между версиями

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

Версия 16:40, 26 мая 2010

Draw Rectangle Smoothing Mode HighQuality

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()
    "
    "Form1
    "
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(504, 629)
    Me.Name = "Form1"
    Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
    Me.Text = "Form1"
  End Sub
#End Region
  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  End Sub
  Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
    Dim R1 As New Rectangle(10, 10, 40, 40)
    e.Graphics.SmoothingMode = SmoothingMode.HighQuality
    e.Graphics.DrawRectangle(Pens.Black, R1)
    e.Graphics.TranslateTransform(50.0F, 0.0F)
    e.Graphics.FillRectangle(Brushes.Black, R1)
    "Draw three rectangles
    Dim ThreeRects() As Rectangle = {New Rectangle(110, 10, 40, 40), _
                              New Rectangle(160, 10, 40, 40), _
                              New Rectangle(210, 10, 40, 40)}
    e.Graphics.ResetTransform()
    e.Graphics.DrawRectangles(Pens.Red, ThreeRects)
  End Sub

End Class


SmoothingMode Demo

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 x As Integer = 10
        Dim y As Integer = 10
        DrawCircle(e.Graphics, Drawing2D.SmoothingMode.Default, x, y)
        DrawCircle(e.Graphics, Drawing2D.SmoothingMode.HighSpeed, x, y)
        DrawCircle(e.Graphics, Drawing2D.SmoothingMode.None, x, y)
        x = 10
        y += 250
        DrawCircle(e.Graphics, Drawing2D.SmoothingMode.HighQuality, x, y)
        DrawCircle(e.Graphics, Drawing2D.SmoothingMode.AntiAlias, x, y)
    End Sub
    Private Sub DrawCircle(ByVal gr As Graphics, ByVal smoothing_mode As Drawing2D.SmoothingMode, ByRef x As Integer, ByRef y As Integer)
        gr.DrawString(smoothing_mode.ToString, Me.Font, Brushes.Black, x, y)
        gr.SmoothingMode = smoothing_mode
        gr.DrawEllipse(Pens.Black, x, y + 20, 200, 200)
        gr.FillEllipse(Brushes.Black, x + 30, y + 20, 200, 200)
        x += 300
    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(500, 500)
        Me.Name = "Form1"
        Me.Text = "Title"
        Me.ResumeLayout(False)
    End Sub
End Class


SmoothingMode = Drawing2D SmoothingMode AntiAlias

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

Public Class MainClass
   Shared Sub Main()
       Dim form1 As Form = New Form1()
       Application.Run(form1)
   End Sub " ValidationError
End Class
 
 

Public Class Form1
    Private Sub Form1_Paint(ByVal sender As Object, _
     ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Dim the_pen As New Pen(Color.Black, 10)
        e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
        e.Graphics.DrawEllipse(the_pen, 30, 50, 100, 100)
    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(292, 273)
        Me.Name = "Form1"
        Me.Text = "TransformArrow"
        Me.ResumeLayout(False)
    End Sub
End Class