Winforms SplitContainer中的Top ListView赢得';添加垂直滚动条
我有一个Winforms应用程序,在一个SplitContainer中有两个ListView 当我拖动拆分器隐藏部分Panel2 ListView项目时,它会自动添加一个垂直滚动条。Winforms SplitContainer中的Top ListView赢得';添加垂直滚动条,winforms,listview,splitcontainer,Winforms,Listview,Splitcontainer,我有一个Winforms应用程序,在一个SplitContainer中有两个ListView 当我拖动拆分器隐藏部分Panel2 ListView项目时,它会自动添加一个垂直滚动条。 当我拖动拆分器以隐藏部分Panel1 ListView项目时,它不会添加垂直滚动条。 更改具有相同行为的面板中的哪个ListView。这就好像SplitContainer或它的面板控制着垂直滚动条是否被添加到Panel1中的ListView中。如何使顶部面板中的列表视图1也自动添加垂直滚动条 要进行复制,请使用
当我拖动拆分器以隐藏部分Panel1 ListView项目时,它不会添加垂直滚动条。
更改具有相同行为的面板中的哪个ListView。这就好像SplitContainer或它的面板控制着垂直滚动条是否被添加到Panel1中的ListView中。如何使顶部面板中的列表视图1也自动添加垂直滚动条 要进行复制,请使用一个表单创建一个简单的Winforms应用程序。下面是我的表单代码,后面是设计器表单代码
Public Class Form1
Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Try
Timer1.Enabled = False
TechDateList.BeginUpdate()
TechDateList.Items.Clear()
StopsList.BeginUpdate()
StopsList.Items.Clear()
For i As Integer = 1 To 5
Dim techItem = New ListViewItem
techItem.UseItemStyleForSubItems = False
techItem.SubItems(0).Text = Date.Now.ToString("MMM dd, yyyy")
techItem.SubItems.Add(String.Format("Tech {0}", i))
TechDateList.Items.Add(techItem)
Next
For i As Integer = 1 To 5
Dim stopItem = New ListViewItem
stopItem.UseItemStyleForSubItems = False
stopItem.SubItems(0).Text = Choose(i, "AAA", "BBB", "CCC", "DDD", "EEE")
stopItem.SubItems.Add(String.Format("Stop {0}", i))
StopsList.Items.Add(stopItem)
Next
Catch ex As Exception
MsgBox(ex.ToString(), MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Timer1_Tick Error 1")
Finally
TechDateList.EndUpdate()
StopsList.EndUpdate()
End Try
Try
ListSplitter.Panel1Collapsed = False
ListSplitter.SplitterDistance = 125
ListSplitter.SplitterWidth = 6
TechDateList.Items.Item(0).Selected = True
Catch ex As Exception
MsgBox(ex.ToString(), MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Timer1_Tick Error 2")
End Try
End Sub
End Class
_
部分类Form1
继承System.Windows.Forms.Form
'窗体覆盖dispose以清理组件列表。
_
受保护的重写子处置(ByVal作为布尔值处置)
尝试
如果处理AndAlso组件不是什么,那么
components.Dispose()
如果结束
最后
MyBase.Dispose(Dispose)
结束尝试
端接头
'是Windows窗体设计器所必需的
作为System.ComponentModel.IContainer的专用组件
'注意:Windows窗体设计器需要以下过程
'可以使用Windows窗体设计器对其进行修改。
'不要使用代码编辑器修改它。
_
私有子初始化组件()
Me.components=New System.ComponentModel.Container()
Me.ListSplitter=New System.Windows.Forms.SplitContainer()
Me.TechDateList=New System.Windows.Forms.ListView()
Me.UInitial=CType(新的System.Windows.Forms.ColumnHeader(),System.Windows.Forms.ColumnHeader)
Me.SchedDate=CType(新System.Windows.Forms.ColumnHeader(),System.Windows.Forms.ColumnHeader)
Me.StopsList=New System.Windows.Forms.ListView()
Me.StopNum=CType(新的System.Windows.Forms.ColumnHeader(),System.Windows.Forms.ColumnHeader)
Me.StopName=CType(新的System.Windows.Forms.ColumnHeader(),System.Windows.Forms.ColumnHeader)
Me.Timer1=新系统.Windows.Forms.Timer(Me.components)
CType(Me.ListSplitter、System.ComponentModel.ISupportInitialize.BeginInit())
Me.ListSplitter.Panel1.SuspendLayout()
Me.ListSplitter.Panel2.SuspendLayout()
Me.ListSplitter.SuspendLayout()
Me.SuspendLayout()
'
'列表拆分器
'
Me.ListSplitter.Dock=System.Windows.Forms.DockStyle.Fill
Me.ListSplitter.FixedPanel=System.Windows.Forms.FixedPanel.Panel1
Me.ListSplitter.Location=新系统.Drawing.Point(0,0)
Me.ListSplitter.Name=“ListSplitter”
Me.ListSplitter.Orientation=System.Windows.Forms.Orientation.Horizontal
'
'ListSplitter.Panel1
'
Me.ListSplitter.Panel1.Controls.Add(Me.TechDateList)
Me.ListSplitter.Panel1Collapsed=True
Me.ListSplitter.Panel1MinSize=0
'
'ListSplitter.Panel2
'
Me.ListSplitter.Panel2.Controls.Add(Me.StopsList)
Me.ListSplitter.Size=新系统.图纸.尺寸(384261)
Me.listspliter.SplitterDistance=25
Me.ListSplitter.SplitterWidth=1
Me.ListSplitter.TabIndex=1
'
'TechDateList
'
Me.TechDateList.Anchor=CType((System.Windows.Forms.AnchorStyles.Top或System.Windows.Forms.AnchorStyles.Bottom)_
或System.Windows.Forms.AnchorsStyles.Left),System.Windows.Forms.AnchorsStyles)
Me.TechDateList.Columns.AddRange(新System.Windows.Forms.ColumnHeader(){Me.UIInitial,Me.SchedDate})
Me.TechDateList.FullRowSelect=True
Me.TechDateList.HeaderStyle=System.Windows.Forms.ColumnHeaderStyle.None
Me.TechDateList.HideSelection=False
Me.TechDateList.LabelWrap=False
Me.TechDateList.Location=新系统.绘图.点(4,0)
Me.TechDateList.Margin=New System.Windows.Forms.Padding(0)
Me.TechDateList.MultiSelect=False
Me.TechDateList.Name=“TechDateList”
Me.TechDateList.ShowGroups=False
Me.TechDateList.Size=新系统.图纸.尺寸(258166)
Me.TechDateList.TabIndex=0
Me.TechDateList.UseCompatibleStateImageBehavior=False
Me.TechDateList.View=System.Windows.Forms.View.Details
'
“原始的
'
Me.UInitial.Text=“路线”
Me.UInitial.TextAlign=System.Windows.Forms.HorizontalAlignment.Center
Me.u初始宽度=100
'
“SchedDate
'
Me.SchedDate.Text=“作业日期”
Me.SchedDate.Width=133
'
“止损单
'
Me.StopsList.Anchor=CType((System.Windows.Forms.AnchorStyles.Top或System.Windows.Forms.AnchorStyles.Bottom)_
或System.Windows.Forms.AnchorsStyles.Left),System.Windows.Forms.AnchorsStyles)
Me.StopsList.Columns.AddRange(新的System.Windows.Forms.ColumnHeader(){Me.StopNum,Me.StopName})
Me.StopsList.FullRowSelect=True
Me.StopsList.HeaderStyle=System.Windows.Forms.ColumnHeaderStyle.None
Me.StopsList.HideSelection=False
Me.StopsList.LabelWrap=False
Me.StopsList.Location=新系统.图纸.点(4,0)
Me.StopsList.Margin=New System.Windows.Forms.Padding(0)
Me.StopsList.MultiSelect=False
Me.StopsList.Name=“StopsList”
Me.StopsList.ShowGroups=False
Me.StopsList.Size=新系统.图纸.尺寸(258252)
Me.StopsList.TabIndex=0
Me.StopsList.UseCompatibleStateImageBehavior=False
Me.StopsList.View=System.Windows.Forms.View.Details
'
“StopNum
'
Me.StopNum.Text=“000”
Me.StopNum.TextAlign=System.Windows.Forms.HorizontalAlignment.Center
我。
<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)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
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.components = New System.ComponentModel.Container()
Me.ListSplitter = New System.Windows.Forms.SplitContainer()
Me.TechDateList = New System.Windows.Forms.ListView()
Me.UInitial = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader)
Me.SchedDate = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader)
Me.StopsList = New System.Windows.Forms.ListView()
Me.StopNum = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader)
Me.StopName = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader)
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
CType(Me.ListSplitter, System.ComponentModel.ISupportInitialize).BeginInit()
Me.ListSplitter.Panel1.SuspendLayout()
Me.ListSplitter.Panel2.SuspendLayout()
Me.ListSplitter.SuspendLayout()
Me.SuspendLayout()
'
'ListSplitter
'
Me.ListSplitter.Dock = System.Windows.Forms.DockStyle.Fill
Me.ListSplitter.FixedPanel = System.Windows.Forms.FixedPanel.Panel1
Me.ListSplitter.Location = New System.Drawing.Point(0, 0)
Me.ListSplitter.Name = "ListSplitter"
Me.ListSplitter.Orientation = System.Windows.Forms.Orientation.Horizontal
'
'ListSplitter.Panel1
'
Me.ListSplitter.Panel1.Controls.Add(Me.TechDateList)
Me.ListSplitter.Panel1Collapsed = True
Me.ListSplitter.Panel1MinSize = 0
'
'ListSplitter.Panel2
'
Me.ListSplitter.Panel2.Controls.Add(Me.StopsList)
Me.ListSplitter.Size = New System.Drawing.Size(384, 261)
Me.ListSplitter.SplitterDistance = 25
Me.ListSplitter.SplitterWidth = 1
Me.ListSplitter.TabIndex = 1
'
'TechDateList
'
Me.TechDateList.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.TechDateList.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.UInitial, Me.SchedDate})
Me.TechDateList.FullRowSelect = True
Me.TechDateList.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None
Me.TechDateList.HideSelection = False
Me.TechDateList.LabelWrap = False
Me.TechDateList.Location = New System.Drawing.Point(4, 0)
Me.TechDateList.Margin = New System.Windows.Forms.Padding(0)
Me.TechDateList.MultiSelect = False
Me.TechDateList.Name = "TechDateList"
Me.TechDateList.ShowGroups = False
Me.TechDateList.Size = New System.Drawing.Size(258, 166)
Me.TechDateList.TabIndex = 0
Me.TechDateList.UseCompatibleStateImageBehavior = False
Me.TechDateList.View = System.Windows.Forms.View.Details
'
'UInitial
'
Me.UInitial.Text = "Route"
Me.UInitial.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
Me.UInitial.Width = 100
'
'SchedDate
'
Me.SchedDate.Text = "Job Date"
Me.SchedDate.Width = 133
'
'StopsList
'
Me.StopsList.Anchor = CType(((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles)
Me.StopsList.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.StopNum, Me.StopName})
Me.StopsList.FullRowSelect = True
Me.StopsList.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None
Me.StopsList.HideSelection = False
Me.StopsList.LabelWrap = False
Me.StopsList.Location = New System.Drawing.Point(4, 0)
Me.StopsList.Margin = New System.Windows.Forms.Padding(0)
Me.StopsList.MultiSelect = False
Me.StopsList.Name = "StopsList"
Me.StopsList.ShowGroups = False
Me.StopsList.Size = New System.Drawing.Size(258, 252)
Me.StopsList.TabIndex = 0
Me.StopsList.UseCompatibleStateImageBehavior = False
Me.StopsList.View = System.Windows.Forms.View.Details
'
'StopNum
'
Me.StopNum.Text = "000"
Me.StopNum.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
Me.StopNum.Width = 34
'
'StopName
'
Me.StopName.Text = "Stop Name"
Me.StopName.Width = 199
'
'Timer1
'
Me.Timer1.Interval = 250
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(384, 261)
Me.Controls.Add(Me.ListSplitter)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ListSplitter.Panel1.ResumeLayout(False)
Me.ListSplitter.Panel2.ResumeLayout(False)
CType(Me.ListSplitter, System.ComponentModel.ISupportInitialize).EndInit()
Me.ListSplitter.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
Friend WithEvents ListSplitter As SplitContainer
Friend WithEvents TechDateList As ListView
Friend WithEvents UInitial As ColumnHeader
Friend WithEvents SchedDate As ColumnHeader
Friend WithEvents StopsList As ListView
Friend WithEvents StopNum As ColumnHeader
Friend WithEvents StopName As ColumnHeader
Friend WithEvents Timer1 As Timer
End Class
Private Sub ListSplitter_SplitterMoved(sender As Object, e As SplitterEventArgs) Handles ListSplitter.SplitterMoved
TechDateList.Height = ListSplitter.Panel1.Height
End Sub
Me.ListSplitter.SplitterDistance = 25
Me.TechDateList.Size = New System.Drawing.Size(258, 166)
Me.ListSplitter.SplitterDistance = 125
Me.TechDateList.Size = New System.Drawing.Size(258, 120)