每次按键时,textbox1的值应显示在textbox2中. [英] Value of textbox1 should show in textbox2 on every key pressing.using delegates

查看:71
本文介绍了每次按键时,textbox1的值应显示在textbox2中.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个文本框,即txtbox1和txtbox2.我要这样做,当我在textbox1中输入值(因为我必须编写CODE)时,首先我将在textbox1中按C,但是当我在textbox1中键入C时,也应该在txtbox2中显示,依此类推,直到CODE.

实际上,我使用用户控件UI,在内部绘制了一个texbox,然后在窗体上使用.我向您提供详细说明-
1-我添加了一个项目用户控件
2-将文本框添加到用户控件
3-在主窗口窗体上,我的用户控件的名称是UCTxtBox
是我的2倍.

所以我想当我在UCTxtBox1.Textbox1.text中输入文本时,所以我按的每个键都应该在UCTxtBox2.Textbox2.text中连续显示.
假设我必须写-CODE
1首先,我将在UCTxtBox1.Textbox1.Text中按C,然后它也应该出现在UCTxtBox2.Textbox1.Text
2-i这次将在UCTxtBox1.Textbox1.Text中按O,然后当CO应该在UCTxtBox2.Textbox1.Text中显示时,UCTxtBox1.Textbox1.Text的文本将为-CO.

等等
这里的UCTxtBox是UserControlUI组件
-------------------------------------------------- --------------------------------------------
1-Form1.cs代码

i have 2 textbox,txtbox1 and txtbox2.I want that,when i am entering value in textbox1 as i have to write CODE,then first i will press C in textbox1,but as i type C,in textbox1 then should also display in txtbox2.and so on till CODE.

ActuallY i m using user control UI,inside i draw a texbox,then using on my forms.I m giving u detail explanation-
1-I add an item User Control
2-Add a textbox into User Control
3-On my main windows form i take 2 times my usercontrol whose name UCTxtBox


so i want as i m entering text into UCTxtBox1.Textbox1.text,so on every key i m pressing it should show continiously in UCTxtBox2.Textbox2.text.
Suppose i have to write -CODE
1-first i will press C in UCTxtBox1.Textbox1.Text,then it should also come in UCTxtBox2.Textbox1.Text
2-i will press O this time in UCTxtBox1.Textbox1.Text then the text of UCTxtBox1.Textbox1.Text will be-CO,THEN CO SHOULD DISPLAY IN UCTxtBox2.Textbox1.Text

AND SO ON
here UCTxtBox is UserControlUI Component
----------------------------------------------------------------------------------------------
1-Form1.cs code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TxtBoxAutomation
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void ucTxtBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            ucTxtBox1.textBox1.Text = ucTxtBox2.textBox1.Text;
        }

    }
}



2-UCTxtBox.cs代码-



2-UCTxtBox.cs code-

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TxtBoxAutomation
{
    public partial class UCTxtBox : UserControl
    {
        public UCTxtBox()
        {
            InitializeComponent();
        }
    }
}

推荐答案



OnKeyUp事件只需要将文本从textbox1复制到textbox2.为什么要坚持这样简单的问题?

阅读一些C#MSDN教程以获取有关事件的信息.

祝您好运
Hi,

OnKeyUp event you just need to copy the text from textbox1 to textbox2. Why you stuck with such simple issue?

Read some C# MSDN tutorial to get information about events.

Best of luck


textbox1的按键事件中
textbox2.Text = Textbox1.Text;


祝您编码愉快!
:)


Happy Coding!
:)


private void textBox1_TextChanged(object sender, EventArgs e)
        {
            textBox2.Text = textBox1.Text;
        }


:) :) :)

问候
伪造


:):):)

Regard
Sham


这篇关于每次按键时,textbox1的值应显示在textbox2中.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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