C#将控件添加到控件中... [英] C# Adding Control to a Control...............

查看:96
本文介绍了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中,通常是PanelForm.

—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#将控件添加到控件中...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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