Use TrackBar to control the Scale : TrackBar « GUI « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » GUI » TrackBar 
14.41.2.Use TrackBar to control the Scale
Use TrackBar to control the Scale
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms

public class TrackBarScale
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class

Public Class Form1
    Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgsHandles DisplayScale.Scroll
        DrawingArea.Invalidate()
    End Sub

    Private Sub DrawingArea_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgsHandles DrawingArea.Paint
        Dim titleFont As Font
        Dim mainFont As Font
        Dim titleArea As Rectangle
        Dim textArea As Rectangle
        Dim titleFormat As StringFormat
        Const MainTitle As String = "www.java2java.com"

        titleFont = New Font("Arial"16, FontStyle.Bold)
        mainFont = New Font("Arial"12, FontStyle.Regular)

        titleArea = New Rectangle(00, DrawingArea.ClientRectangle.Width, titleFont.Height)
        textArea = New Rectangle(0, titleFont.Height * 1.4, DrawingArea.ClientRectangle.Width, DrawingArea.ClientRectangle.Height - (titleFont.Height * 1.4))

        e.Graphics.ScaleTransform(DisplayScale.Value, DisplayScale.Value)

        titleFormat = New StringFormat()
        titleFormat.Alignment = StringAlignment.Center
        e.Graphics.DrawString(MainTitle, titleFont, Brushes.Black, titleArea, titleFormat)
        titleFormat.Dispose()

        mainFont.Dispose()
        titleFont.Dispose()
    End Sub
End Class


<Global.Microsoft.VisualBasic.CompilerServices.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.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.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.LabelText = New System.Windows.Forms.Label
        Me.DisplayText = New System.Windows.Forms.TextBox
        Me.LabelScale = New System.Windows.Forms.Label
        Me.DisplayScale = New System.Windows.Forms.TrackBar
        Me.ActDisplay = New System.Windows.Forms.Button
        Me.DrawingArea = New System.Windows.Forms.PictureBox
        CType(Me.DisplayScale, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.DrawingArea, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'LabelText
        '
        Me.LabelText.AutoSize = True
        Me.LabelText.Location = New System.Drawing.Point(88)
        Me.LabelText.Name = "LabelText"
        Me.LabelText.Size = New System.Drawing.Size(3113)
        Me.LabelText.TabIndex = 0
        Me.LabelText.Text = "&Text:"
        '
        'LabelScale
        '
        Me.LabelScale.AutoSize = True
        Me.LabelScale.Location = New System.Drawing.Point(8144)
        Me.LabelScale.Name = "LabelScale"
        Me.LabelScale.Size = New System.Drawing.Size(3713)
        Me.LabelScale.TabIndex = 2
        Me.LabelScale.Text = "&Scale:"
        '
        'DisplayScale
        '
        Me.DisplayScale.Location = New System.Drawing.Point(48136)
        Me.DisplayScale.Maximum = 5
        Me.DisplayScale.Minimum = 1
        Me.DisplayScale.Name = "DisplayScale"
        Me.DisplayScale.Size = New System.Drawing.Size(10445)
        Me.DisplayScale.TabIndex = 3
        Me.DisplayScale.Value = 1
        '
        'DrawingArea
        '
        Me.DrawingArea.BackColor = System.Drawing.Color.White
        Me.DrawingArea.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.DrawingArea.Location = New System.Drawing.Point(1928)
        Me.DrawingArea.Name = "DrawingArea"
        Me.DrawingArea.Size = New System.Drawing.Size(328208)
        Me.DrawingArea.TabIndex = 5
        Me.DrawingArea.TabStop = False
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(532227)
        Me.Controls.Add(Me.DrawingArea)

        Me.Controls.Add(Me.DisplayScale)



        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.MaximizeBox = False
        Me.Name = "Form1"
        Me.Text = "Displaying Scaled Content"
        CType(Me.DisplayScale, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.DrawingArea, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
    Friend WithEvents LabelText As System.Windows.Forms.Label
    Friend WithEvents DisplayText As System.Windows.Forms.TextBox
    Friend WithEvents LabelScale As System.Windows.Forms.Label
    Friend WithEvents DisplayScale As System.Windows.Forms.TrackBar
    Friend WithEvents ActDisplay As System.Windows.Forms.Button
    Friend WithEvents DrawingArea As System.Windows.Forms.PictureBox

End Class
14.41.TrackBar
14.41.1.Get TrackBar value and LargeChange valueGet TrackBar value and LargeChange value
14.41.2.Use TrackBar to control the ScaleUse TrackBar to control the Scale
14.41.3.Link ProgressBar with a TrackBarLink ProgressBar with a TrackBar
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.