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 groupBox2 As System.Windows.Forms.GroupBox
Friend WithEvents manualPanel As System.Windows.Forms.Panel
Friend WithEvents automaticPanel As System.Windows.Forms.Panel
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.groupBox2 = New System.Windows.Forms.GroupBox()
Me.manualPanel = New System.Windows.Forms.Panel()
Me.automaticPanel = New System.Windows.Forms.Panel()
Me.groupBox2.SuspendLayout()
Me.SuspendLayout()
'
'groupBox2
'
Me.groupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.manualPanel})
Me.groupBox2.Dock = System.Windows.Forms.DockStyle.Fill
Me.groupBox2.Font = New System.Drawing.Font("Microsoft Sans Serif", 18.0!)
Me.groupBox2.Location = New System.Drawing.Point(155, 0)
Me.groupBox2.Name = "groupBox2"
Me.groupBox2.Size = New System.Drawing.Size(137, 266)
Me.groupBox2.TabIndex = 5
Me.groupBox2.TabStop = False
Me.groupBox2.Text = "Manual"
'
'manualPanel
'
Me.manualPanel.BackColor = System.Drawing.Color.White
Me.manualPanel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.manualPanel.Dock = System.Windows.Forms.DockStyle.Fill
Me.manualPanel.Font = New System.Drawing.Font("Microsoft Sans Serif", 18.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.manualPanel.Location = New System.Drawing.Point(3, 31)
Me.manualPanel.Name = "manualPanel"
Me.manualPanel.Size = New System.Drawing.Size(131, 232)
Me.manualPanel.TabIndex = 0
'MultiLineTextForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.groupBox2})
Me.Name = "MultiLineTextForm"
Me.Text = "MultiLineTextForm"
Me.groupBox2.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
Dim s As String = "Line 1" & vbCrLf & "Line 2" & vbCrLf & "Line 3"
Private Sub manualPanel_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles manualPanel.Paint
Dim g As Graphics = e.Graphics
Dim y As Single = 0
Dim arrPens As Pen() = New Pen() {Pens.Red, Pens.Green, Pens.Blue}
Dim line As String
For Each line In s.Split(vbCrLf)
Dim width As Single = manualPanel.ClientRectangle.Width
Dim height As Single = manualPanel.ClientRectangle.Height - y
Dim layoutRect As RectangleF = New RectangleF(0, y, width, height)
Dim format As StringFormat = New StringFormat(StringFormatFlags.NoWrap Or StringFormatFlags.DisplayFormatControl)
g.DrawString(line, Me.Font, Brushes.Black, layoutRect, format)
Dim size As SizeF = g.MeasureString(line, Me.Font, layoutRect.Size, format)
g.DrawRectangle(arrPens(CInt(y / Me.Font.GetHeight(g))), 0, y, size.Width, size.Height)
y = y + Me.Font.GetHeight(g)
Next
End Sub
Private Sub manualPanel_Layout(ByVal sender As Object, ByVal e As System.Windows.Forms.LayoutEventArgs) Handles manualPanel.Layout
Me.manualPanel.Refresh()
End Sub
End Class
|