从代码添加文本框

编程入门 行业动态 更新时间:2024-10-28 06:26:05
本文介绍了从代码添加文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在Visual Studio 2010中使用Visual Basic.如何从代码内将文本框添加到表单?

I''m using Visual Basic in Visual Studio 2010. How do I add a textbox to a form from within the code?

推荐答案

如果您不做任何操作来查看控件,您将如何看待它?到目前为止,我看到的答案"也缺少您需要的主要代码. 要查看新创建的控件,您还需要调用parentControl.Controls.Add(newlyCreatedControl);,其中parentControl是成为父项的某个控件,Form或任何其他控件,而newlyCreatedControl是您的文本框或您创建的任何其他控件. br/> 要知道如何解决诸如此类的许多问题,您需要了解一件事.所有控件始终在运行时随代码一起添加";没有别的办法了.设计人员仅帮助您创建此代码.不要被设计时"这个术语所迷惑,它只是意味着控件的代码应该支持与设计者一起工作. 因此,如果您知道如何与设计者进行某些事情,但不确定如何用代码编写,请先与设计者打交道,然后查看自动生成的代码,该代码位于文件中作为子节点的文件中.解决方案资源管理器中的主表单节点.通过这段代码,您将了解如何做到这一点.
-SA
How could you see your control if you don''t do anything to see it? The "answers" I''ve seen so far also lack the main piece of code you need. To see your newly created control, you also need to call parentControl.Controls.Add(newlyCreatedControl); where parentControl is some control to become a parent, Form or any other, and newlyCreatedControl is your text box or any other control you create. To know how to solve many problems like this one, you need to understand one thing. All controls are added "withing the code", always in run time; there is no other way. The designer merely helps you to create this code. Don''t be mystified by the term "design-time" — it simply means that the control''s code should support working with the designer. So, if you know how to make certain things with the designer but not sure how to write it in code, do wit the designer first and then look at the auto-generated code, which is placed in the file shown as a child node of the main form node in the Solution Explorer. From this code, you will understand how to do it.
—SA

Dim TextBox1 As TextBox = New TextBox With TextBox1 .Top = 8 .Left = 16 'set the other properties End With

有关更多信息,请参见 MSDN [ ^ ]网站.

More at MSDN[^] site.

Public Class Form1 Dim lowerBound As Double Dim textBoxes(4) As TextBox Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load TextBox1.AppendText("sales") textBoxes(1) = New TextBox() With textBoxes(1) .Top = 60 .Left = 17 .Height = 20 .Width = 104 .Visible = True .ForeColor = Color.Black .BackColor = Color.Transparent .AcceptsReturn = False End With End Sub

更多推荐

从代码添加文本框

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

发布评论

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

>www.elefans.com

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