I am appending text to RichTextBox. When text is more than visible area of richtextbox then automatically Vertical ScrollBar appears.
I want to check if no scrollbar is present than set Padding to 5. If scrollbar appears then padding should be 0
private void frmAno_Load(object sender, EventArgs e)
{
DisplayingAnomalies();
ChangeFormSize();
}
private void DisplayingAnomalies()
{
int length;
string heading;
switch (_lstNullSheet.Count == 0 ? "zero" :
_lstNullSheet.Count == 1 ? "one" :
_lstNullSheet.Count > 1 ? "more" : "floor")
{
case "zero":
break;
case "one":
heading = "Empty Sheet";
rtbDisplay.Text = String.Format("{0}\r\n[", heading);
rtbDisplay.AppendText(_lstNullSheet[0] + "] Sheet in Excel has no data.\r\n\n");
break;
case "more":
heading = "Empty Sheets";
rtbDisplay.Text = String.Format("{0}\r\n",heading);
foreach(var item in _lstNullSheet)
{
rtbDisplay.AppendText("["+item);
length = rtbDisplay.Text.Length;
if(_lstNullSheet.Last().Equals(item))
{
rtbDisplay.AppendText("] Sheets in Excel has no data.afsdfaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n\n");
break;
}
rtbDisplay.AppendText("], ");
}
break;
case "floor":
break;
default:
break;
}
_sizeToChange = true;
}
private void ChangeFormSize()
{
if(_sizeToChange)
{
this.Height = 200;
}
//Here i want to check if scrollbar is present in richtextbox or not
if(rtbDisplay.Width - rtbDisplay.ClientSize.Width >=
SystemInformation.VerticalScrollBarWidth)
{
}
}
I have added the code for appending text to richtextbox. Then I am comparing the richtextbox width with scrollbar width.
RichTextBox.Width - RichTextBox.ClientSize.Width >= SystemInformation.VerticalScrollBarWidth
RichTextBox.Width - RichTextBox.ClientSize.Width >= SystemInformation.VerticalScrollBarWidth
this statement is false everytime. bczRichTextBox.Width - RichTextBox.ClientSize.Width
is equal to zeroRTB.Width - RTB.ClientSize.Width = 0
whenRTB.BorderStyle = None
, otherwise= 4
. Until you add enough text to make the vertical scrollbar appear. After that,RTB.Width - RTB.ClientSize.Width = SystemInformation.VerticalScrollBarWidth