Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C#
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 code-

C#
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();
        }
    }
}
Posted
Updated 20-Sep-12 23:41pm
v5
Comments
[no name] 21-Sep-12 1:35am    
Is this a web application or a windows application?
StackQ 21-Sep-12 1:38am    
Windows application,with C#
StackQ 21-Sep-12 2:28am    
----------------------------------------------------------------------------------------------
1-Form1.cs code

Collapse | Copy 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 code-

Collapse | Copy 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();
}
}
}
Ganesh Nikam 21-Sep-12 2:53am    
which template you have used for UCTxtBox.cs

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
 
Share this answer
 
Comments
StackQ 21-Sep-12 2:07am    
i m not getting,plz help..
AmitGajjar 21-Sep-12 2:37am    
private void textBox1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
{
textbox2.Text = textbox1.Text;
}
StackQ 21-Sep-12 2:44am    
not working bcoz this is not simple textbox,this textbox is in user control UI component.U should see once again my updated question.
AmitGajjar 21-Sep-12 2:45am    
You need to expose UserControl with textbox Text property with get and set so it can be changed from other forms.
StackQ 21-Sep-12 2:48am    
how,can u guide through code,coz i have no idea,about this concept,i m learning C# since 2 months.
inside textbox1's keyspress event
C#
textbox2.Text = Textbox1.Text;

Happy Coding!
:)
 
Share this answer
 
Comments
StackQ 21-Sep-12 2:09am    
NOT WORKING
Aarti Meswania 21-Sep-12 2:11am    
copy-paste your code block for textbox1's keyspress event
StackQ 21-Sep-12 2:19am    
Now u should see once again,my updated question
Aarti Meswania 21-Sep-12 2:27am    
ok you have to create custom event to achieve this functionality
StackQ 21-Sep-12 2:30am    
how can i do it,bcoz i m a beginner ,so can u give me some idea or guide through code,i have also pasted my user control and forms code.
C#
private void textBox1_TextChanged(object sender, EventArgs e)
        {
            textBox2.Text = textBox1.Text;
        }

:):):)

Regard
Sham
 
Share this answer
 
Comments
StackQ 21-Sep-12 2:24am    
there is not the textchanged event in my user control ui component.Lol
StackQ 21-Sep-12 2:25am    
u should see once again my updated question and then reply.
Shambhoo kumar 22-Sep-12 7:42am    
Hello my swt frnd ..plz u go ur usercontrol page and double click the textbox field and add this code ur code behind page

textBox2.Text = textBox1.Text;

and then go build option and rebuild ur application.and then run ur application
just write Textbox1.Text=TextBox2.Text in TextChanged event of TextBox1
 
Share this answer
 
Comments
StackQ 21-Sep-12 2:41am    
THERE is not the textChanged event bcoz this is not simple textbox,this textbox is in user control UI component.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900