如何将Groupbox中的控件的位置更改为另一个Groupbox [英] How Do I Change Location Of A Control Which Is In A Groupbox To Another Groupbox

查看:375
本文介绍了如何将Groupbox中的控件的位置更改为另一个Groupbox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在groupbox1中有一个TextBox控件,我想在Windows应用程序中的按钮单击事件中在运行时将文本框的位置从groupbox1更改为groupbox2

我怎么能这样做? ?



请帮助

解决方案

假设这是WinForms应用程序(如果然后才看到Andy Lanng的评论)



我创建了一个带有两个组合框的表单,一个按钮并在第一个组框中放置了一个文本框。所有控件都保留了默认名称。



以下代码移动按钮上组框之间的文本框单击

 私有  Sub  Button1_Click(发件人 As 系统。对象,e  As  System.EventArgs)句柄 Button1。点击
如果 TextBox1.Parent GroupBox2 那么
TextBox1.Parent = GroupBox1
Else
TextBox1.Parent = GroupBox2
结束 如果
结束 Sub



请注意,测试必须使用 Is 而不是 = 否则你会得到一个编译错误

Quote:

没有为类型'System.Windows.Forms.Control'和'系统定义运算符'=' .Windows.Forms.GroupBox。


i have a TextBox control in groupbox1 and i want to change the location of the textbox from groupbox1 to groupbox2 in run time at a button click event in Windows Application
how could i do that???

please help

解决方案

Assuming this is WinForms application (if is not then see the comment from Andy Lanng)

I created a form with two groupboxes, one button and placed a textbox in the first groupbox. All controls were left with their default names.

The following code moves the text box between the groupboxes on the button click

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    If TextBox1.Parent Is GroupBox2 Then
        TextBox1.Parent = GroupBox1
    Else
        TextBox1.Parent = GroupBox2
    End If
End Sub


Note that the test has to use Is instead of = otherwise you will get a compile error

Quote:

Operator '=' is not defined for types 'System.Windows.Forms.Control' and 'System.Windows.Forms.GroupBox'.


这篇关于如何将Groupbox中的控件的位置更改为另一个Groupbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆