How to: Tweak the Crystal Reports Viewer control
Novita Wegbrands, a colleague of mine, needed to hide the tabs that are usually shown in the Crystal reports viewer. Either that, or change the default "MainReport" description. She found some code here on forums.belution.com/en/crystal that suited her needs. She sent the code to me (thanks Novita!) and I changed them a little so they would fit my library of Crystal Helper classes. So here's what we have now.
Show / Hide the status bar
By default, the Crystal Reports viewer shows a status bar at the bottom to indicate the current page, the total number of pages and the current zoom factor. But maybe you'd like to hide it. No problem, the following code will do just that:
public void ViewerStatusBar(CrystalReportViewer viewer, bool visible)
{ foreach (Control control in viewer.Controls)
{ if (control.GetType().Name.ToString() == "StatusBar")
{ control.Visible = visible;
}
}
}
Show / Hide the tabs
The Crystal Reports viewer will also display tabs for the report. By default there is always one. But when it not possible to perform a drill-down in a report then this tab is virtually useless. Using the following code, you can hide those tabs:
public void ViewerTabs(CrystalReportViewer viewer, bool visible)
{ foreach (Control control in viewer.Controls)
{ if (control is PageView)
{ TabControl tab = (TabControl)((PageView)control).Controls[0];
if (!visible)
{ tab.ItemSize = new Size(0, 1);
tab.SizeMode = TabSizeMode.Fixed;
tab.Appearance = TabAppearance.Buttons;
}
else
{ tab.ItemSize = new Size(67, 18);
tab.SizeMode = TabSizeMode.Normal;
tab.Appearance = TabAppearance.Normal;
}
}
}
}
The ItemSize that is created on the tab control is a default size. Because the SizeMode property is set to Normal, Crystal Reports will automatically scale the tab to fit the name.
Change the name of the tab
As stated before, the default name for the first tab is usually MainReport. It is possible to change this by using the following code: