473,322 Members | 1,314 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,322 software developers and data experts.

VB.NET Select Text in Label

Hi all,

I just joined because I've found loads of help on this site but I cant find an answer to this.

I have a form that i loads data in from a database and stores them in various controls and the address is in a label, is it possible that you can select text in the label just like in a text box and copy the text? I cant find anything that helps :(

I don't want to change it from a label to a text box since the background color of the form changes depending on a field from the database and the textbox doesn't support a transparent background (i could set the bacground of the textbox to the same as the form but seems silly just to select text!)


Hope someone can help.
Julian
Sep 30 '08 #1
5 14685
nateraaaa
663 Expert 512MB
Have you tried using the .Text property of the Label control? That should give you the text of the label.

Nathan
Sep 30 '08 #2
Frinavale
9,735 Expert Mod 8TB
If you're developing a web application then you should be able to select the text within the label. If its in a desktop application I don't think this is possible. Maybe provide a button or link that lets the user retrieve the text in these labels...like how nateraaaa was suggesting.

-Frinny
Sep 30 '08 #3
mldisibio
190 Expert 100+
If this is a Windows Form and you want your user to be able to right-click and copy the text, then you can add a ContextMenuStrip to the label with a 'Copy' ToolStripItem whose click event is handled by a simple method which copies the Label.Text to the Clipboard.

Expand|Select|Wrap|Line Numbers
  1.  
  2. ///<summary>ContextMenu to allow user to copy label text to clipboard.</summary>
  3. ContextMenuStrip createCopyMenu(EventHandler specificAction) {
  4.   ContextMenuStrip contextMenu = new ContextMenuStrip();
  5.   ToolStripItem copyCmd = contextMenu.Items.Add("Copy");
  6.   copyCmd.Click += specificAction;
  7.   return contextMenu;
  8. }
  9.  
  10. ///<summary>Copy Label text to clipboard when ContextMenu.Copy is clicked.</summary>
  11. void copyAddressCmd_Click(object sender, EventArgs e) {
  12.   Clipboard.SetDataObject(myAddressLabel.Text, false);
  13. }
  14.  
  15. myAddressLabel.ContextMenuStrip = createCopyMenu(copyAddressCmd_Click);
  16.  
The above code allows you to apply a context menu to several controls, each with their own EventHandler for clicking on the Copy command.

(Sorry, just noticed you were looking for VB.Net code. Feel free to post your port if you find it helpful.)
Sep 30 '08 #4
Its a desktop app, I thought about having a right click and copy or a button, was just wondering if its possible to have it selectable as sometimes they want to copy the entire address and others just the postcode.

Nothing to port really, just added the context strip in the designer and just added

Clipboard.SetDataObject(AddressLbl.Text, False)

to the handler, I'll just ignore the postcode for now since its not actually that important.


Thanks anyway :)
Oct 1 '08 #5
Frinavale
9,735 Expert Mod 8TB
Hey Mldisibio, would you mind turning on your PMs so that I can send you a message :)

Thanks

-Frinny
Oct 1 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: FrodoBaggins | last post by:
Dear Team, I am trying to use stylesheets on a web form. Initially, I created a folder named 'styles' within the WebUI project. In this I created the following stylesheet named...
2
by: Hareth | last post by:
i got the idea "form.textbox.text = label.text" from vb... i tried it in C# but it generated errors i found a diff example from :...
1
by: Menü Sargut | last post by:
Hey there, How can I set the BorderColor from a text Label (FixedSingle) Thanks for any help.
2
by: RobKinney1 | last post by:
Hello and thank you for reading this post. I have a RichTextBox. I need to select text inside for a search feature. Easy enough... right? Well apparently from the .NET help and everything from...
5
by: Yohan Blurp | last post by:
Hi, Here is sample page to show you the problem : <html><body> <form action="/cgi-bin/test.cgi" method="post"> Data Path : <input type="text" size="50" value="C:\Test Data\May 2007.xls"...
3
by: bhanubalaji | last post by:
hi, I am unable to disable the text(label) in javascript..it's working fine with IE,but i am using MOZILLA.. can any one help regarding this.. What's the wrong with my code? I am...
2
damonreid
by: damonreid | last post by:
Is it possible to pass a field to a text label when a form loads? I have tried Private Sub Form_Load() Dim textName As String textName = "Text Edit Text" Me.Text29 =...
1
by: kenneth6 | last post by:
Windows form app: 1. how to get text label updated? 2. how to get text label assigned with a variable value (integer / string)?
7
by: chaitanya83 | last post by:
How to select text which is in multiple lines on clicking more than twice? I have scenario like this: eg:-6118051 Non-Receipt Per web, delivery incomplete. Request trace and driver followup...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.