473,414 Members | 1,775 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,414 software developers and data experts.

Bold Button

20
Hi,
i want to make a button on a toolstrip that is like the bold Button in Microsoft Word, ive tried a few things but i think im way off.. and im farely new to VB soo could sum1 please explain how to do this and show me the script!

Thanks

Prose!
Mar 8 '07 #1
31 5174
Killer42
8,435 Expert 8TB
Hi,
i want to make a button on a toolstrip that is like the bold Button in Microsoft Word, ive tried a few things but i think im way off.. and im farely new to VB soo could sum1 please explain how to do this and show me the script!
What part of it is giving you trouble? We don't know exactly what the button is supposed to do, or to what.

What version of VB are you using?

Can you show us what you've done so far?
Mar 8 '07 #2
Prose
20
What part of it is giving you trouble? We don't know exactly what the button is supposed to do, or to what.

What version of VB are you using?

Can you show us what you've done so far?

Well Basically ive done nothing.. i keep writing stuff and running program and it doesnt work.. soo i try again and im using Visual Basic 2005 Express Edition,.. and i want a button to bold selected text when clicked.. and wen clicked again it will unbold the selected text.. is that enough information for u to help me?
Mar 8 '07 #3
Killer42
8,435 Expert 8TB
Well Basically ive done nothing.. i keep writing stuff and running program and it doesnt work.. soo i try again and im using Visual Basic 2005 Express Edition,.. and i want a button to bold selected text when clicked.. and wen clicked again it will unbold the selected text.. is that enough information for u to help me?
Not me, because I don't know VB2005 - only VB6.

However, what is the text in? If it's in a textbox for example, I think you can only turn bold on or off for the entire control, not part of the text. The RichTextBox control is a different story, of course.

You could also try asking in the .Net forum and see whether you get a better response.
Mar 8 '07 #4
Prose
20
Not me, because I don't know VB2005 - only VB6.

However, what is the text in? If it's in a textbox for example, I think you can only turn bold on or off for the entire control, not part of the text. The RichTextBox control is a different story, of course.

You could also try asking in the .Net forum and see whether you get a better response.

thanks and it's in a RichTextBox
Mar 8 '07 #5
Killer42
8,435 Expert 8TB
thanks and it's in a RichTextBox
Well, if you have selected some of the text in the RTB then hit your button, I think you need to set (or clear) the .SelBold property (of the RTB). I haven't played with this for a while, though.
Mar 8 '07 #6
Prose
20
Well, if you have selected some of the text in the RTB then hit your button, I think you need to set (or clear) the .SelBold property (of the RTB). I haven't played with this for a while, though.
uhh.. i dont really understand wat u mean by the .selbold property of the RTB.. atm i just have a button with no code in it.. cause i got frusted and deleted all the previous code for the button.. lol..
Mar 8 '07 #7
Killer42
8,435 Expert 8TB
uhh.. i dont really understand wat u mean by the .selbold property of the RTB.. atm i just have a button with no code in it.. cause i got frusted and deleted all the previous code for the button.. lol..
RTB was just a shorthand way of referring to the RichTextBox control. If you look through the properties of the control, you should find a bunch that start with "Sel" (Eg. SelBold, SelColor). These relate to the part of the contents which is currently selected (if any). Thus, you may select part of the text in your RTB then change the SelBold property to switch it between bold and normal. Likewise you can change the SelColor property to adjust the colour of the text.

From the sound of it, you should try searching for tutorials (there's a Google search box at the top-right). We're really here to help people out with specific problems in their code, not so much to teach people to program.
Mar 8 '07 #8
Prose
20
RTB was just a shorthand way of referring to the RichTextBox control. If you look through the properties of the control, you should find a bunch that start with "Sel" (Eg. SelBold, SelColor). These relate to the part of the contents which is currently selected (if any). Thus, you may select part of the text in your RTB then change the SelBold property to switch it between bold and normal. Likewise you can change the SelColor property to adjust the colour of the text.

From the sound of it, you should try searching for tutorials (there's a Google search box at the top-right). We're really here to help people out with specific problems in their code, not so much to teach people to program.
yes well .. i know the basics and stuff and there is no selbold etc.. in the property of the RTB.. thats why i asked wat u where talking about.. i looked through the property's b4 and there wasnt anything and i just looked through again...and still cant see anything.. anyway.. im gonnah fully explain wat i wanna do again cause i was kindah fuzzy to begin with...

Im making a Text Editor.. Like NotePad and Microsoft Word combined... i already have my Open butons and save buttons.. cut paste copy etc.. coded.. but i would like to make bold, ittalic and underline buttons.. like the ones in microsoft word.. ive looked all over the internet.. (using google).. and im really frustrated now cause i couldnt find anything.. originally i thought i could just write..

Expand|Select|Wrap|Line Numbers
  1. RichTextBox1.SelectedText = FontStyle.Bold
(very basic way of writing wat i thought, but this was the basic princibal i was thinking of)

Buuut.. that's not the case.. lol.... do you think it's possible to set sumthing in RTB code.. such as:
Expand|Select|Wrap|Line Numbers
  1. Selected text + bold button = FontStyle.Bold
?(again a very basic way of writing wat i thought, but this was the basic princibal im thinking of)

i havent tried that yet.. but im looking for a simple way to do it.. and im really tired at the moment.. sooo sorry if none of this makes much sense.. ... :)
Mar 8 '07 #9
Killer42
8,435 Expert 8TB
Hm... VB2005 must be more different than I thought. In VB6, the RichTextBox has the properties that I mentioned. I don't get it.

Ah! Got it.

I'll bet you're looking in the list of properties which can be set at design time, in the GUI. The .Selxxx properties aren't listed there, because they don't apply at that point.

In VB6, there is an option to have the properties and methods automatically listed as soon as you type the object name in your code, then a dot. Alternatively, you can enter the object name then select "List Properties/Methods" from the Edit menu. VB2005 must have something analogous, so you can see the available properties while writing your code.

Try pasting this code somewhere (for example, the form click event procedure) and executing it, to see what happens (that is, if it compiles)...
Expand|Select|Wrap|Line Numbers
  1. RichTextBox1.Text = "The following word should be in bold."
  2. RichTextBox1.SelStart = 4
  3. RichTextBox1.SelLength = 9
  4. RichTextBox1.SelBold = True
  5. RichTextBox1.SelLength = 0
In theory, this should bold the word "following".
Mar 8 '07 #10
SammyB
807 Expert 512MB
Fonts are more difficult in .Net, but much more versatile. What you want is
Expand|Select|Wrap|Line Numbers
  1. RichTextBox1.SelectionFont = New Font(RichTextBox1.Font, FontStyle.Bold)
HTH --Sam
Mar 8 '07 #11
Prose
20
Fonts are more difficult in .Net, but much more versatile. What you want is
Expand|Select|Wrap|Line Numbers
  1. RichTextBox1.SelectionFont = New Font(RichTextBox1.Font, FontStyle.Bold)
HTH --Sam
okay thanks i managed to figure that out.. but now.. wen i make my italic and underline buttons, i cant make the selected font bold and italic...
Mar 9 '07 #12
Killer42
8,435 Expert 8TB
okay thanks i managed to figure that out.. but now.. wen i make my italic and underline buttons, i cant make the selected font bold and italic...
I just had a look at MSDN, and I think you can just set the .Bold, .Italic and .Underline properties (among others) of the SelectionFont. In other words...
Expand|Select|Wrap|Line Numbers
  1. RichTextBox1.SelectionFont.Bold = True
Have a look at these links...
Mar 9 '07 #13
SammyB
807 Expert 512MB
No, the Bold property, etc are all readonly. From help: "Because the Font object is immutable (meaning that you cannot adjust any of it's properties), you can only assign the Font property a new Font object. However, you can base the new font on the existing font."

In other words, you always have to create a new Font object. You just look at which buttons are up and which are down, and then you add the FontStyles together. You also want to use the SelectionFont as the prototype font. For example,
Expand|Select|Wrap|Line Numbers
  1. RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, FontStyle.Bold + FontStyle.Italic)
Mar 9 '07 #14
Prose
20
Okay, umm here is the code i have
BoldButton:
Expand|Select|Wrap|Line Numbers
  1.         If RichTextBox1.SelectionFont.Style <> FontStyle.Bold Then
  2.             RichTextBox1.SelectionFont = New Font(RichTextBox1.Font, FontStyle.Bold)
  3.         Else
  4.             RichTextBox1.SelectionFont = New Font(RichTextBox1.Font, FontStyle.Regular)
  5.         End If
Italic Button:
Expand|Select|Wrap|Line Numbers
  1.         If RichTextBox1.SelectionFont.Style <> FontStyle.Italic Then
  2.             RichTextBox1.SelectionFont = New Font(RichTextBox1.Font, FontStyle.Italic)
  3.         Else
  4.             RichTextBox1.SelectionFont = New Font(RichTextBox1.Font, FontStyle.Regular)
  5.         End If
Underline Button:
Expand|Select|Wrap|Line Numbers
  1.         If RichTextBox1.SelectionFont.Style <> FontStyle.Underline Then
  2.             RichTextBox1.SelectionFont = New Font(RichTextBox1.Font, FontStyle.Underline)
  3.         Else
  4.             RichTextBox1.SelectionFont = New Font(RichTextBox1.Font, FontStyle.Regular)
  5.         End If
And each button Can either be Checked Or unChecked but wen i want to check the bold button and lets say the underline button for the same text if it is bold first naturally, wen i click the underline button it becomes unbolded but underlined.. Does anyone know how to check two of the buttons at once and have both effects applied to the same selected text?..

im thinking ill need an "If statement" involving all 3 buttons.. but i havent tried that yet And im not sure if it will be possible to do it that way... Can anyone Help me?
Mar 9 '07 #15
Killer42
8,435 Expert 8TB
No, the Bold property, etc are all readonly. From help: "Because the Font object is immutable (meaning that you cannot adjust any of it's properties), you can only assign the Font property a new Font object. However, you can base the new font on the existing font."
????? That's crazy! :O
What were M$ smoking when they came up with that one?

Does that apply to the Font object in general, or a particular one (such as the one provided by SelectionFont)?
Mar 9 '07 #16
Prose
20
????? That's crazy! :O
What were M$ smoking when they came up with that one?

Does that apply to the Font object in general, or a particular one (such as the one provided by SelectionFont)?
i think it's the font object in general.. could be wrong but im pretty sure it apply's to the font object in general
Mar 9 '07 #17
Prose
20
Okay, umm here is the code i have
BoldButton:
Expand|Select|Wrap|Line Numbers
  1.         If RichTextBox1.SelectionFont.Style <> FontStyle.Bold Then
  2.             RichTextBox1.SelectionFont = New Font(RichTextBox1.Font, FontStyle.Bold)
  3.         Else
  4.             RichTextBox1.SelectionFont = New Font(RichTextBox1.Font, FontStyle.Regular)
  5.         End If
Italic Button:
Expand|Select|Wrap|Line Numbers
  1.         If RichTextBox1.SelectionFont.Style <> FontStyle.Italic Then
  2.             RichTextBox1.SelectionFont = New Font(RichTextBox1.Font, FontStyle.Italic)
  3.         Else
  4.             RichTextBox1.SelectionFont = New Font(RichTextBox1.Font, FontStyle.Regular)
  5.         End If
Underline Button:
Expand|Select|Wrap|Line Numbers
  1.         If RichTextBox1.SelectionFont.Style <> FontStyle.Underline Then
  2.             RichTextBox1.SelectionFont = New Font(RichTextBox1.Font, FontStyle.Underline)
  3.         Else
  4.             RichTextBox1.SelectionFont = New Font(RichTextBox1.Font, FontStyle.Regular)
  5.         End If
And each button Can either be Checked Or unChecked but wen i want to check the bold button and lets say the underline button for the same text if it is bold first naturally, wen i click the underline button it becomes unbolded but underlined.. Does anyone know how to check two of the buttons at once and have both effects applied to the same selected text?..

im thinking ill need an "If statement" involving all 3 buttons.. but i havent tried that yet And im not sure if it will be possible to do it that way... Can anyone Help me?


So No1 Has Any Ideas then?..
Mar 9 '07 #18
SammyB
807 Expert 512MB
????? That's crazy! :O
What were M$ smoking when they came up with that one?
I doubt that they allow smoking ;o), but that's sort of what I thought: it doesn't seem to match the rest of DotNet's framework, but since you can base the new font on the existing font and do in one line, its not so bad, but it takes a while to figure out the first time. --Sam
Mar 9 '07 #19
SammyB
807 Expert 512MB
So No1 Has Any Ideas then?..
Look back at my last posting of code. Notice that I use SelectionFont as the base for the new font. You are using the control's default font. Don't forget to check the case when the selected text has more than one font style. It will be hard to model MS toggle buttons, but fun (for you)! -- Sam
Mar 9 '07 #20
Prose
20
umm i changed them too selectionFont .. but still it wont work.. this is proving to be harder then i thought.. lol here is the code i have now..

Expand|Select|Wrap|Line Numbers
  1.     Private Sub tlbItalic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tlbItalic.Click
  2.  
  3.         If RichTextBox1.SelectionFont.Style <> FontStyle.Italic Then
  4.             RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, FontStyle.Italic)
  5.         Else
  6.             RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, FontStyle.Regular)
  7.         End If
  8.  
  9.     End Sub
  10.  
  11.     Private Sub tlbUnderline_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tlbUnderline.Click
  12.  
  13.         If RichTextBox1.SelectionFont.Style <> FontStyle.Underline Then
  14.             RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, FontStyle.Underline)
  15.         Else
  16.             RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, FontStyle.Regular)
  17.         End If
  18.  
  19.     End Sub
  20.  
  21.     Private Sub tlbStrikeout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tlbStrikeout.Click
  22.  
  23.         If RichTextBox1.SelectionFont.Style <> FontStyle.Strikeout Then
  24.             RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, FontStyle.Strikeout)
  25.         Else
  26.             RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, FontStyle.Regular)
  27.         End If
  28.  
  29.     End Sub
but it still wont let me apply 2 styles to the one selection.. :(.. any other ideas :|
Mar 10 '07 #21
Prose
20
umm i changed them too selectionFont .. but still it wont work.. this is proving to be harder then i thought.. lol here is the code i have now..

Expand|Select|Wrap|Line Numbers
  1.     Private Sub tlbItalic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tlbItalic.Click
  2.  
  3.         If RichTextBox1.SelectionFont.Style <> FontStyle.Italic Then
  4.             RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, FontStyle.Italic)
  5.         Else
  6.             RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, FontStyle.Regular)
  7.         End If
  8.  
  9.     End Sub
  10.  
  11.     Private Sub tlbUnderline_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tlbUnderline.Click
  12.  
  13.         If RichTextBox1.SelectionFont.Style <> FontStyle.Underline Then
  14.             RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, FontStyle.Underline)
  15.         Else
  16.             RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, FontStyle.Regular)
  17.         End If
  18.  
  19.     End Sub
  20.  
  21.     Private Sub tlbStrikeout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tlbStrikeout.Click
  22.  
  23.         If RichTextBox1.SelectionFont.Style <> FontStyle.Strikeout Then
  24.             RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, FontStyle.Strikeout)
  25.         Else
  26.             RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, FontStyle.Regular)
  27.         End If
  28.  
  29.     End Sub
but it still wont let me apply 2 styles to the one selection.. :(.. any other ideas :|
i guess no1 knows then?... ahh well.. ill probably figure it out eventually....... i hope..... lol :)
Mar 11 '07 #22
Killer42
8,435 Expert 8TB
i guess no1 knows then?... ahh well.. ill probably figure it out eventually....... i hope..... lol :)
I don't know the answer, but don't be too impatient.

Remember that TSDN is peopled by volunteers, in various timezones all over the world, who put in their own time when they can spare it. It can sometimes take a while.

In the meantime, I'd suggest you try searching TSDN and the web as a whole for tutorials covering VB.Net, the use of fonts and the RichTextBox control. If you find anything good, post a link here and we won't have so much trouble next time someone needs this stuff.
Mar 11 '07 #23
Prose
20
I don't know the answer, but don't be too impatient.

Remember that TSDN is peopled by volunteers, in various timezones all over the world, who put in their own time when they can spare it. It can sometimes take a while.

In the meantime, I'd suggest you try searching TSDN and the web as a whole for tutorials covering VB.Net, the use of fonts and the RichTextBox control. If you find anything good, post a link here and we won't have so much trouble next time someone needs this stuff.
i alrdy searched for alot of stuff.. but ill keep looking.. im thinkin it may involve script in the RTB aswell as script for the buttons aswell.. im not rly sure.. but it is alot harder then what i thought it would be.. :).. anywayz thanks for all ur suggestions.. i guess ill check back later if i figure sumffin out.. :)

Thanks again,

Prose.
Mar 12 '07 #24
SammyB
807 Expert 512MB
i alrdy searched for alot of stuff..
Well, I guess we both should have read the help. The Font object is even stranger than I had thought. The constructor that we are using, Font(prototype,style) does not use the prototype to initialize the style, so you need:
RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, RichTextBox1.SelectionFont.Style Or FontStyle.Bold)
to bold the selection. But, at least the event code is now a single line.
Mar 12 '07 #25
Killer42
8,435 Expert 8TB
i alrdy searched for alot of stuff.. but ill keep looking.. im thinkin it may involve script in the RTB aswell as script for the buttons aswell.. im not rly sure.. but it is alot harder then what i thought it would be.. :).. anywayz thanks for all ur suggestions.. i guess ill check back later if i figure sumffin out.. :)
Keep in mind that the VB.Net font stuff is way over my head. But I just had an idea.

What if you just did the attributes in three steps. I mean, let's say you have a chunk of text selected in the RTB. You want to set it to both bold and italic. Can't you just set it bold, then set it italic, using the techniques already discussed here? Since the "old font" used as the basis of each would be the SelectionFont, one would imagine that setting one attribute shoudn't affect the others.

Or am I talking nonsense?
Mar 12 '07 #26
SammyB
807 Expert 512MB
<snip> What if you just did the attributes in three steps. <snip>
Or am I talking nonsense?
No, I think that that is the best way to go: just use the ToolBar ItemClick event and cascade thru each of the buttons, but you will also need a SelectionChange event to keep the buttons in sync with the text. I started that way (after downloading VB Express), but got bogged down like Prose & only could get a single style, so I went back to the Button click event.

Now, I think I could go back to a single ItemClick event, but I couldn't get the Selection_Change event to work either, so I'm just going to bed. ;o)>>> Sam
Mar 12 '07 #27
Prose
20
Well, I guess we both should have read the help. The Font object is even stranger than I had thought. The constructor that we are using, Font(prototype,style) does not use the prototype to initialize the style, so you need:
RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, RichTextBox1.SelectionFont.Style Or FontStyle.Bold)
to bold the selection. But, at least the event code is now a single line.
Okay thanks for that SammyB ive got it all working now.. and with only 1 line of code for each button.. but like u said in ur last post im going to have to mess around with sum other stuff.. eg SelectionChange.. to make it like the MS word buttons :).. thanks for all you help everyone :) im very very grateful!!

Prose

P.S if this question ever comes up again.. just give them the link of this forum.. here is the code!
Expand|Select|Wrap|Line Numbers
  1.     Private Sub tlbBold_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tlbBold.Click
  2.  
  3.         RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, RichTextBox1.SelectionFont.Style Or FontStyle.Bold)
  4.  
  5.     End Sub
  6.  
  7.     Private Sub tlbItalic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tlbItalic.Click
  8.  
  9.         RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, RichTextBox1.SelectionFont.Style Or FontStyle.Italic)
  10.  
  11.     End Sub
  12.  
  13.     Private Sub tlbUnderline_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tlbUnderline.Click
  14.  
  15.         RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, RichTextBox1.SelectionFont.Style Or FontStyle.Underline)
  16.  
  17.     End Sub
  18.  
  19.     Private Sub tlbStrikeout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tlbStrikeout.Click
  20.  
  21.         RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, RichTextBox1.SelectionFont.Style Or FontStyle.Strikeout)
  22.  
  23.     End Sub
that is for.. bold, italic, underline and strikeout! but remember it still may not be exactly what you want.. but that allows more the one fontstyle to be applied to the same text!!

Thanks Again,

Prose.
Mar 12 '07 #28
Killer42
8,435 Expert 8TB
Thanks for that, Prose. It will be very useful to have here for future searchers to find.

One question - does this work alright (that is, not crash) if the user has not selected any text before clicking?
Mar 12 '07 #29
SammyB
807 Expert 512MB
One question - does this work alright (that is, not crash) if the user has not selected any text before clicking?
If nothing is selected then it looks like SelectionFont is the control's default font. In any case it is not null, so it does not crash. --Sam
Mar 13 '07 #30
Killer42
8,435 Expert 8TB
If nothing is selected then it looks like SelectionFont is the control's default font. In any case it is not null, so it does not crash. --Sam
Excellent. Just wanted to ensure you hadn't built in a nasty bug. I would have tried it myself, but I only have VB6 here.

Well, sounds as though your project is well on its way. Have fun!
Mar 13 '07 #31
I also have been having a lot of problems with the bold italic and underline buttons however using the tips here as a basis i was able to make them function very closely to how they function in MS Word and other such programs. The key is you need 3 global boolean flags to get all 3 to work together properly.

Expand|Select|Wrap|Line Numbers
  1.  Dim fontbold As Boolean = False
  2.     Dim fontitalic As Boolean = False
  3.     Dim fontunderline As Boolean = False
I then Used a sub procedure to do all the text formatting
Expand|Select|Wrap|Line Numbers
  1.     Private Sub textproperty()
  2.         'REGULAR
  3.         If fontbold = False And fontitalic = False And fontunderline = False Then
  4.             rtbTextArea.SelectionFont = New Font(rtbTextArea.SelectionFont, FontStyle.Regular)
  5.             'BOLD
  6.         ElseIf fontbold = True And fontitalic = False And fontunderline = False Then
  7.             rtbTextArea.SelectionFont = New Font(rtbTextArea.SelectionFont, FontStyle.Bold)
  8.             'ITALIC
  9.         ElseIf fontbold = False And fontitalic = True And fontunderline = False Then
  10.             rtbTextArea.SelectionFont = New Font(rtbTextArea.SelectionFont, FontStyle.Italic)
  11.             'UNDERLINE
  12.         ElseIf fontbold = False And fontitalic = False And fontunderline = True Then
  13.             rtbTextArea.SelectionFont = New Font(rtbTextArea.SelectionFont, FontStyle.Underline)
  14.             'BOLD ITALIC
  15.         ElseIf fontbold = True And fontitalic = True And fontunderline = False Then
  16.             rtbTextArea.SelectionFont = New Font(rtbTextArea.SelectionFont, FontStyle.Bold Or FontStyle.Italic)
  17.             'BOLD UNDERLINE
  18.         ElseIf fontbold = True And fontitalic = False And fontunderline = True Then
  19.             rtbTextArea.SelectionFont = New Font(rtbTextArea.SelectionFont, FontStyle.Bold Or FontStyle.Underline)
  20.             'BOLD ITALIC UNDERLINE
  21.         ElseIf fontbold = True And fontitalic = True And fontunderline = True Then
  22.             rtbTextArea.SelectionFont = New Font(rtbTextArea.SelectionFont, FontStyle.Bold Or FontStyle.Italic Or FontStyle.Underline)
  23.             'ITALIC UNDERLINE
  24.         ElseIf fontbold = False And fontitalic = True And fontunderline = True Then
  25.             rtbTextArea.SelectionFont = New Font(rtbTextArea.SelectionFont, FontStyle.Italic Or FontStyle.Underline)
  26.         End If
  27.     End Sub
Then all you need in the buttons is to reference the sub procedure and change the boolean flag when appropriate
Expand|Select|Wrap|Line Numbers
  1.  Private Sub tsbBold_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbBold.Click
  2.         If fontbold = True Then
  3.             fontbold = False
  4.         Else
  5.             fontbold = True
  6.         End If
  7.         textproperty()
  8.         If fontbold = True Then
  9.             tsbBold.CheckState = CheckState.Checked
  10.         Else
  11.             tsbBold.CheckState = CheckState.Unchecked
  12.         End If
  13.     End Sub
  14.     Private Sub tsbItalic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbItalic.Click
  15.  
  16.         If fontitalic = True Then
  17.             fontitalic = False
  18.         Else
  19.             fontitalic = True
  20.         End If
  21.         textproperty()
  22.         If fontbold = True Then
  23.             tsbItalic.CheckState = CheckState.Checked
  24.         Else
  25.             tsbItalic.CheckState = CheckState.Unchecked
  26.         End If
  27.  
  28.     End Sub
  29.     Private Sub tsbUnderline_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsbUnderline.Click
  30.  
  31.         If fontunderline = True Then
  32.             fontunderline = False
  33.         Else
  34.             fontunderline = True
  35.         End If
  36.         textproperty()
  37.         If fontbold = True Then
  38.             tsbUnderline.CheckState = CheckState.Checked
  39.         Else
  40.             tsbUnderline.CheckState = CheckState.Unchecked
  41.         End If
  42.     End Sub 
Mar 24 '07 #32

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

Similar topics

2
by: Imaya Kumar | last post by:
Hi, i'm developing an editor in VS.NET using Rich Text Box Control. I need to make a selected text Bold. how can i do this? also i will have an Italic Button too. If i click Bold button the...
6
by: Ronny sigo | last post by:
Hello all, I have made a form with a lot of entryfields and one button which, when clicked on, transforms all of the entryfields values into a MS Word document. All the formatting is done...
4
by: anthony | last post by:
hi, why can't i set the font of a button to bold at run time (it's read only), i can only set at design time. it can be done in vb6. thx
5
by: Stefan Mueller | last post by:
In HTML I use <b>...</b> to make parts of a text bold. <h1 class = "Style-MyText">This text is normal. <b>This text is bold.</b></h1> Now I'd like to do the same with a JavaScript. I tried...
5
by: James_Ptg | last post by:
Hello peole, i'm begin with VB.NET (before i was under ASP and VB) i have a -CheckBox- turned into a button with him properties Appearance. so i whant that the text become in Bold so i have...
1
by: Henry Jones | last post by:
I found some code to change the font on a button to bold: private void btnBold_Click(object sender, System.EventArgs e) { btnCalculate.Font = new Font(btnCalculate.Font, ...
2
by: Prose | last post by:
Okay i already made a discussion about this but this time.. i thought id be more acurate soo: Im Using VB 2005 Express Edition Im Making a Text Editor kinda like MS Word and Notepad Combined, So...
3
by: jonniethecodeprince | last post by:
Hello everyone. I want to change the style of a HTML element. I can change the paragraph alignment to left right, justify etc. But I can seem to find the code for any other style change, for...
5
by: sunadumari | last post by:
Hi folks, hope I'm in the wright section (I'm a newbie). I've got a textarea that, with the click on a button, shows the html-look of the data in the textarea. This script I found on the net (with...
1
jamesd0142
by: jamesd0142 | last post by:
Hi, im using a rich text box called "main", a button called "bold". when my program is running i want to be able to type in the rich text box, then when i highlight some text and press the bold...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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
tracyyun
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.