473,406 Members | 2,707 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,406 software developers and data experts.

mixing font attributes

!NoItAll
297 100+
So - I have some text in an RTF control. I want the user to be able to highlight text and apply an attribute. The following code is placed into a button called BOLD and seems to work nicely:

Expand|Select|Wrap|Line Numbers
  1.      If rtfText.SelectedText.Length > 0 Then
  2.            rtfText.SelectionFont = New Font(rtfText.SelectionFont, FontStyle.Bold)
  3.      End If
  4.  
The code above will turn the selected text bold. Great!
But then the user selects the Same text and with the following code placed into a button called ITALIC it removes the bold attribute and replaces it with italics.

Expand|Select|Wrap|Line Numbers
  1.       If rtfText.SelectedText.Length > 0 Then
  2.           rtfText.SelectionFont = New Font(rtfText.SelectionFont, FontStyle.Italic)
  3.        End If
  4.  
Since the users actions are separate - I can not know that they want BOLD and ITALIC, so how do I make sure I keep the existing attribute on the selected text (which, by the way could be part bold and part not-bold) and add italic?

Somehow I need to add the italic attribute to the selected text, not simply replace all attributes with italic.
Apr 2 '09 #1
1 1215
!NoItAll
297 100+
Ok SOME progress, but not there yet....

Here's new code:

For Bold
Expand|Select|Wrap|Line Numbers
  1. If rtfText.SelectedText.Length > 0 Then
  2.            rtfText.SelectionFont = New Font(rtfText.SelectionFont, FontStyle.Bold Or rtfText.SelectionFont.Style)
  3. End If
  4.  
For Italic
Expand|Select|Wrap|Line Numbers
  1. If rtfText.SelectedText.Length > 0 Then
  2.            rtfText.SelectionFont = New Font(rtfText.SelectionFont, FontStyle.Italic Or rtfText.SelectionFont.Style)
  3. End If
  4.  

Notice that I added the OR, and apply the new font style to the current. This works well, but only when the second selection is of text with all the same attribute.
If I select a section of text and make it bold, then select a portion of the bold text along with a portion of the normal text then the above italic code will make everything just italic - removing the bold

Please don't tell me I have to go character by character - that would suck!
Granted - somebody has to, but I would prefer it be the lower level routine...
Apr 2 '09 #2

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

Similar topics

1
by: Matt Adams | last post by:
I want define for a couple of words inside a longer text with different font specifications. I declared it like: ....text before.... <FONT class=aaa> these text should get other attributes...
2
by: Haines Brown | last post by:
I don't understand the inheritance logic in this situation. Let me describe a simple situation: I have a document with a style sheet that specifies: address, blockquote, caption, center, dd,...
14
by: Viken Karaguesian | last post by:
Hello all, It stinks being a newbie! One thing that I'm not sure about with CSS is: where is the "proper" place to put font attibutes? This has me a little confused. Take the below style sheet...
1
by: Do | last post by:
Hi, In my listbox, I'd like to change the color of some listitems depending on user security. I tried wrapping the <font color=red></font> around my listitme's .text property, but the tags...
4
by: tshad | last post by:
I am having trouble with links in my DataGrid. I have Links all over my page set to smaller and they are consistant all over the page in both Mozilla and IE, except for the DataGrid. Here is a...
1
by: Roger Miller | last post by:
The following program gets a TextCtrl's text attributes and sets them back unchanged. However it reports that the font size is 124, and after resetting the attributes the text becomes that size....
1
by: Jukka K. Korpela | last post by:
This is pretty theoretical, but it might matter if you convert existing HTML documents to more modern style, getting rid of <fontmarkup. One might expect that just removing all attributes from a...
5
by: Arndt Jonasson | last post by:
I have a schema defining the input of a particular application. Let's refer to the namespace for my schema by the prefix "my:". Now the need has arisen to annotate such input documents with foreign...
4
by: mdarling | last post by:
I am using Lebans lady example to mix Bold and Normal in a single line text box, I have altered it and I still cant get it to bold the text I need bolded I have pasted it here, can somebody help? I...
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: 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...
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
Oralloy
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,...
0
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...
0
agi2029
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.