VB.Net/GUI/ScrollBar — различия между версиями

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

Текущая версия на 12:43, 26 мая 2010

Get HScrollBar Value

Imports System
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Imports System.Drawing.Imaging
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()
    AlphaScroll.Minimum = 20
    AlphaScroll.Maximum = 245
    AlphaScroll.SmallChange = 5
    AlphaScroll.LargeChange = 5
    GammaScroll.Minimum = 1
    GammaScroll.Maximum = 50
    GammaScroll.SmallChange = 1
    GammaScroll.LargeChange = 5

  End Sub
  Friend WithEvents GammaScroll As System.Windows.Forms.HScrollBar
  Friend WithEvents AlphaScroll As System.Windows.Forms.HScrollBar
  "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.GammaScroll = New System.Windows.Forms.HScrollBar()
    Me.AlphaScroll = New System.Windows.Forms.HScrollBar()
    Me.SuspendLayout()
    "
    "GammaScroll
    "
    Me.GammaScroll.Location = New System.Drawing.Point(32, 24)
    Me.GammaScroll.Name = "GammaScroll"
    Me.GammaScroll.Size = New System.Drawing.Size(96, 16)
    Me.GammaScroll.TabIndex = 0
    "
    "AlphaScroll
    "
    Me.AlphaScroll.Location = New System.Drawing.Point(32, 136)
    Me.AlphaScroll.Name = "AlphaScroll"
    Me.AlphaScroll.Size = New System.Drawing.Size(96, 16)
    Me.AlphaScroll.TabIndex = 1
    "
    "Form1
    "
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(292, 273)
    Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.AlphaScroll, Me.GammaScroll})
    Me.Name = "Form1"
    Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
    Me.Text = "Form1"
    Me.ResumeLayout(False)
  End Sub
#End Region

  Private Sub Form1_Load(ByVal sender As System.Object, _
                         ByVal e As System.EventArgs) _
                         Handles MyBase.Load
  End Sub
  Private Sub GammaScroll_Scroll(ByVal sender As System.Object, _
                          ByVal e As System.Windows.Forms.ScrollEventArgs) _
                          Handles GammaScroll.Scroll
    
    Console.WriteLine( CType(GammaScroll.Value / 10, Single) )
  End Sub
  Private Sub AlphaScroll_Scroll(ByVal sender As System.Object, _
                          ByVal e As System.Windows.Forms.ScrollEventArgs) _
                          Handles AlphaScroll.Scroll
    Console.WriteLine( AlphaScroll.Value )
  End Sub
End Class


Get Value from Vertical Scroll Bar

Imports System
Imports System.Data
Imports System.Windows.Forms
Imports System.Drawing
Public Class MainClass
    
    Shared Sub Main()
        Dim form1 As Form = New Form1
        Application.Run(form1)
    End Sub
End Class

Public Class Form1
    Private Sub hbarDays_ValueChanged(ByVal sender As Object, _
     ByVal e As System.EventArgs) Handles hbarDays.ValueChanged
        lblDays.Text = hbarDays.Value.ToString
    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.hbarDays = New System.Windows.Forms.HScrollBar
        Me.Label1 = New System.Windows.Forms.Label
        Me.lblDays = New System.Windows.Forms.Label
        Me.SuspendLayout()
        "
        "hbarDays
        "
        Me.hbarDays.Location = New System.Drawing.Point(8, 32)
        Me.hbarDays.Maximum = 109
        Me.hbarDays.Name = "hbarDays"
        Me.hbarDays.Size = New System.Drawing.Size(280, 16)
        Me.hbarDays.TabIndex = 0
        "
        "Label1
        "
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(8, 8)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(27, 13)
        Me.Label1.TabIndex = 1
        Me.Label1.Text = "Days"
        "
        "lblDays
        "
        Me.lblDays.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
        Me.lblDays.Location = New System.Drawing.Point(48, 8)
        Me.lblDays.Name = "lblDays"
        Me.lblDays.Size = New System.Drawing.Size(40, 16)
        Me.lblDays.TabIndex = 2
        Me.lblDays.Text = "0"
        "
        "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, 84)
        Me.Controls.Add(Me.lblDays)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.hbarDays)
        Me.Name = "Form1"
        Me.Text = "UseHScrollBar"
        Me.ResumeLayout(False)
        Me.PerformLayout()
    End Sub
    Friend WithEvents hbarDays As System.Windows.Forms.HScrollBar
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents lblDays As System.Windows.Forms.Label
End Class


ScrollBar Demo: get value

Imports System.Windows.Forms
Module Module1
    Sub Main()
        Application.Run(New Form1)
    End Sub
End Module
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.
    Friend WithEvents HScrollBar1 As System.Windows.Forms.HScrollBar
    Friend WithEvents VScrollBar1 As System.Windows.Forms.VScrollBar
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.HScrollBar1 = New System.Windows.Forms.HScrollBar()
        Me.VScrollBar1 = New System.Windows.Forms.VScrollBar()
        Me.TextBox1 = New System.Windows.Forms.TextBox()
        Me.TextBox2 = New System.Windows.Forms.TextBox()
        Me.SuspendLayout()
        "
        "HScrollBar1
        "
        Me.HScrollBar1.Location = New System.Drawing.Point(32, 112)
        Me.HScrollBar1.Maximum = 1000
        Me.HScrollBar1.Minimum = 1
        Me.HScrollBar1.Name = "HScrollBar1"
        Me.HScrollBar1.Size = New System.Drawing.Size(200, 13)
        Me.HScrollBar1.TabIndex = 0
        Me.HScrollBar1.Value = 1
        "
        "VScrollBar1
        "
        Me.VScrollBar1.LargeChange = 1
        Me.VScrollBar1.Location = New System.Drawing.Point(32, 16)
        Me.VScrollBar1.Minimum = 1
        Me.VScrollBar1.Name = "VScrollBar1"
        Me.VScrollBar1.TabIndex = 1
        Me.VScrollBar1.Value = 1
        "
        "TextBox1
        "
        Me.TextBox1.Location = New System.Drawing.Point(64, 24)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.TabIndex = 2
        Me.TextBox1.Text = ""
        "
        "TextBox2
        "
        Me.TextBox2.Location = New System.Drawing.Point(248, 112)
        Me.TextBox2.Name = "TextBox2"
        Me.TextBox2.TabIndex = 3
        Me.TextBox2.Text = ""
        "
        "Form1
        "
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(368, 165)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.TextBox2, Me.TextBox1, Me.VScrollBar1, Me.HScrollBar1})
        Me.Name = "Form1"
        Me.Text = "ScrollBarDemo"
        Me.ResumeLayout(False)
    End Sub
#End Region
    Private Sub VScrollBar1_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles VScrollBar1.ValueChanged
        TextBox1.Text = VScrollBar1.Value
    End Sub
    Private Sub HScrollBar1_Scroll(ByVal sender As Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles HScrollBar1.Scroll
        TextBox2.Text = HScrollBar1.Value
    End Sub
End Class


Use Scroll Bar to set rotate, X position and repaint

Imports System
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Imports System.Drawing.Imaging
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
  Dim XlateY As Int32
  Dim Angle As Single
  Dim DrawingRect As Rectangle = New Rectangle(25, 25, 225, 225)
#Region " Windows Form Designer generated code "
  Public Sub New()
    MyBase.New()
    "This call is required by the Windows Form Designer.
    InitializeComponent()
    Angle = 0
    Xlatey = 0
    xlate.Minimum = -50
    xlate.Maximum = 50
    xlate.SmallChange = 1
    xlate.LargeChange = 5
    xlate.Value = 0
    rotate.Minimum = -180
    rotate.Maximum = 180
    rotate.SmallChange = 1
    rotate.LargeChange = 10
    rotate.Value = 0
    Me.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
    Me.SetStyle(ControlStyles.DoubleBuffer, True)
    Me.SetStyle(ControlStyles.UserPaint, True)
  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.
  Friend WithEvents xlate As System.Windows.Forms.VScrollBar
  Friend WithEvents rotate As System.Windows.Forms.HScrollBar
  <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    Me.xlate = New System.Windows.Forms.VScrollBar()
    Me.rotate = New System.Windows.Forms.HScrollBar()
    Me.SuspendLayout()
    "
    "xlate
    "
    Me.xlate.Location = New System.Drawing.Point(264, 32)
    Me.xlate.Name = "xlate"
    Me.xlate.Size = New System.Drawing.Size(16, 200)
    Me.xlate.TabIndex = 0
    "
    "rotate
    "
    Me.rotate.Location = New System.Drawing.Point(8, 240)
    Me.rotate.Name = "rotate"
    Me.rotate.Size = New System.Drawing.Size(240, 16)
    Me.rotate.TabIndex = 1
    "
    "Form1
    "
    Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    Me.ClientSize = New System.Drawing.Size(292, 273)
    Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.rotate, Me.xlate})
    Me.MaximizeBox = False
    Me.MinimizeBox = False
    Me.Name = "Form1"
    Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
    Me.Text = "Form1"
    Me.ResumeLayout(False)
  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 G As Graphics = e.Graphics
    G.SmoothingMode = SmoothingMode.AntiAlias
    " Create a graphics path, add a rectangle, set colors
    Dim Path As New GraphicsPath()
    Path.AddRectangle(New Rectangle(75, 100, 100, 75))
    Dim Pts As PointF() = Path.PathPoints
    Dim B As New PathGradientBrush(Pts)
    "translate the brush
    Dim m As New Matrix()
    m.Translate(0, Xlatey, MatrixOrder.Append)
    m.RotateAt(Angle, B.CenterPoint, MatrixOrder.Append)
    B.MultiplyTransform(m, MatrixOrder.Append)
    G.FillRectangle(B, DrawingRect)
  End Sub
  Private Sub xlate_Scroll(ByVal sender As System.Object, _
                           ByVal e As System.Windows.Forms.ScrollEventArgs) _
                           Handles xlate.Scroll
    Xlatey = xlate.Value
    Me.Invalidate(DrawingRect)
  End Sub
  Private Sub rotate_Scroll(ByVal sender As System.Object, _
                            ByVal e As System.Windows.Forms.ScrollEventArgs) _
                            Handles rotate.Scroll
    Angle = rotate.Value
    Me.Invalidate(DrawingRect)
  End Sub
End Class