Home All Groups Group Topic Archive Search About

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

Author
11 Feb 2007 5:08 PM
Ben
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
Author
12 Feb 2007 12:26 PM
Kevin Spencer
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

--
HTH,

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

The shortest distance between 2 points is a curve.

Show quoteHide quote
"Ben" <B**@discussions.microsoft.com> wrote in message
news:A62D43EA-4B34-4ABA-92D3-DB429254394A@microsoft.com...
> 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
Are all your drivers up to date? click for free checkup

Author
12 Feb 2007 5:37 PM
Ben
Hey Kevin,
Thanks a alot,
I'll have a look at that.

Ben

Show quoteHide quote
"Kevin Spencer" wrote:

> 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
>
> --
> HTH,
>
> Kevin Spencer
> Microsoft MVP
> Software Composer
> http://unclechutney.blogspot.com
>
> The shortest distance between 2 points is a curve.
>
> "Ben" <B**@discussions.microsoft.com> wrote in message
> news:A62D43EA-4B34-4ABA-92D3-DB429254394A@microsoft.com...
> > 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
>
>
>
Author
13 Feb 2007 7:59 AM
Ben
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
Author
13 Feb 2007 7:33 PM
Mattias Sjögren
>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

--
Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Author
13 Feb 2007 9:03 PM
Ben
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

Bookmark and Share