VB.Net by API/System.Windows.Forms/Panel
Версия от 16:40, 26 мая 2010; (обсуждение)
Panel.AutoScroll
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports System.ruponentModel
Imports System.Drawing.Drawing2D
Imports System.IO
Public Class MainClass
Shared Sub Main()
Dim form1 As Form = 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()
"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 Panel1 As System.Windows.Forms.Panel
Friend WithEvents Button6 As System.Windows.Forms.Button
Friend WithEvents Button5 As System.Windows.Forms.Button
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Panel1 = New System.Windows.Forms.Panel()
Me.Button6 = New System.Windows.Forms.Button()
Me.Button5 = New System.Windows.Forms.Button()
Me.Button4 = New System.Windows.Forms.Button()
Me.Button3 = New System.Windows.Forms.Button()
Me.Button2 = New System.Windows.Forms.Button()
Me.Button1 = New System.Windows.Forms.Button()
Me.Panel1.SuspendLayout()
Me.SuspendLayout()
"
"Panel1
"
Me.Panel1.Anchor = (((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right)
Me.Panel1.AutoScroll = True
Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.Panel1.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button6, Me.Button5, Me.Button4, Me.Button3, Me.Button2, Me.Button1})
Me.Panel1.Location = New System.Drawing.Point(8, 8)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(284, 172)
Me.Panel1.TabIndex = 1
"
"Button6
"
Me.Button6.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.Button6.Location = New System.Drawing.Point(16, 180)
Me.Button6.Name = "Button6"
Me.Button6.Size = New System.Drawing.Size(168, 24)
Me.Button6.TabIndex = 5
Me.Button6.Text = "Button6"
"
"Button5
"
Me.Button5.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.Button5.Location = New System.Drawing.Point(16, 148)
Me.Button5.Name = "Button5"
Me.Button5.Size = New System.Drawing.Size(168, 24)
Me.Button5.TabIndex = 4
Me.Button5.Text = "Button5"
"
"Button4
"
Me.Button4.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.Button4.Location = New System.Drawing.Point(16, 116)
Me.Button4.Name = "Button4"
Me.Button4.Size = New System.Drawing.Size(168, 24)
Me.Button4.TabIndex = 3
Me.Button4.Text = "Button4"
"
"Button3
"
Me.Button3.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.Button3.Location = New System.Drawing.Point(16, 84)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(168, 24)
Me.Button3.TabIndex = 2
Me.Button3.Text = "Button3"
"
"Button2
"
Me.Button2.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.Button2.Location = New System.Drawing.Point(16, 52)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(168, 24)
Me.Button2.TabIndex = 1
Me.Button2.Text = "Button2"
"
"Button1
"
Me.Button1.FlatStyle = System.Windows.Forms.FlatStyle.System
Me.Button1.Location = New System.Drawing.Point(16, 20)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(168, 24)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
"
"ScrollablePanel
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 14)
Me.ClientSize = New System.Drawing.Size(300, 186)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Panel1})
Me.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Name = "ScrollablePanel"
Me.Text = "Scrollable Panel"
Me.Panel1.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
End Class
Panel.BorderStyle
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class PanelInAction
public Shared Sub Main
Application.Run(New Form1)
End Sub
End class
Public Class Form1
Inherits System.Windows.Forms.Form
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Dim Panel1 As New Panel
Dim Panel2 As New Panel
Dim WithEvents RadioButton1 As New RadioButton
Dim WithEvents RadioButton2 As New RadioButton
Dim WithEvents RadioButton3 As New RadioButton
Dim WithEvents RadioButton4 As New RadioButton
Dim WithEvents RadioButton5 As New RadioButton
Dim WithEvents RadioButton6 As New RadioButton
Public Sub New()
MyBase.New()
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.SuspendLayout()
Me.TextBox1.Location = New System.Drawing.Point(8, 200)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(272, 20)
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = ""
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.TextBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
Panel1.Location = New Point(20, 60)
Panel1.Size = New Size(110, 100)
Panel1.BorderStyle = BorderStyle.FixedSingle
Panel2.Location = New Point(140, 60)
Panel2.Size = New Size(110, 100)
Panel2.BorderStyle = BorderStyle.FixedSingle
RadioButton1.Location = New Point(6, 16)
RadioButton1.Text = "Radio Button 1"
RadioButton1.Size = New Size(120, 16)
RadioButton2.Location = New Point(6, 36)
RadioButton2.Text = "Radio Button 2"
RadioButton2.Size = New Size(120, 20)
RadioButton3.Location = New Point(6, 56)
RadioButton3.Text = "Radio Button 3"
RadioButton3.Size = New Size(120, 20)
RadioButton4.Location = New Point(6, 16)
RadioButton4.Text = "Radio Button 4"
RadioButton4.Size = New Size(120, 16)
RadioButton5.Location = New Point(6, 36)
RadioButton5.Text = "Radio Button 5"
RadioButton5.Size = New Size(120, 20)
RadioButton6.Location = New Point(6, 56)
RadioButton6.Text = "Radio Button 6"
RadioButton6.Size = New Size(120, 20)
Panel1.Controls.Add(RadioButton1)
Panel1.Controls.Add(RadioButton2)
Panel1.Controls.Add(RadioButton3)
Panel2.Controls.Add(RadioButton4)
Panel2.Controls.Add(RadioButton5)
Panel2.Controls.Add(RadioButton6)
Controls.Add(Panel1)
Controls.Add(Panel2)
AddHandler RadioButton1.CheckedChanged, AddressOf _
RadioButton1_CheckedChanged
AddHandler RadioButton2.CheckedChanged, AddressOf _
RadioButton2_CheckedChanged
AddHandler RadioButton3.CheckedChanged, AddressOf _
RadioButton3_CheckedChanged
AddHandler RadioButton4.CheckedChanged, AddressOf _
RadioButton4_CheckedChanged
AddHandler RadioButton5.CheckedChanged, AddressOf _
RadioButton5_CheckedChanged
AddHandler RadioButton6.CheckedChanged, AddressOf _
RadioButton6_CheckedChanged
End Sub
Private Sub RadioButton1_CheckedChanged(ByVal sender As _
System.Object, ByVal e As System.EventArgs)
TextBox1.Text = "You clicked radio button 1"
End Sub
Private Sub RadioButton2_CheckedChanged(ByVal sender As _
System.Object, ByVal e As System.EventArgs)
TextBox1.Text = "You clicked radio button 2"
End Sub
Private Sub RadioButton3_CheckedChanged(ByVal sender As _
System.Object, ByVal e As System.EventArgs)
TextBox1.Text = "You clicked radio button 3"
End Sub
Private Sub RadioButton4_CheckedChanged(ByVal sender As _
System.Object, ByVal e As System.EventArgs)
TextBox1.Text = "You clicked radio button 4"
End Sub
Private Sub RadioButton5_CheckedChanged(ByVal sender As _
System.Object, ByVal e As System.EventArgs)
TextBox1.Text = "You clicked radio button 5"
End Sub
Private Sub RadioButton6_CheckedChanged(ByVal sender As _
System.Object, ByVal e As System.EventArgs)
TextBox1.Text = "You clicked radio button 6"
End Sub
End Class
Panel.Controls.Add
Imports System
Imports System.Data
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Printing
Public Class MainClass
Shared Sub Main()
Dim form1 As Form = New Form1
Application.Run(form1)
End Sub
End Class
Public Class Form1
Private Sub btnScroll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnScroll.Click
Panel1.AutoScrollPosition = New Point(Integer.Parse(txtX.Text), Integer.Parse(txtY.Text))
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.Panel1 = New System.Windows.Forms.Panel
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.Label3 = New System.Windows.Forms.Label
Me.txtX = New System.Windows.Forms.TextBox
Me.txtY = New System.Windows.Forms.TextBox
Me.btnScroll = New System.Windows.Forms.Button
Me.Label4 = New System.Windows.Forms.Label
Me.Label5 = New System.Windows.Forms.Label
Me.Panel1.SuspendLayout()
Me.SuspendLayout()
"
"Panel1
"
Me.Panel1.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
Me.Panel1.AutoScroll = True
Me.Panel1.Controls.Add(Me.Label5)
Me.Panel1.Controls.Add(Me.Label4)
Me.Panel1.Controls.Add(Me.Label2)
Me.Panel1.Controls.Add(Me.Label1)
Me.Panel1.Location = New System.Drawing.Point(8, 8)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(272, 216)
Me.Panel1.TabIndex = 0
"
"Label1
"
Me.Label1.AutoSize = True
Me.Label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.Label1.Location = New System.Drawing.Point(0, 0)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(29, 15)
Me.Label1.TabIndex = 0
Me.Label1.Text = "(0, 0)"
"
"Label2
"
Me.Label2.AutoSize = True
Me.Label2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.Label2.Location = New System.Drawing.Point(200, 200)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(53, 15)
Me.Label2.TabIndex = 1
Me.Label2.Text = "(200, 200)"
"
"Label3
"
Me.Label3.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.Label3.AutoSize = True
Me.Label3.Location = New System.Drawing.Point(0, 232)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(44, 13)
Me.Label3.TabIndex = 1
Me.Label3.Text = "Scroll to:"
"
"txtX
"
Me.txtX.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.txtX.Location = New System.Drawing.Point(48, 232)
Me.txtX.Name = "txtX"
Me.txtX.Size = New System.Drawing.Size(24, 20)
Me.txtX.TabIndex = 2
Me.txtX.Text = "50"
"
"txtY
"
Me.txtY.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.txtY.Location = New System.Drawing.Point(72, 232)
Me.txtY.Name = "txtY"
Me.txtY.Size = New System.Drawing.Size(24, 20)
Me.txtY.TabIndex = 3
Me.txtY.Text = "50"
"
"btnScroll
"
Me.btnScroll.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.btnScroll.Location = New System.Drawing.Point(96, 232)
Me.btnScroll.Name = "btnScroll"
Me.btnScroll.Size = New System.Drawing.Size(72, 24)
Me.btnScroll.TabIndex = 4
Me.btnScroll.Text = "Scroll"
"
"Label4
"
Me.Label4.AutoSize = True
Me.Label4.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.Label4.Location = New System.Drawing.Point(50, 50)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(41, 15)
Me.Label4.TabIndex = 2
Me.Label4.Text = "(50, 50)"
"
"Label5
"
Me.Label5.AutoSize = True
Me.Label5.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.Label5.Location = New System.Drawing.Point(100, 100)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(53, 15)
Me.Label5.TabIndex = 3
Me.Label5.Text = "(100, 100)"
"
"Form1
"
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(289, 256)
Me.Controls.Add(Me.btnScroll)
Me.Controls.Add(Me.txtY)
Me.Controls.Add(Me.txtX)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Panel1)
Me.Name = "Form1"
Me.Text = "UsePanel"
Me.Panel1.ResumeLayout(False)
Me.Panel1.PerformLayout()
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents Panel1 As System.Windows.Forms.Panel
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents txtX As System.Windows.Forms.TextBox
Friend WithEvents txtY As System.Windows.Forms.TextBox
Friend WithEvents btnScroll As System.Windows.Forms.Button
Friend WithEvents Label5 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
End Class
Panel.Refresh()
Imports System
Imports System.Collections
Imports System.ruponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Configuration
Imports System.Resources
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Imaging
Public Class MainClass
Shared Sub Main()
Dim myform As Form = New PanningForm()
Application.Run(myform)
End Sub
End Class
Public Class PanningForm
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 upButton As System.Windows.Forms.Button
Friend WithEvents panel1 As System.Windows.Forms.Panel
Friend WithEvents downButton As System.Windows.Forms.Button
Friend WithEvents leftButton As System.Windows.Forms.Button
Friend WithEvents rightButton As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.upButton = New System.Windows.Forms.Button()
Me.panel1 = New System.Windows.Forms.Panel()
Me.downButton = New System.Windows.Forms.Button()
Me.leftButton = New System.Windows.Forms.Button()
Me.rightButton = New System.Windows.Forms.Button()
Me.SuspendLayout()
"
"upButton
"
Me.upButton.Anchor = System.Windows.Forms.AnchorStyles.Top
Me.upButton.Location = New System.Drawing.Point(132, 10)
Me.upButton.Name = "upButton"
Me.upButton.Size = New System.Drawing.Size(24, 23)
Me.upButton.TabIndex = 5
Me.upButton.Text = "^"
"
"panel1
"
Me.panel1.Anchor = (((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left) _
Or System.Windows.Forms.AnchorStyles.Right)
Me.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.panel1.Location = New System.Drawing.Point(36, 43)
Me.panel1.Name = "panel1"
Me.panel1.Size = New System.Drawing.Size(216, 184)
Me.panel1.TabIndex = 2
"
"downButton
"
Me.downButton.Anchor = System.Windows.Forms.AnchorStyles.Bottom
Me.downButton.Location = New System.Drawing.Point(132, 234)
Me.downButton.Name = "downButton"
Me.downButton.Size = New System.Drawing.Size(24, 23)
Me.downButton.TabIndex = 6
Me.downButton.Text = "v"
"
"leftButton
"
Me.leftButton.Anchor = System.Windows.Forms.AnchorStyles.Left
Me.leftButton.Location = New System.Drawing.Point(6, 124)
Me.leftButton.Name = "leftButton"
Me.leftButton.Size = New System.Drawing.Size(24, 23)
Me.leftButton.TabIndex = 3
Me.leftButton.Text = "<"
"
"rightButton
"
Me.rightButton.Anchor = System.Windows.Forms.AnchorStyles.Right
Me.rightButton.Location = New System.Drawing.Point(262, 124)
Me.rightButton.Name = "rightButton"
Me.rightButton.Size = New System.Drawing.Size(24, 23)
Me.rightButton.TabIndex = 4
Me.rightButton.Text = ">"
"
"PanningForm
"
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.upButton, Me.panel1, Me.downButton, Me.leftButton, Me.rightButton})
Me.Name = "PanningForm"
Me.Text = "PanningForm"
Me.ResumeLayout(False)
End Sub
#End Region
Dim bmp As Bitmap = New Bitmap("figure2.bmp")
Dim offset As Size = New Size(0, 0)
Private Sub panel1_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles panel1.Paint
Dim g As Graphics = e.Graphics
Dim destRect As Rectangle = Me.panel1.ClientRectangle
Dim srcRect As Rectangle = New Rectangle(offset.Width, offset.Height, destRect.Width, destRect.Height)
g.DrawImage(bmp, destRect, srcRect, g.PageUnit)
End Sub
Private Sub upButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles upButton.Click
offset.Height = offset.Height + 10
panel1.Refresh()
End Sub
Private Sub downButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles downButton.Click
offset.Height = offset.Height - 10
panel1.Refresh()
End Sub
Private Sub rightButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rightButton.Click
offset.Width = offset.Width + 10
panel1.Refresh()
End Sub
Private Sub leftButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles leftButton.Click
offset.Width = offset.Width - 10
panel1.Refresh()
End Sub
End Class