Search:
Namespaces
Discussions
.NET v1.1
Feedback
RichTextBox Label URL?
Messages
Related Types
This message was discovered on
microsoft.public.dotnet.languages.vb
.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...
JZ
Hi,
I remember reading sometime ago that is possible to create a RichtextBox
label.
Has anyone got any source or a URL.
I'm looking for improvements on just setting ReadOnly = true or Enabled =
false.
Something which hides the caret / selection character.
Help!!!!!!!!!!!!!!!!!!!
--
JZ
Reply to this message...
JZ
Hi,
I have come up with a solution, its not 100% but I think its as good as I'm
going to get it.
If you click and move your mouse over the label from start to finish you get
a little flicker.
But apart from that it works, you can still use URLs too.
Well just in case anyone is reading this in the future here's to code....
Imports System.Windows.Forms
Imports System.ComponentModel
Public Class ReadOnlyRichTextBox
Inherits
RichTextBox
Private Declare Auto Function HideCaret Lib "user32.dll" (ByVal hwnd As
IntPtr) As Int32
Protected Overrides Sub OnGotFocus(ByVal e As EventArgs)
HideCaret(Me.Handle)
End Sub
Protected Overrides Sub OnEnter(ByVal e As EventArgs)
HideCaret(Me.Handle)
End Sub
<DefaultValue(True)> Public Shadows Property [ReadOnly]() As Boolean
Get
Return True
End Get
Set(ByVal Value As Boolean)
End Set
End Property
<DefaultValue(False)> Public Shadows Property TabStop() As Boolean
Get
Return False
End Get
Set(ByVal Value As Boolean)
End Set
End Property
Public Sub New()
MyBase.ReadOnly = True
MyBase.TabStop = False
Me.SetStyle(
ControlStyles
.Selectable, False)
HideCaret(Me.Handle)
End Sub
Private Sub ReadOnlyRichTextBox_SelectionChanged(ByVal sender As Object,
ByVal e As System.EventArgs) Handles MyBase.SelectionChanged
Me.SelectionLength = 0
HideCaret(Me.Handle)
End Sub
Private Sub ReadOnlyRichTextBox_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
HideCaret(Me.Handle)
End Sub
Private Sub ReadOnlyRichTextBox_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp
HideCaret(Me.Handle)
End Sub
End Class
If anyone improves on that please post in here, even months ahead.
--
JZ
Reply to this message...
JZ
In fact if you don't need to use URLs then you can add.
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
' WM_NCLBUTTONDOWN WM_LBUTTONDOWN
If Me.ReadOnly AndAlso (m.Msg = &HA1 OrElse m.Msg = &H201) Then
Console
.WriteLine("ignored")
Return 'ignore it
End If
MyBase.WndProc(m)
End Sub 'WndProc
I also forgot to mention that you'd need to change the borderstyle to none
and the background color.
--
JZ
Reply to this message...
Imran Koradia (VIP)
If you simply want to hide the caret, here's a link:
http://tinyurl.com/3kkdc
hope this helps..
Imran.
"JZ" <
Click here to reveal e-mail address
> wrote in message
news:413f4cb4$0$29907$
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
JZ
Yeah I'd seen that, I've tried various events but it still shows selection.
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
HideCaret(Me.RichTextBox1.Handle)
End Sub
Private Sub RichTextBox1_Enter(ByVal sender As Object, ByVal e As
System.EventArgs) Handles RichTextBox1.Enter
HideCaret(Me.RichTextBox1.Handle)
End Sub
Private Sub RichTextBox1_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles RichTextBox1.MouseDown
HideCaret(Me.RichTextBox1.Handle)
End Sub
Private Sub RichTextBox1_MouseEnter(ByVal sender As Object, ByVal e As
System.EventArgs) Handles RichTextBox1.MouseEnter
HideCaret(Me.RichTextBox1.Handle)
End Sub
Private Sub RichTextBox1_SelectionChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles RichTextBox1.SelectionChanged
RichTextBox1.SelectionStart = 0
RichTextBox1.SelectionLength = 0
HideCaret(Me.RichTextBox1.Handle)
End Sub
Private Sub RichTextBox1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles RichTextBox1.MouseUp
HideCaret(Me.RichTextBox1.Handle)
End Sub
Any further advice?
--
JZ
Reply to this message...
Imran Koradia (VIP)
try these:
http://www.syncfusion.com/FAQ/WinForms/FAQ_c94c.asp#q949q
http://www.syncfusion.com/FAQ/WinForms/FAQ_c94c.asp#q866q
hope that helps..
Imran.
"JZ" <
Click here to reveal e-mail address
> wrote in message
news:413f65cd$0$29953$
Click here to reveal e-mail address
...
> Yeah I'd seen that, I've tried various events but it still shows
selection.
[Original message clipped]
Reply to this message...
JZ
Hi,
Well I think a combination of
'--------
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
' WM_NCLBUTTONDOWN WM_LBUTTONDOWN
If Me.ReadOnly AndAlso (m.Msg = &HA1 OrElse m.Msg = &H201) Then
Console
.WriteLine("ignored")
Return 'ignore it
End If
MyBase.WndProc(m)
End Sub 'WndProc
'--------
And
'--------
HideCaret(Me.RichTextBox1.Handle)
'--------
Should do it, but I haven't quite figured it out yet.
Its late in the UK, I'll work on it tomorrow.
Thanks,
--
JZ
"Imran Koradia" <
Click here to reveal e-mail address
> wrote in message
news:Ob%
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
thomas wenning
Hi JZ,
use this
http://www.codeproject.com/vb/net/rtflabelcp.asp
Greeting
Thomas
"JZ" <
Click here to reveal e-mail address
> schrieb im Newsbeitrag
news:413f4cb4$0$29907$
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
JZ
That still shows the selected text, not really a label!
--
JZ
Reply to this message...
System.Console
System.EventArgs
System.IntPtr
System.Windows.Forms.ControlStyles
System.Windows.Forms.Message
System.Windows.Forms.MouseEventArgs
System.Windows.Forms.RichTextBox
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com