[英]Passing text from one textBox to another in a same form using C# Windows Form
[英]Retrieve text from a textbox to place in another textbox on same windows form
我創建了一個很好的Windows窗體。 我被要求做的是將其分解。 我希望用戶能夠執行的操作是在TextBox
鍵入內容,但要包含某種表示來自另一個TextBox
文本的標記。
我有四個文本框:
1- to_fromTextBox
2- city1TextBox
3- city2TextBox
4- enterTextbox
因此,如果用戶輸入city1TextBox
-Orlando,則輸入city2TextBox
-Longwood。
然后在輸入enterTextBox
-從(從一些標簽插入city1TextBox
)到(從一些標簽插入city1TextBox
),例如,從某個標識符到某個identifie 。
這將連接到to_fromTextBox
以保存在數據庫表中。 例如從奧蘭多到朗伍德
之所以必須分開,是因為在創建報表時,其他文本框將具有地圖坐標,並將跟隨城市文本框。 報告的文字,例如從奧蘭多(H-5)到朗伍德(H-4)
我已經竭盡全力尋找這個答案,但是沒有運氣。 有人可以指出我正確的方向。
如果^^和##是預定義的,則可以像這樣在enterTextbox
keyup
事件上編寫此代碼
var text = "From ^^ to ##";
if (text.IndexOf("^^") != -1 && text.IndexOf("##") != -1)
{
to_fromTextBox.Text = text
.Replace("^^", city1TextBox.Text)
.Replace("##", city2TextBox.Text);
}
但是,如果使用{0}和{1}作為標識符,則可以使用String.Format
這樣的
var text = "From {0} to {1}";
if (text.IndexOf("{0}") != -1 && text.IndexOf("{1}") != -1)
{
to_fromTextBox.Text = String.Format(
text,
city1TextBox.Text,
city2TextBox.Text);
}
您可以使用.Text訪問文本框中的字符串(這是一個Get / Set,因此可以以相同的形式更改其值)。
textBox1.Text = "1"
textBoxt2.Text = "2"
textBoxN.Text = "n...";
textBoxTarget.Text = textBox1.Text +" - "+ textBoxt2.Text +" - "+ TextBoxN.Text;
textBoxTarget.Text = "1 - 2 - n..."
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.