本文介绍了专注于一个小组。使用带垂直滚动的面板。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 大家好, 如何聚焦位于父控件尺寸以下的面板。父AutoScroll设置为true。见下图。 控件 pnlControlList 面板 - 参见 ImageBox02 。这在表单加载时隐藏。仅在单击向下箭头时显示。项目也是面板。 picControlListView PictureBox 要显示 pnlControlList 请看这张图片。 [ ^ ] ImageBox01 这是运行程序时显示的内容。默认选择的项目是 项目表格。 ImageBox02 当您点击向下箭头右上角,将显示所有项目。 ImageBox03 这就是我想要发生的事情。我只需手动滚动显示 项目表。 注意 这与组合框控件相同。 项目创建 Dim pnl As 新面板 pnl.Padding = 新填充( 3 , 2 , 0 , 0 ) pnl.Height = 18 pnl.Tag = node AddHandler pnl.Click, AddressOf ControlList_Click AddHandler pnl.MouseEnter, AddressOf ControlList_MouseEnter pnlControlList.Controls.Add(pnl) Dim lbl2 作为 新标签 lbl2.Text = & controlStr lbl2.AutoSize = True lbl2.Dock = DockStyle.Left lbl2.Tag = fieldName& _& controlStr AddHandler lbl2.Click, AddressOf ControlList_Click AddHandler lbl2.MouseEnter, AddressOf ControlList_MouseEnter pnl.Controls.Add(lbl2) Dim lbl1 作为 新标签 lbl1.Text = fieldName lbl1.AutoSize = True lbl1.Dock = DockStyle.Left lbl1.Font = 新字体(lblControlListName.Font.FontFamily,lblControlListName.Font.Size,FontStyle.Bold) lbl1.Tag = fieldName& _& controlStr AddHandler lbl1.Click, AddressOf ControlList_Click AddHandler lbl1.MouseEnter, AddressOf ControlList_MouseEnter pnl.Controls.Add(lbl1) 某些控件的处理程序 #RegionDROPDOWN LIST 私有 Sub picControlListView_Click(发件人 As 对象,e 作为 EventArgs)句柄 picControlListView.Click If pnlControlList.Visible 然后 pnlControlList.Visible = False 其他 pnlControlList.Width = TreeView1.Width pnlControlList.Visible = True 对于 每个 c 作为控制在 pnlControlList.Controls 如果 c.Controls.Count> 0 然后 c.Width = pnlControlList.Width - ( 2 + IIf(pnlControlList.VerticalScroll.Maximum = 100 , 0 , 23 )) 结束 如果 下一步 txtControlListFocus.Focus() 结束 如果 结束 Sub 私有 Sub pnlControlListView_Click(发件人 As 对象,e As EventArgs)句柄 pnlControlL istView.Click picControlListView_Click(sender,e) End Sub 私有 Sub lblControlListName_Click(发件人 As 对象,e 作为 EventArgs)句柄 lblControlListName.Click picControlListView_Click(sender,e) End Sub 私有 Sub lblControlListType_Click(发件人正如 对象,e As EventArgs)句柄 lblControlListType.Click picControlListView_Click(sender,e) 结束 Sub 私人 Sub txtControlListFocus_LostFocus(sender As Object ,e As EventArgs)句柄 txtControlListFocus.LostFocus pnlControlList.Visible = False 结束 Sub #End Region 我尝试过: 这是我在google中找到的。 我试过 pnlControlList.ScrollControlIntoView(childPanel)但是而不是面板获得焦点,父控件在孩子上方放置一个巨大的边距/空白区域。 请看这个我mage。 [ ^ ] 解决方案 我在重现你的问题时遇到了问题所以我已经把一个有效的测试项目放在了一起。您可以在此处下载并试用: WinformScrollIntoViewPanel.zip - Google云端硬盘 [ ^ ] 为了进一步测试,我在可滚动面板中放置了一个可滚动的面板,并在测试表单中添加了按钮,将主面板元素和子面板元素滚动到视图中。一切都按预期工作。以下是滚动到视图中的测试代码: 私有 Sub ButtonClicked(发件人作为 对象,e 作为 EventArgs)_ Handles 但是GroupBox1.Click,但是PictBox1.Click,但是ListBox1.Click, butComboBox1.Click,但是PictBox2。单击,但是ListBox2.Click, butGroupBox2.Click,但是ComboBox2.Click Dim mainPanelCtrl 作为 Control = Nothing Dim subPanelCtrl 作为 Control = Nothing 选择 案例 True ' - 主要控制台 - 案例发​​件人是但是GroupBox1 mainPanelCtrl = GroupBox1 案例 sender butListBox1 mainPanelCtrl = ListBox1 案例 sender 是但是ComboBox1 mainPanelCtrl = ComboBox1 案例 sender 是但是PictureBox1 mainPanelCtrl = PictureBox1 ' - 主要控制台的子面板 - 案例发​​件人是但是GroupBox2 mainPanelCtrl = Pa nel2 ' 滚动子面板 subPanelCtrl = GroupBox2 ' 然后控件 案例发​​件人是 butListBox2 mainPanelCtrl = Panel2 subPanelCtrl = ListBox2 案例 sender 但是ComboBox2 mainPanelCtrl = Panel2 subPanelCtrl = ComboBox2 案例发​​件人是但是PICTureBox2 mainPanelCtrl = Panel2 subPanelCtrl = PictureBox2 结束 选择 如果 mainPanelCtrl IsNot Nothing 然后 Panel1.ScrollControlIntoView(mainPanelCtrl) 结束 如果 如果 subPanelCtrl IsNot Nothing 然后 Panel2.ScrollControlIntoView(subPanelCtrl) 结束 如果 结束 Sub 需要注意的是,内部子面板需要小于主面板的视口。如果不是,子面板中的元素将不会滚动到视图中。原因是ScrollIntoView(...)方法仅将上坐标滚动到视图中。如果子面板对于视口来说太大,则子面板中的某些元素可能看起来不会滚动到视图中,因为元素的顶部(或左侧)位于主面板视口之外,但位于子面板视口内。 Hello everyone,How can I focus a panel that is located way below the parent control size. The parent AutoScroll is set to true. See below image.ControlspnlControlList Panel - See ImageBox02. This is hidden when form loaded. Shown only when down arrow is click. Items are also panel.picControlListView PictureBox To diplay the pnlControlListPlease see this image.[^]ImageBox01 That is the displayed when you run the program. The default selected item is Item Table.ImageBox02 When you clicked the down arrow top right, all items will be shown. ImageBox03 This is what I want to happen. I just manually scroll to display the Item Table.NoteThis is same as a combobox control.Items CreationDim pnl As New Panelpnl.Padding = New Padding(3, 2, 0, 0)pnl.Height = 18pnl.Tag = nodeAddHandler pnl.Click, AddressOf ControlList_ClickAddHandler pnl.MouseEnter, AddressOf ControlList_MouseEnterpnlControlList.Controls.Add(pnl)Dim lbl2 As New Labellbl2.Text = " " & controlStrlbl2.AutoSize = Truelbl2.Dock = DockStyle.Leftlbl2.Tag = fieldName & "_" & controlStrAddHandler lbl2.Click, AddressOf ControlList_ClickAddHandler lbl2.MouseEnter, AddressOf ControlList_MouseEnterpnl.Controls.Add(lbl2)Dim lbl1 As New Labellbl1.Text = fieldNamelbl1.AutoSize = Truelbl1.Dock = DockStyle.Leftlbl1.Font = New Font(lblControlListName.Font.FontFamily, lblControlListName.Font.Size, FontStyle.Bold)lbl1.Tag = fieldName & "_" & controlStrAddHandler lbl1.Click, AddressOf ControlList_ClickAddHandler lbl1.MouseEnter, AddressOf ControlList_MouseEnterpnl.Controls.Add(lbl1)Handlers of some controls#Region "DROPDOWN LIST" Private Sub picControlListView_Click(sender As Object, e As EventArgs) Handles picControlListView.Click If pnlControlList.Visible Then pnlControlList.Visible = False Else pnlControlList.Width = TreeView1.Width pnlControlList.Visible = True For Each c As Control In pnlControlList.Controls If c.Controls.Count > 0 Then c.Width = pnlControlList.Width - (2 + IIf(pnlControlList.VerticalScroll.Maximum = 100, 0, 23)) End If Next txtControlListFocus.Focus() End If End Sub Private Sub pnlControlListView_Click(sender As Object, e As EventArgs) Handles pnlControlListView.Click picControlListView_Click(sender, e) End Sub Private Sub lblControlListName_Click(sender As Object, e As EventArgs) Handles lblControlListName.Click picControlListView_Click(sender, e) End Sub Private Sub lblControlListType_Click(sender As Object, e As EventArgs) Handles lblControlListType.Click picControlListView_Click(sender, e) End Sub Private Sub txtControlListFocus_LostFocus(sender As Object, e As EventArgs) Handles txtControlListFocus.LostFocus pnlControlList.Visible = False End Sub#End RegionWhat I have tried:This is what I found in google.I tried pnlControlList.ScrollControlIntoView(childPanel) but instead of panel getting focus the parent control puts a huge margin/white space above the childs.Please see this image.[^] 解决方案 I'm having problems reproducing your problem so I have put together a test project that works. You can download and try it here: WinformScrollIntoViewPanel.zip - Google Drive[^]To test this further, I've put a scrollable Panel inside a scrollable Panel and added buttons to the test form to scroll main Panel elements and sub Panel elements into view. Everything works as expected. Here is the test code for scrolling into view:Private Sub ButtonClicked(sender As Object, e As EventArgs) _ Handles butGroupBox1.Click, butPictureBox1.Click, butListBox1.Click, butComboBox1.Click, butPictureBox2.Click, butListBox2.Click, butGroupBox2.Click, butComboBox2.Click Dim mainPanelCtrl As Control = Nothing Dim subPanelCtrl As Control = Nothing Select Case True ' -- MAIN PANEL CONTROLS -- Case sender Is butGroupBox1 mainPanelCtrl = GroupBox1 Case sender Is butListBox1 mainPanelCtrl = ListBox1 Case sender Is butComboBox1 mainPanelCtrl = ComboBox1 Case sender Is butPictureBox1 mainPanelCtrl = PictureBox1 '-- SUB PANEL OF MAIN PANEL CONTROLS -- Case sender Is butGroupBox2 mainPanelCtrl = Panel2 ' scroll the sub-panel subPanelCtrl = GroupBox2 ' then the control Case sender Is butListBox2 mainPanelCtrl = Panel2 subPanelCtrl = ListBox2 Case sender Is butComboBox2 mainPanelCtrl = Panel2 subPanelCtrl = ComboBox2 Case sender Is butPictureBox2 mainPanelCtrl = Panel2 subPanelCtrl = PictureBox2 End Select If mainPanelCtrl IsNot Nothing Then Panel1.ScrollControlIntoView(mainPanelCtrl) End If If subPanelCtrl IsNot Nothing Then Panel2.ScrollControlIntoView(subPanelCtrl) End IfEnd SubSomething to note, the inner sub Panels will need to be smaller than the viewport of the main Panel. If not, elements in the sub Panel will not scroll into view. The reason for this is that the ScrollIntoView(...) method only scrolls the upper coordinates into view. if the sub Panel is too large for the Viewport, some elements in the sub Panel may appear to not scroll into view as the top (or left) of the element is outside the main Panel viewport but within the sub Panel viewport. 这篇关于专注于一个小组。使用带垂直滚动的面板。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-01 21:06