如何将文本框文本设置为新编辑的值 [英] How to make textbox text to new edited value

查看:78
本文介绍了如何将文本框文本设置为新编辑的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表单中有一个组合框和文本框。

combobox1有3个选项,op1,op2和op3。

基于组合框值的文本在文本框中更改,

例如:

如果combobox1_selectedIndex = 0

textbox1.text =oooo;

如果combobox1_selectedIndex = 1

textbox1.text =9999;

问题是我想编辑文本框文本并使用新文本重新生成默认文本。

这意味着

如果组合框选择索引是0,那么textbox1.text =oooo;这个我将在文本框中编辑为oo99.how to acheive这个,请帮帮我。

i我试图将文本框文本存储在数组ar1,ar2,ar3中。



我是什么尝试过:



i have a combo box and text box in a form.
combobox1 have 3 options,op1,op2 and op3.
based on the combo box value the text in the text box changes,
for ex:
if combobox1_selectedIndex=0
textbox1.text="oooo";
if combobox1_selectedIndex=1
textbox1.text="9999";
the problem is i want to edit the textbox text and repalce the default text with new text.
which means
if combo box selected index is 0,then textbox1.text ="oooo";this i will edit in text box to "oo99".how to acheive this ,please help me.
i am trying to store the textbox text in arrays ar1,ar2,ar3.

What I have tried:

public Form1()
{
    InitializeComponent();
    comboBox1.SelectedIndex = 0;
}
String[] ar1 = new String[32];
String[] ar2 = new String[32];
String[] ar3 = new String[32];

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    if (comboBox1.SelectedIndex == 0)
    {
        dt1();
    }
    if (comboBox1.SelectedIndex == 1)
    {
        dt2();
    }
    if (comboBox1.SelectedIndex == 2)
    {
        dt3();
    }
}

void dt1()
{
    textBox1.Text = "0000";
}
void dt2()
{
    textBox1.Text = "9999";
}
void dt3()
{
    textBox1.Text = "aaaa";
}

private void textBox1_TextChanged(object sender, EventArgs e)
{
    if (comboBox1.SelectedIndex == 0)
    {
        ar1[0] = textBox1.Text;
    }
    if (comboBox1.SelectedIndex == 1)
    {
        ar2[0] = textBox1.Text;
    }
    if (comboBox1.SelectedIndex == 2)
    {
        ar3[0] = textBox1.Text;
    }
}

推荐答案

如果您对组合框进行了更改,我从您的问题中理解的是值,如果您尝试重新启动或重新加载表单,则您将获得旧值...如果这是问题,则必须将新值保存在文件中,或者可以将其保存在应用程序设置中。然后在第一次加载时从你保存它的任何地方读取然后显示它。



如果你的问题就像你改变索引时的错误一样那么你的函数需要改变,

What I understood from your question is suppose if you made changes to the combo box value and if you try restarting or reloading the form you are getting the old value itself...If that is the issue then you have to save the new value in a file or you can save it in application settings. Then while loading for the first time read from wherever you save it and then display it.

If your question is like when you are changing the index you are getting wrong value then u r function need to be changed,
void dt1()
{
    textBox1.Text = ar[0];
}
void dt2()
{
    textBox1.Text = ar[1];
}
void dt3()
{
    textBox1.Text = ar[2];
}


这篇关于如何将文本框文本设置为新编辑的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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