i just added "is nothing" to get rid or error that i posted below. but
it is not displaying in richtextbox. all i seeing is debug window.
Dim nrtb As New RichTextBox
Sub DisplayMessage(ByVal rtb As RichTextBox, ByVal sText As String,
Optional ByVal Colour As String = "")
If rtb.SelectedText Is Nothing Then
rtb.SelectionStart = rtb.Text.Length
' rtb.doColor(rtb, DirectCast(sText, String))
' rtb.doColor(rtb, CType(sText, String))
rtb.SelectedText = nrtb.doColor(sText)
rtb.SelectionStart = rtb.Text.Length
rtb.ScrollToCaret()
sText = String.Empty
End If
End Sub
ne hints?
regards 5 1111
Hi,
The richtextbox does not have a doColor method kind of confused as
to what you are trying to do. If you are trying to change the color of the
selected text try some like this.
RichTextBox1.HideSelection = False ' Text stays selected if richtextbox
doesnt have focus
RichTextBox1.Focus()
RichTextBox1.SelectAll()
RichTextBox1.SelectionColor = Color.Green ' will make all the text green.
Ken
----------------------
"Supra" <su*****@rogers.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
i just added "is nothing" to get rid or error that i posted below. but it is
not displaying in richtextbox. all i seeing is debug window.
Dim nrtb As New RichTextBox
Sub DisplayMessage(ByVal rtb As RichTextBox, ByVal sText As String, Optional
ByVal Colour As String = "")
If rtb.SelectedText Is Nothing Then
rtb.SelectionStart = rtb.Text.Length
' rtb.doColor(rtb, DirectCast(sText, String))
' rtb.doColor(rtb, CType(sText, String))
rtb.SelectedText = nrtb.doColor(sText)
rtb.SelectionStart = rtb.Text.Length
rtb.ScrollToCaret()
sText = String.Empty
End If
End Sub
ne hints?
regards
in userconrtrol i named doColour... but also i added method called
doColor....please have a look .....
in usercontrol......:
Option Explicit On
Option Strict Off
Imports System.Runtime.InteropServices
Imports System.Drawing
Namespace PirateChat
<System.ComponentModel.DesignerCategoryAttribute(" UserControl")> _
Public Class RichTextBox
Inherits System.Windows.Forms.RichTextBox
Private Declare Function GetScrollRange Lib "User32" (ByVal hWnd
As IntPtr, ByVal nBar As Integer, ByRef lpMinPos As Integer, ByRef
lpMaxPos As Integer) As Boolean
Function doColor(ByVal a As String)
Dim b As String, n, fgcolor, bgcolor As Integer
Dim colour() As Color = {Color.White, Color.Black,
Color.DarkBlue, Color.DarkGreen, Color.Red, Color.Brown, _
Color.Purple, Color.Orange,
Color.Yellow, Color.LightGreen, Color.DarkMagenta, Color.SkyBlue, _
Color.Blue, Color.Magenta,
Color.Gray, Color.LightSlateGray}
Dim rtb As RichTextBox
rtb = New RichTextBox
fgcolor = 1
bgcolor = 0
For n = 1 To a.Length
b = Mid(a, n, 1)
If b = Chr(3) Then
'Parse Colours
If IsNumeric(Mid(a, n + 1, 1)) Then
If IsNumeric(Mid(a, n + 2, 1)) Then
If Mid(a, n + 3, 1) = "," Then
If IsNumeric(Mid(a, n + 4, 1)) Then
If IsNumeric(Mid(a, n + 5, 1)) Then
'@##,##
fgcolor = CInt(Mid(a, n + 1, 2))
bgcolor = CInt(Mid(a, n + 4, 2))
n += 5
Else
'@##,#
fgcolor = CInt(Mid(a, n + 1, 2))
bgcolor = CInt(Mid(a, n + 4, 1))
n += 4
End If
Else
'@##,
fgcolor = CInt(Mid(a, n + 1, 2))
n += 3
End If
Else
'@##
fgcolor = CInt(Mid(a, n + 1, 2))
n += 2
End If
ElseIf Mid(a, n + 2, 1) = "," Then
If IsNumeric(Mid(a, n + 3, 1)) Then
If IsNumeric(Mid(a, n + 4, 1)) Then
'@#,##
fgcolor = CInt(Mid(a, n + 1, 1))
bgcolor = CInt(Mid(a, n + 3, 2))
n += 4
Else
'@#,#
fgcolor = CInt(Mid(a, n + 1, 1))
bgcolor = CInt(Mid(a, n + 3, 1))
n += 3
End If
Else
'@#,
fgcolor = CInt(Mid(a, n + 1, 1))
n += 2
End If
Else
'@#
fgcolor = CInt(Mid(a, n + 1, 1))
n = n + 1
End If
If fgcolor > 15 Then
fgcolor = 1
End If
If bgcolor > 15 Then
bgcolor = 0
End If
rtb.SelectionColor = colour(fgcolor)
SelectionBackColor = colour(bgcolor)
Else
rtb.SelectionColor = colour(1)
SelectionBackColor = colour(0)
End If
ElseIf b = Chr(2) Then
Dim IsBold As Boolean = ((rtb.SelectionFont.Style
And FontStyle.Bold) = FontStyle.Bold)
rtb.SelectionFont = _
New Font(rtb.SelectionFont,
DirectCast(IIf(IsBold, rtb.SelectionFont.Style And Not FontStyle.Bold,
rtb.SelectionFont.Style Or FontStyle.Bold), FontStyle))
ElseIf b = Chr(31) Then
Dim IsUnderline As Boolean =
((rtb.SelectionFont.Style And FontStyle.Underline) = FontStyle.Underline)
rtb.SelectionFont = _
New Font( _
rtb.SelectionFont, _
DirectCast(IIf(IsUnderline,
rtb.SelectionFont.Style And Not FontStyle.Underline,
rtb.SelectionFont.Style Or FontStyle.Underline), FontStyle))
ElseIf b = Chr(22) Then
Dim IsItalic As Boolean = ((rtb.SelectionFont.Style
And FontStyle.Italic) = FontStyle.Italic)
rtb.SelectionFont = _
New Font( _
rtb.SelectionFont, _
DirectCast(IIf(IsItalic,
rtb.SelectionFont.Style And Not FontStyle.Italic,
rtb.SelectionFont.Style Or FontStyle.Italic), FontStyle))
ElseIf b = "" Then
b = Mid(a, n, 1)
Else
' rtb.SelectedText = DirectCast(b.ToString, String)
' rtb.SelectedText = CType(b, String) '.ToString
rtb.SelectedText = b.ToString
End If
Next n
End Function
ne hints u cann help me?
regsrds,
Ken Tucker [MVP] wrote: Hi,
The richtextbox does not have a doColor method kind of confused as to what you are trying to do. If you are trying to change the color of the selected text try some like this.
RichTextBox1.HideSelection = False ' Text stays selected if richtextbox doesnt have focus
RichTextBox1.Focus()
RichTextBox1.SelectAll()
RichTextBox1.SelectionColor = Color.Green ' will make all the text green. Ken
---------------------- "Supra" <su*****@rogers.com> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl... i just added "is nothing" to get rid or error that i posted below. but it is not displaying in richtextbox. all i seeing is debug window.
Dim nrtb As New RichTextBox Sub DisplayMessage(ByVal rtb As RichTextBox, ByVal sText As String, Optional ByVal Colour As String = "") If rtb.SelectedText Is Nothing Then rtb.SelectionStart = rtb.Text.Length ' rtb.doColor(rtb, DirectCast(sText, String)) ' rtb.doColor(rtb, CType(sText, String)) rtb.SelectedText = nrtb.doColor(sText) rtb.SelectionStart = rtb.Text.Length rtb.ScrollToCaret() sText = String.Empty End If End Sub
ne hints? regards
ths code in posted above will woked both fore and background colour
that embedded in richtextbox. it is similar to mirc chat colour. that i
done this in vb6.
refards
Supra wrote: in userconrtrol i named doColour... but also i added method called doColor....please have a look ..... in usercontrol......: Option Explicit On Option Strict Off
Imports System.Runtime.InteropServices Imports System.Drawing
Namespace PirateChat <System.ComponentModel.DesignerCategoryAttribute(" UserControl")> _ Public Class RichTextBox Inherits System.Windows.Forms.RichTextBox
Private Declare Function GetScrollRange Lib "User32" (ByVal hWnd As IntPtr, ByVal nBar As Integer, ByRef lpMinPos As Integer, ByRef lpMaxPos As Integer) As Boolean
Function doColor(ByVal a As String) Dim b As String, n, fgcolor, bgcolor As Integer Dim colour() As Color = {Color.White, Color.Black, Color.DarkBlue, Color.DarkGreen, Color.Red, Color.Brown, _ Color.Purple, Color.Orange, Color.Yellow, Color.LightGreen, Color.DarkMagenta, Color.SkyBlue, _ Color.Blue, Color.Magenta, Color.Gray, Color.LightSlateGray} Dim rtb As RichTextBox rtb = New RichTextBox fgcolor = 1 bgcolor = 0
For n = 1 To a.Length b = Mid(a, n, 1) If b = Chr(3) Then 'Parse Colours If IsNumeric(Mid(a, n + 1, 1)) Then If IsNumeric(Mid(a, n + 2, 1)) Then If Mid(a, n + 3, 1) = "," Then If IsNumeric(Mid(a, n + 4, 1)) Then If IsNumeric(Mid(a, n + 5, 1)) Then '@##,## fgcolor = CInt(Mid(a, n + 1, 2)) bgcolor = CInt(Mid(a, n + 4, 2)) n += 5 Else '@##,# fgcolor = CInt(Mid(a, n + 1, 2)) bgcolor = CInt(Mid(a, n + 4, 1)) n += 4
End If Else '@##, fgcolor = CInt(Mid(a, n + 1, 2)) n += 3
End If Else '@## fgcolor = CInt(Mid(a, n + 1, 2)) n += 2 End If
ElseIf Mid(a, n + 2, 1) = "," Then If IsNumeric(Mid(a, n + 3, 1)) Then If IsNumeric(Mid(a, n + 4, 1)) Then '@#,## fgcolor = CInt(Mid(a, n + 1, 1)) bgcolor = CInt(Mid(a, n + 3, 2)) n += 4 Else '@#,# fgcolor = CInt(Mid(a, n + 1, 1)) bgcolor = CInt(Mid(a, n + 3, 1)) n += 3
End If Else '@#, fgcolor = CInt(Mid(a, n + 1, 1)) n += 2 End If Else '@# fgcolor = CInt(Mid(a, n + 1, 1)) n = n + 1 End If
If fgcolor > 15 Then fgcolor = 1 End If
If bgcolor > 15 Then bgcolor = 0 End If
rtb.SelectionColor = colour(fgcolor) SelectionBackColor = colour(bgcolor) Else rtb.SelectionColor = colour(1) SelectionBackColor = colour(0) End If
ElseIf b = Chr(2) Then Dim IsBold As Boolean = ((rtb.SelectionFont.Style And FontStyle.Bold) = FontStyle.Bold) rtb.SelectionFont = _ New Font(rtb.SelectionFont, DirectCast(IIf(IsBold, rtb.SelectionFont.Style And Not FontStyle.Bold, rtb.SelectionFont.Style Or FontStyle.Bold), FontStyle))
ElseIf b = Chr(31) Then Dim IsUnderline As Boolean = ((rtb.SelectionFont.Style And FontStyle.Underline) = FontStyle.Underline) rtb.SelectionFont = _ New Font( _ rtb.SelectionFont, _ DirectCast(IIf(IsUnderline, rtb.SelectionFont.Style And Not FontStyle.Underline, rtb.SelectionFont.Style Or FontStyle.Underline), FontStyle)) ElseIf b = Chr(22) Then Dim IsItalic As Boolean = ((rtb.SelectionFont.Style And FontStyle.Italic) = FontStyle.Italic) rtb.SelectionFont = _ New Font( _ rtb.SelectionFont, _ DirectCast(IIf(IsItalic, rtb.SelectionFont.Style And Not FontStyle.Italic, rtb.SelectionFont.Style Or FontStyle.Italic), FontStyle)) ElseIf b = "" Then b = Mid(a, n, 1) Else ' rtb.SelectedText = DirectCast(b.ToString, String) ' rtb.SelectedText = CType(b, String) '.ToString rtb.SelectedText = b.ToString End If Next n End Function ne hints u cann help me? regsrds,
Ken Tucker [MVP] wrote:
Hi,
The richtextbox does not have a doColor method kind of confused as to what you are trying to do. If you are trying to change the color of the selected text try some like this.
RichTextBox1.HideSelection = False ' Text stays selected if richtextbox doesnt have focus
RichTextBox1.Focus()
RichTextBox1.SelectAll()
RichTextBox1.SelectionColor = Color.Green ' will make all the text green. Ken
---------------------- "Supra" <su*****@rogers.com> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl... i just added "is nothing" to get rid or error that i posted below. but it is not displaying in richtextbox. all i seeing is debug window.
Dim nrtb As New RichTextBox Sub DisplayMessage(ByVal rtb As RichTextBox, ByVal sText As String, Optional ByVal Colour As String = "") If rtb.SelectedText Is Nothing Then rtb.SelectionStart = rtb.Text.Length ' rtb.doColor(rtb, DirectCast(sText, String)) ' rtb.doColor(rtb, CType(sText, String)) rtb.SelectedText = nrtb.doColor(sText) rtb.SelectionStart = rtb.Text.Length rtb.ScrollToCaret() sText = String.Empty End If End Sub
ne hints? regards
There is a difference between String is nothing and String.Length = 0. You
might want to try if rtb.SelectedText.Length = 0 then.
"Supra" wrote: i just added "is nothing" to get rid or error that i posted below. but it is not displaying in richtextbox. all i seeing is debug window.
Dim nrtb As New RichTextBox Sub DisplayMessage(ByVal rtb As RichTextBox, ByVal sText As String, Optional ByVal Colour As String = "") If rtb.SelectedText Is Nothing Then rtb.SelectionStart = rtb.Text.Length ' rtb.doColor(rtb, DirectCast(sText, String)) ' rtb.doColor(rtb, CType(sText, String)) rtb.SelectedText = nrtb.doColor(sText) rtb.SelectionStart = rtb.Text.Length rtb.ScrollToCaret() sText = String.Empty End If End Sub
ne hints? regards
Generaly you should avoid giving your custom controls the same name as .Net
controls. The namespace hierarchy searches the referenced Framework
namespaces first, then it looks at other references, next the Imports
statements namespaces and finally the namespaces defined in the project.
Your declaration ...
Dim nrtb As New RichTextBox
will create a .Net RichTextBox instance because you have not specified the
namespace. Therefore of the namespace hierarchy finds
System.Windows.Forms.RichTextBox first since it is in a referenced Framework
namespace. Now to create an instance of your RichTextBox you need the
declaration ...
Dim nrtb As New PirateChat.RichTextBox
as this specifies what namespace to look in. Since there is no PirateChat
Framework namespace the searching for PirateChat.RichTextBox goes to your
PirateChat namespace where your custom RichTextBox is found.
Again, avoid using the same classnames for your classes as thoes in the
Framework. This is particularly true for classes you are extending through
inheritance as it will be very confusing. Just look at all the trouble you
have gone through to find the true problem with your code.
Robby
"Supra" <su*****@rogers.com> wrote in message
news:eR**************@TK2MSFTNGP09.phx.gbl... in userconrtrol i named doColour... but also i added method called doColor....please have a look ..... in usercontrol......: Option Explicit On Option Strict Off
Imports System.Runtime.InteropServices Imports System.Drawing
Namespace PirateChat <System.ComponentModel.DesignerCategoryAttribute(" UserControl")> _ Public Class RichTextBox Inherits System.Windows.Forms.RichTextBox
Private Declare Function GetScrollRange Lib "User32" (ByVal hWnd As IntPtr, ByVal nBar As Integer, ByRef lpMinPos As Integer, ByRef lpMaxPos As Integer) As Boolean
Function doColor(ByVal a As String) Dim b As String, n, fgcolor, bgcolor As Integer Dim colour() As Color = {Color.White, Color.Black, Color.DarkBlue, Color.DarkGreen, Color.Red, Color.Brown, _ Color.Purple, Color.Orange, Color.Yellow, Color.LightGreen, Color.DarkMagenta, Color.SkyBlue, _ Color.Blue, Color.Magenta, Color.Gray, Color.LightSlateGray} Dim rtb As RichTextBox rtb = New RichTextBox fgcolor = 1 bgcolor = 0
For n = 1 To a.Length b = Mid(a, n, 1) If b = Chr(3) Then 'Parse Colours If IsNumeric(Mid(a, n + 1, 1)) Then If IsNumeric(Mid(a, n + 2, 1)) Then If Mid(a, n + 3, 1) = "," Then If IsNumeric(Mid(a, n + 4, 1)) Then If IsNumeric(Mid(a, n + 5, 1)) Then '@##,## fgcolor = CInt(Mid(a, n + 1, 2)) bgcolor = CInt(Mid(a, n + 4, 2)) n += 5 Else '@##,# fgcolor = CInt(Mid(a, n + 1, 2)) bgcolor = CInt(Mid(a, n + 4, 1)) n += 4
End If Else '@##, fgcolor = CInt(Mid(a, n + 1, 2)) n += 3
End If Else '@## fgcolor = CInt(Mid(a, n + 1, 2)) n += 2 End If
ElseIf Mid(a, n + 2, 1) = "," Then If IsNumeric(Mid(a, n + 3, 1)) Then If IsNumeric(Mid(a, n + 4, 1)) Then '@#,## fgcolor = CInt(Mid(a, n + 1, 1)) bgcolor = CInt(Mid(a, n + 3, 2)) n += 4 Else '@#,# fgcolor = CInt(Mid(a, n + 1, 1)) bgcolor = CInt(Mid(a, n + 3, 1)) n += 3
End If Else '@#, fgcolor = CInt(Mid(a, n + 1, 1)) n += 2 End If Else '@# fgcolor = CInt(Mid(a, n + 1, 1)) n = n + 1 End If
If fgcolor > 15 Then fgcolor = 1 End If
If bgcolor > 15 Then bgcolor = 0 End If
rtb.SelectionColor = colour(fgcolor) SelectionBackColor = colour(bgcolor) Else rtb.SelectionColor = colour(1) SelectionBackColor = colour(0) End If
ElseIf b = Chr(2) Then Dim IsBold As Boolean = ((rtb.SelectionFont.Style And FontStyle.Bold) = FontStyle.Bold) rtb.SelectionFont = _ New Font(rtb.SelectionFont, DirectCast(IIf(IsBold, rtb.SelectionFont.Style And Not FontStyle.Bold, rtb.SelectionFont.Style Or FontStyle.Bold), FontStyle))
ElseIf b = Chr(31) Then Dim IsUnderline As Boolean = ((rtb.SelectionFont.Style And FontStyle.Underline) = FontStyle.Underline) rtb.SelectionFont = _ New Font( _ rtb.SelectionFont, _ DirectCast(IIf(IsUnderline, rtb.SelectionFont.Style And Not FontStyle.Underline, rtb.SelectionFont.Style Or FontStyle.Underline), FontStyle)) ElseIf b = Chr(22) Then Dim IsItalic As Boolean = ((rtb.SelectionFont.Style And FontStyle.Italic) = FontStyle.Italic) rtb.SelectionFont = _ New Font( _ rtb.SelectionFont, _ DirectCast(IIf(IsItalic, rtb.SelectionFont.Style And Not FontStyle.Italic, rtb.SelectionFont.Style Or FontStyle.Italic), FontStyle)) ElseIf b = "" Then b = Mid(a, n, 1) Else ' rtb.SelectedText = DirectCast(b.ToString, String) ' rtb.SelectedText = CType(b, String) '.ToString rtb.SelectedText = b.ToString End If Next n End Function ne hints u cann help me? regsrds,
Ken Tucker [MVP] wrote:
Hi,
The richtextbox does not have a doColor method kind of confused as to what you are trying to do. If you are trying to change the color of the selected text try some like this.
RichTextBox1.HideSelection = False ' Text stays selected if richtextbox doesnt have focus
RichTextBox1.Focus()
RichTextBox1.SelectAll()
RichTextBox1.SelectionColor = Color.Green ' will make all the text green. Ken
---------------------- "Supra" <su*****@rogers.com> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl.. . i just added "is nothing" to get rid or error that i posted below. but it is not displaying in richtextbox. all i seeing is debug window.
Dim nrtb As New RichTextBox Sub DisplayMessage(ByVal rtb As RichTextBox, ByVal sText As String, Optional ByVal Colour As String = "") If rtb.SelectedText Is Nothing Then rtb.SelectionStart = rtb.Text.Length ' rtb.doColor(rtb, DirectCast(sText, String)) ' rtb.doColor(rtb, CType(sText, String)) rtb.SelectedText = nrtb.doColor(sText) rtb.SelectionStart = rtb.Text.Length rtb.ScrollToCaret() sText = String.Empty End If End Sub
ne hints? regards
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Jim Hubbard |
last post by:
It seems that Microsoft not only does not need the classic Visual Basic
developer army (the largest army of developers the world has ever seen), but
now they don't need ANY Windows developer at a...
|
by: Richard |
last post by:
In normal asp i used
---------
objRS.Open "tbl_Nieuws", objConn, 1, 3
objRS.AddNew
objRS.Fields("N_Datum") = FormatDateTime(Now(),2)
objRS.Fields("N_Title") =...
|
by: Bennett Haselton |
last post by:
Suppose I add a new row to a table in a dataset, and then I use an
OleDbDataAdapter to add that new row to a SQL Server database using
OleDbDataAdapter.Update(), as in the following code:
...
|
by: mareal |
last post by:
I have noticed how the thread I created just stops running. I have added
several exceptions to the thread
System.Threading.SynchronizationLockException
System.Threading.ThreadAbortException...
|
by: mensanator |
last post by:
Probably just me. I've only been using Access and SQL Server
for 12 years, so I'm sure my opinions don't count for anything.
I was, nevertheless, looking forward to Sqlite3. And now
that gmpy...
|
by: NDayave |
last post by:
How do,
A while ago i had the problem of backing up a Access 2002 table with unique data that changed in some tables but not others, resulting in restore failure. This was sorted by NeoPa with the...
|
by: jelle.huygen |
last post by:
Hello,
I have a problem in ASP.NET 2.0 with the viewstate of my dynamically
added user control. I have reproduced the problem with a very simple
user control and a very simple page.
On my...
|
by: Bhasker V Kode |
last post by:
Hi,
I just wanted to share with everyone a new project that i'm launching
today called the Returnable Project ( http://returnable.org )
Returnable serves as a open-platform architectural guide...
|
by: ags5406 |
last post by:
I've a listbox that I add items to at different points in the code.
It's height is such that only about 6 items can be displayed
vertically. The first item added shows up in the top line, then the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
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...
|
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,...
| |