Bold Button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Prose
    New Member
    • Mar 2007
    • 20

    Bold Button

    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!
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Originally posted by Prose
    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?

    Comment

    • Prose
      New Member
      • Mar 2007
      • 20

      #3
      Originally posted by Killer42
      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?

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Originally posted by Prose
        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.

        Comment

        • Prose
          New Member
          • Mar 2007
          • 20

          #5
          Originally posted by Killer42
          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

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            Originally posted by Prose
            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.

            Comment

            • Prose
              New Member
              • Mar 2007
              • 20

              #7
              Originally posted by Killer42
              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..

              Comment

              • Killer42
                Recognized Expert Expert
                • Oct 2006
                • 8429

                #8
                Originally posted by Prose
                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.

                Comment

                • Prose
                  New Member
                  • Mar 2007
                  • 20

                  #9
                  Originally posted by Killer42
                  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..

                  Code:
                  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:
                  Code:
                  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.. ... :)

                  Comment

                  • Killer42
                    Recognized Expert Expert
                    • Oct 2006
                    • 8429

                    #10
                    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)...
                    Code:
                    RichTextBox1.Text = "The following word should be in bold."
                    RichTextBox1.SelStart = 4
                    RichTextBox1.SelLength = 9
                    RichTextBox1.SelBold = True
                    RichTextBox1.SelLength = 0
                    In theory, this should bold the word "following" .

                    Comment

                    • SammyB
                      Recognized Expert Contributor
                      • Mar 2007
                      • 807

                      #11
                      Fonts are more difficult in .Net, but much more versatile. What you want is
                      Code:
                      RichTextBox1.SelectionFont = New Font(RichTextBox1.Font, FontStyle.Bold)
                      HTH --Sam

                      Comment

                      • Prose
                        New Member
                        • Mar 2007
                        • 20

                        #12
                        Originally posted by SammyB
                        Fonts are more difficult in .Net, but much more versatile. What you want is
                        Code:
                        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...

                        Comment

                        • Killer42
                          Recognized Expert Expert
                          • Oct 2006
                          • 8429

                          #13
                          Originally posted by Prose
                          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...
                          Code:
                          RichTextBox1.SelectionFont.Bold = True
                          Have a look at these links...

                          Comment

                          • SammyB
                            Recognized Expert Contributor
                            • Mar 2007
                            • 807

                            #14
                            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,
                            Code:
                            RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont, FontStyle.Bold + FontStyle.Italic)

                            Comment

                            • Prose
                              New Member
                              • Mar 2007
                              • 20

                              #15
                              Okay, umm here is the code i have
                              BoldButton:
                              Code:
                                      If RichTextBox1.SelectionFont.Style <> FontStyle.Bold Then
                                          RichTextBox1.SelectionFont = New Font(RichTextBox1.Font, FontStyle.Bold)
                                      Else
                                          RichTextBox1.SelectionFont = New Font(RichTextBox1.Font, FontStyle.Regular)
                                      End If
                              Italic Button:
                              Code:
                                      If RichTextBox1.SelectionFont.Style <> FontStyle.Italic Then
                                          RichTextBox1.SelectionFont = New Font(RichTextBox1.Font, FontStyle.Italic)
                                      Else
                                          RichTextBox1.SelectionFont = New Font(RichTextBox1.Font, FontStyle.Regular)
                                      End If
                              Underline Button:
                              Code:
                                      If RichTextBox1.SelectionFont.Style <> FontStyle.Underline Then
                                          RichTextBox1.SelectionFont = New Font(RichTextBox1.Font, FontStyle.Underline)
                                      Else
                                          RichTextBox1.SelectionFont = New Font(RichTextBox1.Font, FontStyle.Regular)
                                      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?

                              Comment

                              Working...