I'm trying to AppendText to a TextEdit. I have a procedure that will
go through the controls on a Windows form and return the control that has
"focus".
I have a number of TextEdits on my form and don't know which control
has focus.
I then want to paste text from the ClipBoard to this TextEdit control.
The following code is what I'm using. Everything works fine, it identifies
the correct control,
however, in a previous version I had this narly switch/case process and
would AppendText to
hard coded TextBox1.Append Text for example. Now that I just get back the
Control.Name,
I can figure out how to AppendText when I get back the Control object.
object o;
o = Clipboard.GetDa taObject().GetD ata("Text");
if (o != null)
{
if (o.GetType().To String() == "System.String" )
TextEdit1.Appen dText((string)o );
}
How do I modify the above code to use the returned Control Name instead of
the actual "TextEdit1.Appe ndText" ?
TIA,
--
Fritz 3 3061
Hi Fritz
Assuming you mean a TextBox when you talk about TextEdit, and you have a
reference to a Control, you can easily cast Control to TextBox (if the
object being referenced in Control is actually a TextBox)
// c is the focused Control
string text = Clipboard.GetDa taObject().GetD ata("Text") as string;
TextBox tb = c as TextBox;
if (text != null && tb != null)
tb.AppendText(t ext);
The 'as' keyword will cast the object to another type if possible. If
not, the result will be null.
Another method is using the 'is' keyword
object o = ClipBoard....
string text = null;
if(o is string)
text = o.ToString();
Now, you don't really need a TextBox to append text to a Control as
Control has a Text property. The code below would do the same as the above
string text = Clipboard.GetDa taObject().GetD ata("Text") as string;
if (text != null)
c.Text += text;
--
Happy Coding!
Morten Wennevik [C# MVP]
Morten,
Yes, I have a custom control extended from a textBox.
Your solution worked.
Thank you for the response and explanation and your contributions to the C#
community. It was greatly appreciated.
--
Fritz
"Morten Wennevik" <Mo************ @hotmail.comwro te in message
news:op******** *******@tr024.b ouvet.no...
Hi Fritz
Assuming you mean a TextBox when you talk about TextEdit, and you have a
reference to a Control, you can easily cast Control to TextBox (if the
object being referenced in Control is actually a TextBox)
// c is the focused Control
string text = Clipboard.GetDa taObject().GetD ata("Text") as string;
TextBox tb = c as TextBox;
if (text != null && tb != null)
tb.AppendText(t ext);
The 'as' keyword will cast the object to another type if possible. If
not, the result will be null.
Another method is using the 'is' keyword
object o = ClipBoard....
string text = null;
if(o is string)
text = o.ToString();
Now, you don't really need a TextBox to append text to a Control as
Control has a Text property. The code below would do the same as the above
string text = Clipboard.GetDa taObject().GetD ata("Text") as string;
if (text != null)
c.Text += text;
--
Happy Coding!
Morten Wennevik [C# MVP]
On Wed, 22 Nov 2006 17:32:55 +0100, Fritz Switzer
<fr***********@ abletfactory.co mwrote:
Morten,
Yes, I have a custom control extended from a textBox.
Your solution worked.
Thank you for the response and explanation and your contributions to the
C#
community. It was greatly appreciated.
Happy to help :)
--
Happy Coding!
Morten Wennevik [C# MVP] This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Greg F. |
last post by:
Dear Folks:
Question #1:
I have not been able to find a method to acknowledge or indicate that a
form is open (not necessarily have the focus). Any ideas on how to
check if a particular form is open from VBA?
Question #2:
Is there anyway to trigger an event or DETECT that the Alt key (or any
other key like SHIFT or CTRL) has been pressed down while CLICKING on a
|
by: Armando |
last post by:
Hey again -
I have a bunch of similar controls on a form (A2000), and I'm calling the
same code (with an argument as to what was clicked) when any one of them is
clicked. I'd like to generalize the code without having to modify EACH one
with a self-specific parameter in the call. That is, instead of calling...
called_when_clicked ("A1")
I just want to run:
|
by: Don Riesbeck Jr. |
last post by:
I'm working on an application (OEM) using C# that utilizes input from a
keyboard, and USB Barcode Scanner. The scanner is a HID Keyboard device,
and input from it is sent to the system as if it were a keyboard. I need to
be able to identify input from the scanner and keyboard independently. I've
looked at DirectX.DirectInput, and using user32.dll to hook into the
keyboard messages, but neither method seems to allow for identification of...
|
by: User N |
last post by:
I have a log class with static methods that grab and release a mutex as
required. The log class is designed to be called from both GUI and
thread pool threads, and dump output to a logfile and a RichEditBox.
To give you some idea of the approach I took...
private static RichTextBox rtb;
private delegate void RtbAppendTextHandler(string output);
private static RtbAppendTextHandler RtbAppendText;
Log.Init(RichTextBox richTextBox,...
|
by: clickon |
last post by:
For testing purposes i have got a 2 step WizardControl. Eqach step contains
a text box, TextBox1 and TextBox2 respectively. If i put the following code
in the respective activate event handlers for the two steps,
TextBox1.Text ="foo";
and
TextBox2.Text = "bar";
| |
by: ChrisUttenreither |
last post by:
Hello folks. I'm writing a Roguelike game in C#. Fun stuff. The game
includes a map that is made entirely of colored ASCII art in a
monospace font. I would like to make this map a control in the main
form.
My first attempt was with RichTextBox. I wanted to set the background
to black. After cruising newsgroups I determined that wasn't possible.
My second attempt involves an AxSHDocVw.AxWebBrowser control. I got
this by adding...
|
by: Jon Slaughter |
last post by:
I've created some custom controls and forms that allow the feature to
temporarily transfer focus to a control that has been entered by the mouse.
Everything seems to work fine but the problem I have is that sometimes I
seem to loose the original "holder" of focus and when the user hits tab
while using "temporary" focus(while the mouse is over a control) it will
change focus to the next control but not update it.
So I have several issues....
|
by: John |
last post by:
Hi
How can I add some txt in red and other in grey to a rich text control?
Thanks
Regards
|
by: jontcaz |
last post by:
Good Day,
I have an application that will send text out of a serial port if i hold down the "1" key for 2 seconds. I am currently just turning a chime on and off but want to expand this to the ability to turn my amplifier on/off etc. I want this to be running in the background but to respond at any time by just hitting a certain key. The program works great one time when i execute, but goes into hide and i never see it again. Any suggestions...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |