所以这就是我想要的。当我点击一个按钮时,它将显示1个PictureBox和1个RichtextBox(这是btw Visible = False,因此除非在程序打开时单击,否则它将不显示),如您在我的屏幕截图中所示: enter image description here
但是当我点击其他按钮时它没有改变它保持我打开程序时点击的第一个按钮。我真的不知道代码,因为我是VB的新手。
这是我使用的代码:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
PictureBox1.Visible = True
RichTextBox1.Visible = True
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
PictureBox2.Visible = True
RichTextBox2.Visible = True
End Sub
End Class
谢谢!
答案 0 :(得分:1)
由于(我猜)两个图像都是正确的,你需要将第一个图像再次设置为不可见。如果不控制哪个图像在顶部取决于添加图像的顺序。
你可以这样做:
Private Sub hideElements()
For i as Integer = 1 to 6
Me.Controls("PictureBox" & i).Visible = False
Me.Controls("RichTextBox" & i).Visible = False
Next
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Call hideElements()
PictureBox1.Visible = True
RichTextBox1.Visible = True
End Sub
此循环将所有PictureBox1 - Picturebox6和RichtextBox1 - RichTextBox6设置为不可见,现在您可以将要显示的那个设置为可见。
所以只需在所有按钮处理程序的开头调用 hideElements 。
如果你想改变图像/富文本框的数量,你只需要调整循环中的 6 。
希望我能提供帮助。