473,394 Members | 1,887 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Need help with windows form

Hi,

I have a windows form written in C#. The form has multiple textboxes
and multiple buttons.

I want to create a form where when the users clicks on a particulat
textbox and then clicks on a button, a text is added to that textbox.

How do i go about doing this when a user selects on any textbox and
clicks on a buttont to insert text, it insert the text in the correct
textbox (the textbox that the user selected before clicking on the
button)?

Any help is really appreciated.

Thanks,

Sean

Jan 5 '07 #1
4 1585
newbie schrieb:
I want to create a form where when the users clicks on a particulat
textbox and then clicks on a button, a text is added to that textbox.

How do i go about doing this when a user selects on any textbox and
clicks on a buttont to insert text, it insert the text in the correct
textbox (the textbox that the user selected before clicking on the
button)?
Do you mean somethin like ?

private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = textBox2.SelectedText;
}
Jan 5 '07 #2
Not really,

Say they click on button1, it will always add the text "TEST" to the
textbox the cursor was on.

How do I know which textbox to add the word "TEST" too since there are
multiple textboxes on the form and it can be a different textbox
everytime depending on which text box they were working on.
Sonya wrote:
newbie schrieb:
I want to create a form where when the users clicks on a particulat
textbox and then clicks on a button, a text is added to that textbox.

How do i go about doing this when a user selects on any textbox and
clicks on a buttont to insert text, it insert the text in the correct
textbox (the textbox that the user selected before clicking on the
button)?

Do you mean somethin like ?

private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = textBox2.SelectedText;
}
Jan 5 '07 #3
newbie wrote:
Not really,

Say they click on button1, it will always add the text "TEST" to the
textbox the cursor was on.

How do I know which textbox to add the word "TEST" too since there are
multiple textboxes on the form and it can be a different textbox
everytime depending on which text box they were working on.

i needed to do something similar. i needed to find out what control
had focus "prior" to clicking or giving focus to a different control,
like a button.

so, what i did was use the MouseEnter event for a button and a
"focusFlag". this way i knew what control (a textbox in this case) had
focus, before the mouse click on the button occurred.

it's a hokey kind of way to do it, but it worked for me.
private void btnClear_MouseEnter(object sender, EventArgs e)
{
////get the focus before the mouse click occurs
if (tbProduct.Focused)
focusFlag = "tbProduct";
else if (tbProductCode.Focused)
focusFlag = "tbProductCode";
}

Jan 6 '07 #4
newbie napisaƂ(a):
Not really,

Say they click on button1, it will always add the text "TEST" to the
textbox the cursor was on.

How do I know which textbox to add the word "TEST" too since there are
multiple textboxes on the form and it can be a different textbox
everytime depending on which text box they were working on.
Sonya wrote:
>newbie schrieb:
>>I want to create a form where when the users clicks on a particulat
textbox and then clicks on a button, a text is added to that textbox.

How do i go about doing this when a user selects on any textbox and
clicks on a buttont to insert text, it insert the text in the correct
textbox (the textbox that the user selected before clicking on the
button)?
Do you mean somethin like ?

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

In your form declare programmaticaly TextBox (without declaring any
additional information like position, size, text etc.) and for all of
you textboxes add *the same* event on TextBoxClick and the same event on
ButtonClick. Here is the code.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
namespace test
{
public partial class Form1 : Form
{
private TextBox lastSelectedTextBox;
public Form1()
{
InitializeComponent();
foreach(Control c in this.Controls)
{
if(c is TextBox)
((TextBox) c).Click +=new EventHandler(TextBoxClick);
else if (c is Button)
((Button) c).Click +=new EventHandler(ButtonClick);
}
}
private void TextBoxClick(object sender, EventArgs e)
{
lastSelectedTextBox = (TextBox) sender;
}
private void ButtonClick(object sender, EventArgs e)
{
label1.Text = lastSelectedTextBox.Text + " from " +
((Button)sender).Text;
}
}
}
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Jan 6 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Bilo | last post by:
I have a Windows Forms Class MainGUI I have declared MainGUI maingui; public System.ComponentModel.Container components = new Container(); in the Class I call another class MediaDriver with...
5
by: MFC | last post by:
Ok, after three C# books, (C# How to Program, Programming in the Key of C#, and C# Weekend Crash Course) and three weeks, I believe I have tried everything to make a certain form function...
6
by: billr | last post by:
I have developed a small API for taking care of a lot of boiler plate stuff in a multi formed windows application, for example setting up a messaging thread framework. New Forms, in the...
3
by: Larry | last post by:
I've set up a list of image filesnames in a listview control(lvSrcFileList), I'm using the selectedIndexChange event to select which file is being displayed in a picturebox control(pbImagePreview)....
3
by: chris | last post by:
Hallo, I am in need of a replacement for the Microsoft Visual Studio .NET. The reason is quiet simple. I develop forms which are used on different microsoft windows platform, and one...
11
by: CM Manager via DotNetMonster.com | last post by:
I am very frustrated due to this exception error I am receiving. I've tried searching numerous user support groups, Microsoft Support Net, Google, etc. and haven't found exactly my situation....
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
3
by: Tony Girgenti | last post by:
Hello. I'm new to all of this. I developed a web consuming windows application/form program with VS.NET 2003, VB, .Net Framework 1.1.4322, ASP.NET 1.1.4322, IIS 5.1. I started converting it...
5
by: Ming Yeung | last post by:
I was wondering if .NET had the equivalent of Frames, Global Objects, and most importantly DataModules like in Delphi?
3
by: Terry Olsen | last post by:
I'm trying to add a domain user to a local group using the code below: Dim LCL As New DirectoryEntry("WinNT://" + Environment.MachineName + ",computer") Dim DOM As New...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.