简体   繁体   English

尝试用来自C#中其他文本框的字符串填充文本框

[英]Trying to Fill a text box with strings from other textboxes in C#

I'm trying to create a simple AD Gui for our HR department to use but I'm hung up on something simple. 我正在尝试为我们的人事部门创建一个简单的AD Gui,但我一直挂在简单的东西上。 Our email address format is firstname.lastname@organization.org. 我们的电子邮件地址格式为firstname.lastname@organization.org。 I have a text box for first name and for last name and I want the text box for the email to autofill with firstname.lastname@organization.org. 我有一个用于名字和姓氏的文本框,并且我希望电子邮件的文本框自动填充firstname.lastname@organization.org。 I tried 我试过了

string FirstName = txtBoxFirstName.text;
string LastName = txtBoxLastName.text;    
txtBoxEmail.Text = FirstName + "." + LastName + "@organization.org";

I also tried not setting them as strings, but that didn't work either. 我也尝试不将它们设置为字符串,但这也不起作用。 I even tried to have the Email text box fill after the "Last Name" text box loses focus by putting 在“姓氏”文本框失去焦点后,我什至尝试填充“电子邮件”文本框

private void txtBoxLastName_Leave(object sender, System.EventArgs e)
{
    txtBoxEmail.Text = txtBoxFirstName.text + "." + txtBoxLastName.text + "@organization.org";
}

I'm making this in a Windows Form application in Visual Studio Express 2013 我在Visual Studio Express 2013的Windows窗体应用程序中进行此操作

Some more Info, I'm very VERY new to this. 更多信息,我对此很陌生。 I've done a lot of searching on the web and nothing seems to be fully fitting my usage case to the point that it's fixed it. 我在网上做了很多搜索,似乎没有什么比我的用例完全适合它的了。 In response to a question, here's a more complete code snippet: 为了回答一个问题,这是一个更完整的代码片段:

private void txtBoxLastName_Leave(object sender, System.EventArgs e)
    {
        string FirstName = txtBoxFirstName.Text;
        string LastName = txtBoxLastName.Text;
        txtBoxEmail.Text = FirstName + "." + LastName + "@lgfcu.org";
    }

This shows that they're in the txtBoxLastName_Leave. 这表明它们位于txtBoxLastName_Leave中。

I'm going to take a stab in the dark and assume that you didn't actually wire the event to the TextBox. 我将在黑暗中刺痛一下,并假设您实际上并未将事件连接到TextBox。 Easiest way to create an event: Right click on your TextBox, click properties, select the "lightning symbol" toward the top, find the event you desire ("leave" in this case) and double click the column to the right of "Leave". 创建事件的最简单方法:右键单击文本框,单击属性,在顶部选择“闪电符号”,找到所需事件(在这种情况下为“离开”),然后双击“离开”右侧的列”。 This will wire the event (look in your designer.cs file for a += ) and create the method for you. 这将关联事件(在designer.cs文件中查找+= )并为您创建方法。

Alternatively, if you want to wire the event manually add this code (after InitializeComponent() ): 另外,如果您想手动连接事件,请添加此代码(在InitializeComponent() ):

txtBoxLastName.Leave += txtBoxLastName_Leave;

The textboxes' properties are title-cased, so you need to capitalize the first letters: 文本框的属性以标题区分大小写,因此您需要将首字母大写:

string FirstName = txtBoxFirstName.Text;
string LastName = txtBoxLastName.Text;

or 要么

txtBoxEmail.Text = txtBoxFirstName.Text + "." + txtBoxLastName.Text + "@organization.org";

@MikeH got it; @MikeH明白了; I had messed up and not been calling my function to populate the Email field. 我搞砸了,没有调用我的函数来填充“电子邮件”字段。 My code was fine, 我的代码很好,

    private void populateEmail(object sender, System.EventArgs e)
    {
        string FirstName = txtBoxFirstName.Text;
        string LastName = txtBoxLastName.Text;
        txtBoxEmail.Text = FirstName + "." + LastName + "@organization.org";
    }

but I had to tie it to an event. 但是我不得不把它和一个事件联系在一起。 I set it such that when the text in FirstName or LastName are edited, it populates the email field which prevents the issue of it not generating correctly if someone goes back into a name field to modify it after clicking in the email box. 我将其设置为在编辑FirstName或LastName中的文本时填充了电子邮件字段,这可以防止如果有人在单击电子邮件框后返回到名称字段进行修改时无法正确生成该问题。

We have take string value and string value pass to TextBox 我们将字符串值和字符串值传递给TextBox

String str = "Welcome";
textBox.Text = str;

暂无
暂无

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

相关问题 使用Npgsql选择带有PostgreSQL的C#填充组合框,然后填充其他文本框 - C# fill combo box with postgreSQL select using Npgsql then populate other textboxes 从一个自动完成的C#填充多个文本框 - Fill multiple textboxes from one autocomplete c# 有没有办法在 Visual Studio 中使用 C# 动态更改文本框的文本,以便该值是来自其他文本框的值的总和? - Is there a way to dynamically change the text of a textBox in Visual Studio with C# so that the value is a sum of values from other textboxes? 尝试使用C#和WPF调整文本框中的TextBox +字体大小,只能做到其中之一 - Trying to resize TextBox + font size in text box with C# and WPF, can only do one or the other C#将文本从文本文件随机加载到多个文本框中 - c# loading text from textfile into multiple textBoxes at random 如何使用c#填充Word文档中的效果文本框? - How to Fill effect Text Box in Word Document using c#? 我正在尝试填写我的清单 <Class> 从文本文件使用C#? - I'm trying to fill my List<Class> from a text file using C#? 根据另一个自动完成文本框 c# winforms 的选定文本填充文本框 - Fill text box on basis of Selected text of another auto completed text box c# winforms 使用C#中的JSON(或其他易于阅读的文本格式)中的数据填充现有SQLite数据库 - Fill existing SQLite database with data from JSON (or other easily-readable text format) in C# 从文本框中获取多个字符串并将其输入到Checked List Box C#中 - taking multiple strings from text boxes and entering them into a Checked List Box C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM