Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2007

Tip: Looking for answers? Try searching our database.

A Label control that its text can be selected with the mouse

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ben - 11 Feb 2007 17:08 GMT
Hi,

Is there a way to allow the Label control to select its text with the mouse
by the user?
I've looked at the Label's properties but I couldn't find anything making
this possible.
Am I missing something here? Well, it can be done with a Textbox control,
but the problem with this approach is that when I click on a read only
Textbox, a vertical line is displayed inside it.
In short, I want something similar to internet browsers, where users can
select the text and copy it to the clipboard.

Thanks for your time,

Ben
Kevin Spencer - 12 Feb 2007 12:26 GMT
You're have to use the Windows API to do this, hiding and showing the caret
according to TextBox events. See the following:

http://www.pinvoke.net/default.aspx/user32/HideCaret.html
http://www.pinvoke.net/default.aspx/user32/ShowCaret.html

Signature

HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

The shortest distance between 2 points is a curve.

> Hi,
>
[quoted text clipped - 12 lines]
>
> Ben
Ben - 12 Feb 2007 17:37 GMT
Hey Kevin,
Thanks a alot,
I'll have a look at that.

Ben

> You're have to use the Windows API to do this, hiding and showing the caret
> according to TextBox events. See the following:
[quoted text clipped - 18 lines]
> >
> > Ben
Ben - 13 Feb 2007 07:59 GMT
HideCaret fails, and when i call Marshal.GetLastWin32Error, it
returns a value of 5, which i think means access denied.
How can i make this work please?

Thanks,
Ben
Mattias Sjögren - 13 Feb 2007 19:33 GMT
>HideCaret fails, and when i call Marshal.GetLastWin32Error, it
>returns a value of 5, which i think means access denied.
>How can i make this work please?

The declaration at pinvoke.net didn't have SetLastError=true in the
DllImport attribute. Did you add that? If not, you can't expect
GetLastWin32Error to return the right error code.

Mattias

Signature

Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Ben - 13 Feb 2007 21:03 GMT
Hi Mattias,

Yes, I did add "SetLastError=true" to the attribute.
I have no idea why I get access denied when I call HideCaret.

Thanks,
Ben

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.