C#将控件添加到控件中...

编程入门 行业动态 更新时间:2024-10-22 14:04:06
本文介绍了C#将控件添加到控件中...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是我的代码,任何人都可以帮忙

This is my code can anyone help

private void button1_Click(object sender, EventArgs e) { TextBox myNewtextbox = new TextBox(); myNewtextbox.Controls.Add(myNewtextbox); myNewtextbox.Location = new Point(button1.Location.X, button1.Location.Y + 10); }

我认为myNewtextbox有问题,我不认为应该在那里.

I think I have a problem with the myNewtextbox I don''t think I know what should be there.

推荐答案

我不会那样做.我将TextBox放在窗体上,然后将其隐藏直到需要为止(当用户单击button1时).更好的是,我将其放在表单上并只是将其禁用.当新控件出现在无处不在"且出于未知原因时,用户不喜欢它. 除此之外,您的问题还不清楚.您是什么意思我不知道应该在那里"? I wouldn''t do it that way. I''d put the TextBox on the form, and then hide it until it''s needed (when the user clicks button1). Even better, I''d put it on the form and just disable it. Users don''t like it when new controls appear "out of nowhere" and for unknown reasons. Beyond that, your question is unclear. What do you mean by "I don''t think I know what should be there"?

问题是您正在尝试对自身进行myNewtextbox(第二行)在您的方法中).您需要添加到其他Control中,通常是Panel或Form.
—SA
The problem is that you''re trying to myNewtextbox to itself (in second line inside your method). You need to added to some other Control, typically a Panel or a Form.
—SA

更多推荐

C#将控件添加到控件中...

本文发布于:2023-11-06 13:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563852.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!