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 4 1599
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(o bject sender, EventArgs e)
{
textBox1.Text = textBox2.Select edText;
}
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(o bject sender, EventArgs e)
{
textBox1.Text = textBox2.Select edText;
}
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_MouseE nter(object sender, EventArgs e)
{
////get the focus before the mouse click occurs
if (tbProduct.Focu sed)
focusFlag = "tbProduct" ;
else if (tbProductCode. Focused)
focusFlag = "tbProductCode" ;
}
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(o bject sender, EventArgs e) { textBox1.Tex t = textBox2.Select edText; }
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 lastSelectedTex tBox;
public Form1()
{
InitializeCompo nent();
foreach(Control c in this.Controls)
{
if(c is TextBox)
((TextBox) c).Click +=new EventHandler(Te xtBoxClick);
else if (c is Button)
((Button) c).Click +=new EventHandler(Bu ttonClick);
}
}
private void TextBoxClick(ob ject sender, EventArgs e)
{
lastSelectedTex tBox = (TextBox) sender;
}
private void ButtonClick(obj ect sender, EventArgs e)
{
label1.Text = lastSelectedTex tBox.Text + " from " +
((Button)sender ).Text;
}
}
}
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 the Constructor
class MediaDriver
{
|
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 correctly. I am
trying to learn C# after playing around for a bit with procedural
programming with PHP, not OOP, and believe I have learned quite a bit
in three weeks, just not enough to accomplish this one task.
If anyone has a bit of free time and...
|
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 appllication using the API, are subclassed to a Form
contained within the API, and they are controlled (controlled in this
instance means, kept alive, displayed and hidden) at runtime by a thread
whose responsibility is this sole task.
In order to run...
|
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). The first time a filename
is selected it works fine but if I try to select another filename the
program bombs with an exception error; flagging the line below "curntImage =
Image.FromFile(cpath). The listview is set for a single selection....
|
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 microsoft windows platform spoils
the other microsoft windows platform. For example: I have two
projects, one for pc
and one for pocket pc. I would like (or better I have to) share the
| |
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. Hopefully someone here can help.
I am just learning VB.NET and purchased the SAM's "Teach Yourself VB.NET
2003 in 21 days' book. I am trying to connect to an Access database I created
locally on my computer per Chapter 16. I originally had it on a...
|
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
communicate with a MySQL database table on a web server, from inside
of my company's Access-VBA application. I know VBA pretty well but
have never before needed to do this HTTP/XML/MySQL type functions.
|
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 to an ASP.NET Web Application because i thought it
would be neater to have the explorer interface.
However, it has become quite a learning experience trying to understand how
|
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?
|
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 DirectoryEntry("WinNT://us.ups.com")
Dim DOMUSR As DirectoryEntry = DOM.Children.Find("USERID", "user")
Dim LCLGRP As DirectoryEntry = LCL.Children.Find("LOCAL_GROUP", "group")
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |