Results 1 to 21 of 21

Thread: Font/Combo Box Thing

  1. #1

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Font/Combo Box Thing

    using This Site: http://www.developerfusion.co.uk/show/1659/

    I Have Made A Combo Box On My Form, Combo 1 And A Module, Module1

    I Have added the code it says on this site and all the fonts are listed in the combo box, now how do i get the font in the combo box to change the font in the richtextbox i am using, called richtextbox1

  2. #2
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Font/Combo Box Thing

    something like
    VB Code:
    1. richtextbox1.selfont = combobox1.value

    should work

  3. #3

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Font/Combo Box Thing

    nope, didn't work

  4. #4
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Font/Combo Box Thing

    I just noticed there is

    richtextbox1.selfontname
    and
    richtextbox1.selfontsize

    those should work

  5. #5

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Font/Combo Box Thing

    i have this

    VB Code:
    1. Private Sub Combo2_Change()
    2. RichTextBox1.SelFontName = Combo2.Text
    3. End Sub

    and it still doesn't work

  6. #6
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Font/Combo Box Thing

    try combo2.value

    and what exactly is listed in the combobox? because the command selfontname would only work with something like "Times New Roman" or another font name in that general format

  7. #7

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Font/Combo Box Thing

    i tried .value

    and it isn't a propetry of the combobox

  8. #8
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Font/Combo Box Thing

    Quote Originally Posted by kfcSmitty
    and what exactly is listed in the combobox? because the command selfontname would only work with something like "Times New Roman" or another font name in that general format

    So whats lsited in ur combobox? can you take a screenshot?

  9. #9

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Font/Combo Box Thing

    just all the fonts installed on my PC, and if it was run on someone elses, it would have all of their fonts

  10. #10
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Font/Combo Box Thing

    so it displays them like
    "Wingdings"
    "Times New Roman"
    "Arial"
    ?

    because I just tried that and it works fine...

  11. #11

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Font/Combo Box Thing

    yeah, it says from A-Z in alphabetical order like this

    Arial
    Times New Roman

    etc. with no speech marks ""

  12. #12
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Font/Combo Box Thing

    you realise with .selfontname you have to have the text selected right?

    I have also noticed that with the combo1_change event, it takes focus away from the textbox, thus unhighlighting the text

  13. #13

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Font/Combo Box Thing

    yeah, i also noticed that,

  14. #14
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Font/Combo Box Thing

    VB Code:
    1. RichTextBox1.Font.Name = Combo1.Text

  15. #15

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Font/Combo Box Thing

    still don't work

  16. #16
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Font/Combo Box Thing

    the code itself works..you just need to find a way to keep the text selected while changing the combo box

    maybe store the selstart and sellength in a variable and right before you change the font, rehighlight the text?

  17. #17

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Font/Combo Box Thing

    how would i code this, i'm rather new to VB

  18. #18
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Font/Combo Box Thing

    Quote Originally Posted by lavarock09
    I Have Made A Combo Box On My Form, Combo 1 And A Module, Module1

    I Have added the code it says on this site and all the fonts are listed in the combo box, now how do i get the font in the combo box to change the font in the richtextbox i am using, called richtextbox1
    Attached is a one form project with a richtextbox and a combo box. If you run it, the font in the richtextbox will change to whatever font you select from the combo.

    This is what you are after, correct?

  19. #19
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: Font/Combo Box Thing

    VB Code:
    1. 'Declarations
    2. Dim SelectionStart As Integer
    3. Dim SelectionLength As Integer
    4.  
    5. Private Sub Combo2_Click()
    6. RichTextBox1.SetFocus
    7. DoEvents
    8. RichTextBox1.SelStart = SelectionStart
    9. RichTextBox1.SelLength = SelectionLength
    10. RichTextBox1.SelFontName = Combo1.Text
    11. End Sub
    12.  
    13. Private Sub RichTextBox1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
    14. SelectionStart = RichTextBox1.SelStart
    15. SelectionLength = RichTextBox1.SelLength
    16. End Sub

    this works for me

  20. #20

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Font/Combo Box Thing

    thanx, that does what i wanted, thanx

  21. #21

    Thread Starter
    Lively Member lavarock09's Avatar
    Join Date
    Jun 2005
    Posts
    124

    Re: Font/Combo Box Thing

    I Do have 2 Other Things i couldn't do,

    1. was to have a character count on,
    2. was to be able to right click my rtb and see the edit menu, cut, copy paste etc

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width