简体   繁体   English

如何将文本从一个文本框保存/追加到VB中同一表单上的另一个文本框

[英]How can I save/append text from one textbox to another textbox on the same Form in VB

Basically what I'm trying to figure out how to do is save text from one textbox to another textbox on the same form. 基本上,我想弄清楚该怎么做的是将文本从一个文本框保存到同一表单上的另一个文本框。 I see a lot of post on how to save or store text from one textbox to another on a different form but not any with doing that on the same form. 我看到了很多关于如何将文本从一个文本框保存或存储到另一表单的文章,但是在同一表单上却没有。

I'm currently working on a feature in my program that allows me to with a click fn my "LogItLater" button save the fields from the First Name, Last Name, and Phone# textboxes on my form and place them on a different textbox on my form which allows the user to add more or edit that information at later time. 我当前正在使用程序中的某个功能,该功能使我可以单击“ LogItLater”按钮来保存表单中“名字”,“姓氏”和“电话号码”文本框中的字段,并将其放置在表单上的其他文本框中。我的表格,允许用户在以后添加更多信息或编辑该信息。

I'm doing this in VB so just a simple how to would be great, this is my first time asking a question so I hope I was as specific as possible. 我正在VB中做到这一点,所以这只是一个简单的方法,这是我第一次问一个问题,所以希望我尽可能具体。


So my new issue is this when I add more than one statement like this 所以当我添加多个这样的语句时,我的新问题就是这个

txtScrapeBox.Text = txtFirstName.Text
txtScrapeBox.Text = txtLastName.Text
txtScrapeBox.Text = txtPhone.Text

The only text that is saved is the last statement and in this case it is the txtPhone.Text, will I need a condition statement to get the first two to save as well? 保存的唯一文本是最后一个语句,在这种情况下,它是txtPhone.Text,是否也需要条件语句才能保存前两个语句?

Only the last assignment is retained, because you are replacing the contents with each assignment. 仅保留最后一个分配,因为您将用每个分配替换内容。 To append (I am assuming this is a multiline TB - if it isnt, the data will come out: ZiggyWagner(800)5550195 ): 追加(我假设这是多行TB-如果不是,则数据将出来: ZiggyWagner(800)5550195 ):

txtScrapeBox.Text = txtFirstName.Text & Environment.NewLine & _
        txtLastName.Text & Environment.NewLine & txtPhone.Text

This presents a problem down the road - if they want to edit "LastName", how will you know which line they want to edit? 这会带来一个问题-如果他们要编辑“ LastName”,您将如何知道他们要编辑哪一行? You will have to save all three items to txtScrapeBox in the same order every time and fetch them back using the .Lines() property. 每次必须将所有三个项目以相同的顺序保存到txtScrapeBox中,然后使用.Lines()属性将其.Lines()

Another way might be to save them to a ListBox where item 0 is always first name, item 1 = LastName etc: 另一种方法是将它们保存到ListBox ,其中项0始终是名字,项1 =姓氏,等等:

 lbData.Items.Clear          ' remove previous contents
 lbData.Items.Add(txtFirstName.Text)
 lbData.Items.Add(txtLastName.Text)
 lbData.Items.Add(txtPhone.Text)

Get one back to edit: 退回进行编辑:

 txtFirstName.Text = lbData.Items(0).ToString
 ' or
 If lbData.SelectedItems.Count > 0 Then      ' check if they selected one
     txtFirstName.Text = lbData.SelectedItem.ToString
 End If

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM