Solved

RichTextBox Forecolor

Posted on 2007-12-06
6
491 Views
Last Modified: 2012-08-13
I searched all the forums about this issue. I found some titles..I tried some codes like:

Private Sub Form_Click()
    RichTextBox1.SelStart = 0
    RichTextBox1.SelLength = Len(RichTextBox1.Text)
    RichTextBox1.SelColor = vbWhite
End Sub


orrrrr


Private Sub Form_Load()
    RichTextBox1.SelColor = vbWhite
    RichTextBox1.SelText = "This is red."
End Sub


but they didnt worked.... My background in RTB is "black" and I would like to set forecolor "white"..Is there any idea for this?.. Thank you
0
Comment
Question by:hakanogu
6 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 20418800
They work for me.
The _Click one turns the whole text white.
The _Load one inserts some text the selection and colours it white
0
 
LVL 2

Accepted Solution

by:
mukeshlaku earned 500 total points
ID: 20418911
Hi,

on form load event write below code, it should be one line code.

RichTextBox1.TextRTF ="{\rtf1\ansi\ansicpg1252\deff0\deflang1033\deflangfe1033{\fonttbl{\f0\froman\fprq2\fcharset0 Times New Roman;}}
{\colortbl ;\red255\green255\blue255;}
\viewkind4\uc1\pard\cf1\f0\fs24
\par }"

this will resolve your problem

regards,
Mukesh Lakum
0
 

Author Comment

by:hakanogu
ID: 20422917
0t didnt work mukeshlaku..nothinh happen..But the other codes it is working, GrahamScan as you said, but the problem:

I put the codes in Form_Click event as you did because they didnt work in Form_Load event:

Private Sub Form_Click()
    RichTextBox1.SelStart = 0
    RichTextBox1.SelLength = Len(RichTextBox1.Text)
    RichTextBox1.SelColor = vbWhite
End Sub

then I put Call command in Form_Load event:

Private Sub Form_Load
       Call Form_Click
End Sub

they changed my text to "white" ok. there is no problem but after click a command button that have the code below everything is again black and just "S1"s are yellow.





----------------------------------------------------------
CPrivate Sub CommandButton_Click

      For Counter = 1 To Len(Me.RichTextBox1.Text)
     
     StringPos = InStr(Counter, Me.RichTextBox1.Text, " S3 ", vbTextCompare)
     
     If StringPos > 0 Then
       
       Me.RichTextBox1.SelStart = StringPos
       Me.RichTextBox1.SelLength = 2
       Me.RichTextBox1.SelColor = vbYellow
       
       Counter = StringPos + 4
       
     Else
       
       Exit For
       
     End If
     
  Next Counter

End Sub

-------------------------------------------------------------------------



When the codes above run ( they are used to search "S3" and paint them "Yellow" ),


What should I do? I want all "S3" yellow and all the other text black..Thank you...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Assisted Solution

by:mukeshlaku
mukeshlaku earned 500 total points
ID: 20425655
Hi,

use following code as form_load event


Private Sub Form_Load()
Dim str1 As String
str1 = "{\rtf1\ansi\ansicpg1252\deff0\deflang1033\deflangfe1033{\fonttbl{\f0\froman\fprq2\fcharset0 Times New Roman;}}" & vbCrLf
str1 = str1 & "{\colortbl ;\red255\green255\blue255;\red255\green255\blue255;}" & vbCrLf
str1 = str1 & "\viewkind4\uc1\pard\cf1\f0\fs24 \cf2" & vbCrLf
str1 = str1 & "\par }"
RichTextBox1.TextRTF = str1
End Sub
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 20426693
your code works for me
0
 

Author Comment

by:hakanogu
ID: 20443204
I am sure It works but I couldnt change my forecolor..Anyway I gave up to change my forecolor I will use again white background and black text again..Thanks to everyone...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now