本文整理汇总了VB.NET中System.Windows.Forms.Control.PerformLayout方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Control.PerformLayout方法的具体用法?VB.NET Control.PerformLayout怎么用?VB.NET Control.PerformLayout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了Control.PerformLayout方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: LayoutForm
' 导入命名空间
Imports System.Windows.Forms
Imports System.Drawing
Public Class LayoutForm
Inherits System.Windows.Forms.Form
Public Sub New()
MyBase.New()
InitializeComponent()
End Sub
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents LayoutControl1 As LayoutControl
Friend WithEvents Button3 As System.Windows.Forms.Button
Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.Button3 = New System.Windows.Forms.Button
Me.LayoutControl1 = New LayoutControl
Me.SuspendLayout()
Me.Button1.Location = New System.Drawing.Point(16, 16)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(120, 32)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Center textbox on control"
Me.Button2.Location = New System.Drawing.Point(152, 16)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(104, 32)
Me.Button2.TabIndex = 3
Me.Button2.Text = "Shrink user control"
Me.Button3.Location = New System.Drawing.Point(96, 232)
Me.Button3.Name = "Button3"
Me.Button3.TabIndex = 5
Me.Button3.Text = "Reset"
Me.LayoutControl1.BackColor = System.Drawing.SystemColors.ControlDark
Me.LayoutControl1.Location = New System.Drawing.Point(72, 64)
Me.LayoutControl1.Name = "LayoutControl1"
Me.LayoutControl1.Size = New System.Drawing.Size(150, 160)
Me.LayoutControl1.TabIndex = 6
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.LayoutControl1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
<System.STAThread()> Shared Sub Main()
Application.Run(New LayoutForm)
End Sub
' This method explicitly calls raises the layout event on
' LayoutControl1, changing the Bounds property.
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
LayoutControl1.PerformLayout(LayoutControl1, "Bounds")
End Sub
' This resize of LayoutControl1 implicitly triggers the layout event.
' Changing the size of the control affects its Bounds property.
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
LayoutControl1.Size = New System.Drawing.Size(100, 100)
End Sub
' This method explicitly calls PerformLayout with no parameters,
' which raises the Layout event with the LayoutEventArgs properties
' equal to Nothing.
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
LayoutControl1.PerformLayout()
End Sub
End Class
'This custom control has the Layout event implented so that when
'PerformLayout(AffectedControl, AffectedProperty) is called on the control,
'where AffectedProperty equals "Bounds" the textbox is centered on the control.
Public Class LayoutControl
Inherits System.Windows.Forms.UserControl
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Public Sub New()
MyBase.New()
InitializeComponent()
End Sub
Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.SuspendLayout()
Me.TextBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.TabIndex = 0
Me.BackColor = System.Drawing.SystemColors.ControlDark
Me.Controls.Add(Me.TextBox1)
Me.Name = "LayoutControl"
Me.ResumeLayout(False)
End Sub
'This method is called when the Layout event is fired. This happens by during the initial load,
'by calling PerformLayout or by resizing, adding or removing controls or other actions that
'affect how the control is laid out. This method checks the value of e.AffectedProperty
'and changes the look of the control accordingly.
Private Sub LayoutControl_Layout(ByVal sender As Object, ByVal e As System.Windows.Forms.LayoutEventArgs) Handles MyBase.Layout
If e.AffectedProperty IsNot Nothing Then
If e.AffectedProperty.Equals("Bounds") Then
TextBox1.Left = (Me.Width - TextBox1.Width) / 2
TextBox1.Top = (Me.Height - TextBox1.Height) / 2
End If
Else
Me.Size = New System.Drawing.Size(150, 160)
TextBox1.Location = New System.Drawing.Point(16, 24)
End If
TextBox1.Text = "Left = " & TextBox1.Left & " Top = " & TextBox1.Top
End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System.Windows.Forms,代码行数:128,代码来源:Control.PerformLayout
注:本文中的System.Windows.Forms.Control.PerformLayout方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论