473,385 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Rich Text Box

gsgurdeep
I am using rich text box control in my vb.net windows application to format some user define text formatting.

I placed 3 buttons for bold, italic, & underline to change text formatting.

These buttons perform very well separately. But when want to use more than one option at same text, latest formatting option overwrites previous formatting.

Give Me Any Suggestion Please Help Me.
Dec 23 '08 #1
4 1966
truezplaya
115 100+
Could you use a global bool value to show if the button is clicked, Then do some checks so
after you have defined these you would set these true and false in the button click events
dim b1 as bool = false // bold
dim b2 as bool = false etc etc /italics


private sub checkButtonsClicked
if b1 = true and b2 = true then
//your text or text box properties italics bold set to true
end sub

you would have to cover all the combinations but that the quickest idea that came to me. Sorry i'm not amazing at programming
Dec 23 '08 #2
truezplaya
115 100+
very simple way
set some global bool variables
on buttonclick set these to either false or true
do some checks so if b1 = true and b2 = true then set properties for bold and italics
as i said very simple but possibly not the best way
Dec 23 '08 #3
phvfl
173 Expert 100+
A flexible way of this is to use the FontStyle as a flag i.e. if the font should be bold and underlined the style is FontStyle.Bold And FontStyle.Underline.

A very thrown together implementation would be:

Expand|Select|Wrap|Line Numbers
  1. Private Sub AddStyle(ByVal style As FontStyle)
  2.     Dim newStyle As FontStyle = testRich.SelectionFont.Style Or style
  3.     Dim ifont As New Font(testRich.Font, newStyle)
  4.     testRich.SelectionFont = ifont
  5.   End Sub
  6.  
  7.   Private Sub RemoveStyle(ByVal style As FontStyle)
  8.     Dim newStyle As FontStyle = testRich.SelectionFont.Style Xor style
  9.     Dim ifont As New Font(testRich.Font, newStyle)
  10.     testRich.SelectionFont = ifont
  11.   End Sub
  12.  
  13.   Private Function HasStyle(ByVal style As FontStyle) As Boolean
  14.     Return (testRich.SelectionFont.Style And style) = style
  15.   End Function
This assumes that the RichTextBox control is called testRich. Calling these procedures is done by:
Expand|Select|Wrap|Line Numbers
  1. ' HasStyle(FontStyle.Bold) = False
  2. AddStyle(FontStyle.Bold)
  3.  
  4. ' HasStyle(FontStyle.Bold) = True
  5. RemoveStyle(FontStyle.Bold)
  6.  
  7. ' HasStyle(FontStyle.Bold) = False
The And, Or & XOr (Exclusive Or) are all bitwise operator. A brief tutorial can be seen here.

Using this method means that you can use any of the FontStyle values.
Dec 24 '08 #4
Thanks for your interest.
But these answers are not helping me.

but finally i have found the solution of my problem.
I used following code for bold event

rich_text.SelectionFont = New Font(rich_text.SelectionFont, IIf(rich_text.SelectionFont.Underline, rich_text.SelectionFont.Style - System.Drawing.FontStyle.Underline, Me.at5_description.SelectionFont.Style + System.Drawing.FontStyle.Underline))

Underline & italic events are same as this code
Jan 7 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Alfredo Agosti | last post by:
Hi folks, I have an Access 2000 db with a memo field. Into the memo field I put text with bold attributes, URL etc etc What I need to to is converting the rich text contained into the memo...
1
by: PC User | last post by:
I found this Rich Text Editor and I've been trying to recreate it in my own application. I've had trouble with the COMCTL.ImageListCtrl and the COMCTL.Toolbar to recreate the toolbar. And I've...
1
by: Peter | last post by:
I have written a small terminal app that reads and writes to the serial port. In particular as the data is read from the serial port it is appended to the rich text box. The problem I am...
4
by: David Davis | last post by:
Woll2Woll has a product for Delphi called Infopower which has a rtf control with a built-in word processor. Does anyone know of a third party control that has the same capabilities. I don't have...
0
by: ray well | last post by:
hi, my app has two parallel rich text boxes containing the same content in 2 different languages. the lines parallel each other, line #3 in english contains the same content as line #3 in...
1
by: tomi.trescak | last post by:
Hi I have a problem with storing rich text in MySQL. I store rich text in MySQL (in column with type "text") which i get from Rich Textbox control. When i do reverse processing by trying to...
9
by: Neil | last post by:
I need to implement a rich text box in an MDB file for a user base that consists of Access 2000 and Access 2002. Unfortunately, I'm using Access 2003 on my development machine. My understanding is...
5
by: ARC | last post by:
Just found out something interesting with Access 2007... In table design, if you set a memo field to the new rich text option, and put that control on a form, set the control to rich text, you can...
4
by: Neil | last post by:
Just found out that the Microsoft Rich Textbox does not support full text justification, since it's based on Version 1.0 of the RichEdit Window Class, and full text justification is only available...
16
by: Neil | last post by:
I posted a few days ago that it seems to me that the Access 2007 rich text feature does not support: a) full text justification; b) programmatic manipulation. I was hoping that someone might...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.