vb.net - 如何在 form1.control 之上添加一个 form2 控件
问题描述
我有两种形式。带有richtextbox 的Form1 和带有列表框的form2。
我想把列表框放在richtextbox 的顶部,对接它。我想做这样的事:
form2.Controls.Remove(ListBox1)
form2.hide
form1.richtextbox1.controls.add(form2.listbox1)
form1.richtextbox1.hide 'I can't hide, also listbox will hide...
form2.listbox1.location= richtextbox1
或者form2.listbox1.bounds=richtextbox1.bounds
一切正常,直到将 form2.listbox1.location 设置为如果richtextbox1 被隐藏,列表框也会被隐藏。此外,将列表框的位置和/或边界设置为与richtextbox 相同并不能完全覆盖richtextbox。我也尝试对两者使用相同的尺寸。
解决方案
这对我有用:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim LB As ListBox = Form2.ListBox1
If IsNothing(LB.Tab)
LB.Tag = LB.Size ' <-- store it for later use
End If
Me.Controls.Add(LB)
LB.Bounds = RichTextBox1.Bounds
RichTextBox1.Hide()
End Sub
稍后,当您将 ListBox 移回时,检索存储在 Tag 中的大小:
If Not IsNothing(LB.Tab)
LB.Size = LB.Tag
End If
输出:
推荐阅读
- php - 重定向到链接然后重定向到codeigniter中的主网站?
- mysql - MySQL 多左连接限制
- mysql - 如何理解不使用 INNER JOIN 将表连接到自身的 SQL SYNTAN?
- php - 矩阵和数组
- java - onStartCommand 中 getString 的服务总是返回 null
- php - 正则表达式,在另一行结束标记
- rest - Vuex 和 axios,远程内容未在初始页面加载时显示
- android - 为什么“匹配”选项不适用于 cordova-plugin-speechrecognition?
- perl - 为 Moo 只读属性设置写入器名称是否使其可读写?
- ios - git clone 后 xcode 找不到 .phc 文件