Trackbar control to change richtextbox font size?

Discussion in 'Programming General' started by hampe-92, Nov 5, 2008.

Trackbar control to change richtextbox font size?
  1. Unread #1 - Nov 5, 2008 at 5:24 PM
  2. hampe-92
    Joined:
    Jul 10, 2008
    Posts:
    328
    Referrals:
    0
    Sythe Gold:
    0

    hampe-92 Forum Addict

    Trackbar control to change richtextbox font size?

    Hi!
    How should one go about changing the font size of the text in a richtextbox by sliding the trackbar? (bigger font size to the right, smaler to the left)

    thx in advance :)
     
  3. Unread #2 - Nov 5, 2008 at 5:50 PM
  4. Flaming Idiots
    Joined:
    Dec 22, 2005
    Posts:
    235
    Referrals:
    1
    Sythe Gold:
    0
    Two Factor Authentication User

    Flaming Idiots Active Member
    Visual Basic Programmers

    Trackbar control to change richtextbox font size?

    This should work. Set the track bar's minimum value to 1 and maximum value to 72.

    Code:
    public Form1()
    {
        InitializeComponent();
    
        richTextBox1.SelectionChanged += new EventHandler(richTextBox1_SelectionChanged);
        trackBar1.ValueChanged += new EventHandler(trackBar1_ValueChanged);
    }
    
    bool sync = true;
    
    void trackBar1_ValueChanged(object sender, EventArgs e)
    {
        if (sync)
        {
            Font current = richTextBox1.SelectionFont;
            richTextBox1.SelectionFont =
                new Font(current.FontFamily, trackBar1.Value, current.Style, current.Unit, current.GdiCharSet, current.GdiVerticalFont);
        }
    }
    
    void richTextBox1_SelectionChanged(object sender, EventArgs e)
    {
        if (sync)
        {
            sync = false;
            this.trackBar1.Value = (int)Math.Floor(richTextBox1.SelectionFont.SizeInPoints);
            sync = true;
        }
    }
     
  5. Unread #3 - Nov 5, 2008 at 5:58 PM
  6. hampe-92
    Joined:
    Jul 10, 2008
    Posts:
    328
    Referrals:
    0
    Sythe Gold:
    0

    hampe-92 Forum Addict

    Trackbar control to change richtextbox font size?

    Ok thx :) I will take a closer look and try it tomorrow... gonna sleep now. thx

    Tyvm! It works great! :)

    EDIT:

    hmm... sometimes I get this error, even tho I don't even use the trackbar... just when I'm changeing like font or color or what ever... :/
    anyway.. this is the error i get:
    [​IMG]
     
< Quadratic Formular Solver (Non-GUI) | my findColor method >

Users viewing this thread
1 guest


 
 
Adblock breaks this site