VB.Net Tutorial/2D Graphics/SolidBrush

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

Color Brushes

Imports System
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Collections
Imports System.ruponentModel
Imports System.Windows.Forms
Imports System.Data
public class SolidBrushCreateFromColor
   public Shared Sub Main
        Application.Run(New BrushesForm)
   End Sub
End class
Public Class BrushesForm
    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()
        "
        "BrushesForm
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Name = "BrushesForm"
        Me.Text = "Form1"
    End Sub
#End Region

    Enum LinearGradientMode
        BackwardDiagonal
        ForwardDiagonal
        Horizontal
        Vertical
    End Enum
    Private Sub BrushesForm_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 / 5
        Dim whiteBrush As Brush = System.Drawing.Brushes.White
        Dim blackBrush As Brush = System.Drawing.Brushes.Black
        Dim b As Brush = New SolidBrush(Color.DarkBlue)
        g.FillRectangle(b, 0, 0, width, height)
        g.DrawString(b.ToString(), Me.Font, whiteBrush, 0, 0)
    End Sub
End Class

Create Brush with Color

Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class GDIObjectsCreateBrushFont
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class
Public Class Form1
    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        Dim canvas As Graphics = e.Graphics
        
        Dim brush1 As New SolidBrush(Color.DarkBlue)
        Dim font1 As New Font("Arial", 24, FontStyle.Bold Or FontStyle.Italic)
        canvas.DrawString("www.vbex.ru",font1, brush1, 120, 70)
        
        canvas = Nothing
    End Sub
End Class

<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form
    "Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected 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(610, 328)
        Me.Name = "Form1"
        Me.Text = "Creating Graphics Objects (Color, Pen, Font, Brush)"
        Me.ResumeLayout(False)
    End Sub
End Class

Draw string with Brushes.Maroon

Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class DrawStringWithMaroon
   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 fntText = New Font(New FontFamily("Times New Roman"), 48, FontStyle.Italic)
        e.Graphics.DrawString("Hello there!", fntText, Brushes.Maroon, 10, 100)
  End Sub
  Public Sub New()
    Me.ClientSize = New System.Drawing.Size(292, 273)
  End Sub
End Class

Transparent Brush

Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class AlphaBPensBrushes
   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 rect As New Rectangle(220, 30, 100, 50)
        Dim transPen As New Pen(Color.FromArgb(128, 255, 255, 255), 10)
        Dim totTransPen As New Pen(Color.FromArgb(40, 0, 255, 0), 10)
        g.DrawLine(transPen, 10, 30, 200, 30)
        g.DrawLine(totTransPen, 10, 50, 200, 50)
        g.FillRectangle(New SolidBrush(Color.FromArgb(40, 0, 0, 255)), rect)
        rect.Y += 60
        g.FillEllipse(New SolidBrush(Color.FromArgb(20, 255, 255, 0)), rect)
        Dim semiTransBrush As New SolidBrush(Color.FromArgb(90, 0, 50, 255))
        g.DrawString("String " + ControlChars.Lf + "Date: ", New Font("Verdana", 14), semiTransBrush, New RectangleF(20, 100, 300, 100))

        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