Mega Code Archive

 
Categories / VB.Net / 2D Graphics
 

MultiLine Text Automatically Layout Demo

Imports System Imports System.ComponentModel Imports System.Windows.Forms Imports System.Data Imports System.Configuration Imports System.Drawing Imports System.Drawing.Drawing2D Imports System.Drawing.Text Imports System.Globalization Imports System.Text Imports System.Collections Public Class MainClass     Shared Sub Main()         Dim myform As Form = New MultiLineTextForm()         Application.Run(myform)     End Sub End Class Public Class MultiLineTextForm     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.ComponentModel.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.     Friend WithEvents groupBox1 As System.Windows.Forms.GroupBox     Friend WithEvents automaticPanel As System.Windows.Forms.Panel     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()         Me.groupBox1 = New System.Windows.Forms.GroupBox()         Me.automaticPanel = New System.Windows.Forms.Panel()         Me.groupBox1.SuspendLayout()         Me.SuspendLayout()         Me.groupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.automaticPanel})         Me.groupBox1.Dock = System.Windows.Forms.DockStyle.Left         Me.groupBox1.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!)         Me.groupBox1.Name = "groupBox1"         Me.groupBox1.Size = New System.Drawing.Size(152, 266)         Me.groupBox1.TabIndex = 3         Me.groupBox1.TabStop = False         Me.groupBox1.Text = "Automatic"         '         'automaticPanel         '         Me.automaticPanel.BackColor = System.Drawing.Color.White         Me.automaticPanel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D         Me.automaticPanel.Dock = System.Windows.Forms.DockStyle.Fill         Me.automaticPanel.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))         Me.automaticPanel.Location = New System.Drawing.Point(3, 31)         Me.automaticPanel.Name = "automaticPanel"         Me.automaticPanel.Size = New System.Drawing.Size(146, 232)         Me.automaticPanel.TabIndex = 0         '         'MultiLineTextForm         '         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)         Me.ClientSize = New System.Drawing.Size(162, 266)         Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.groupBox1})         Me.Name = "MultiLineTextForm"         Me.Text = "MultiLineTextForm"         Me.groupBox1.ResumeLayout(False)         Me.ResumeLayout(False)     End Sub #End Region     Dim s As String = "Line 1" & vbCrLf & "Line 2" & vbCrLf & "Line 3" & vbCrLf & "Line 4" & vbCrLf & "Line 5" & vbCrLf & "Line 6"     Private Sub automaticPanel_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles automaticPanel.Paint         Dim g As Graphics = e.Graphics         Dim layoutRect As RectangleF = RectangleF.op_Implicit(automaticPanel.ClientRectangle)         g.DrawString(s, Me.Font, Brushes.Black, layoutRect)         Dim size As SizeF = g.MeasureString(s, Me.Font, layoutRect.Size)         g.DrawRectangle(Pens.Black, 0, 0, size.Width, size.Height)     End Sub     Private Sub manualPanel_Layout(ByVal sender As Object, ByVal e As System.Windows.Forms.LayoutEventArgs) Handles automaticPanel.Layout         Me.automaticPanel.Refresh()     End Sub End Class