Hi Everyone,
I have no idea about How to check Richtextbox vertical scroll bar is ON.
Means suppose Richtextbox has 3 lines displayed perfectly but when 4 line is inserted vertical scroll bar is on Now i want to check at runtime the vertical scroll bar is available now...
Can anyone help me please..

Thanks in advance

Edited 5 Years Ago by bhagawatshinde: n/a

You can trap the "ClientSizeChanged" event on the RichTextBox. In both cases (when the scrollbar appears and disappears), this event will fire.

Comments
My example came from your statement so you deserve credit

If you're just checking to see if the vertical scroll bar is enabled then you can tell the textbox to write multiple lines of text. Like:

void appLaunch()
{
richTextBox1.Text = "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + "";
}

void timer3000ms()
{
richTextBox1.Text = "";
}

That will force around 15 lines of blank text into the text box, then with the timer, 3 seconds later it will erase the entire text box. Hope it helps. Wasn't too sure on what you're asking.

If you're just checking to see if the vertical scroll bar is enabled then you can tell the textbox to write multiple lines of text. Like:

void appLaunch()
{
richTextBox1.Text = "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + "" + Environment.NewLine + "";
}

void timer3000ms()
{
richTextBox1.Text = "";
}

That will force around 15 lines of blank text into the text box, then with the timer, 3 seconds later it will erase the entire text box. Hope it helps. Wasn't too sure on what you're asking.

What is this example all about?

Edited 5 Years Ago by Mitja Bonca: n/a

If there is a vertical scroll bar in the text box it will appear at start when the application starts, due to the multi-line write. However, I believe richTextBox automatically has both set up automatically. I'm still not understanding what else he/she is looking for out of this though.

Check this out:

public Form1()
        {
            InitializeComponent();
            richTextBox1.TextChanged += new EventHandler(richTextBox1_TextChanged);
        }

        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {
            if (richTextBox1.Lines.Length == 4)
                DoCode(true);
        }

        private void DoCode(bool bVisible)
        {
            if (bVisible)
            {
                //Do code in here
                MessageBox.Show("Verical scrollBar is now visible.");
            }
        }

its a simple one, but this is what you stated in the 1st post.
Mitja

Hi, Mitja
your suggetion is simple one but when richtextbox contains image or math type equation then richtextbox display only single line then how to figure out this question. at this point line count doesn't work

namespace WindowsFormsApplication1 {
    public partial class Form1 : Form {
        private Boolean hasScroll = false;
        public Form1() {
            InitializeComponent();
        }

        private void richTextBox1_ClientSizeChanged(object sender, EventArgs e) {
            hasScroll = !hasScroll;
        }
    }
}

The field hasScroll will be true when there is a scrollbar, false otherwise. Make sure you attach the method to the ClientSizeChanged event of the RichTextBox.

Edited 5 Years Ago by Momerath: n/a

This question has already been answered. Start a new discussion instead.