Friday, May 25, 2012

remove the Main Tab in Crystal Report Viewer WinForm

Omid's answer is correct, but you have to make sure to do that stuff after you have set the viewer's ReportSource. The version in my function below is a little more robust, and makes what's going on a little clearer, though I'm still not sure why doing that bit of magic to the TabControl's ItemSize and SizeMode make the tab bar go away.
// This is a method of a Form with one of these:
//     CrystalDecisions.Windows.Forms.CrystalReportViewer
// This hides the tab control with the "Main Report" button.
public void hideTheTabControl()
{
    System.Diagnostics.Debug.Assert(
        crystalReportViewer1.ReportSource != null, 
        "you have to set the ReportSource first");

    foreach (Control c1 in crystalReportViewer1.Controls)
    {
        if (c1 is CrystalDecisions.Windows.Forms.PageView)
        {
            PageView pv = (PageView)c1;
            foreach (Control c2 in pv.Controls)
            {
                if (c2 is TabControl)
                {
                    TabControl tc = (TabControl)c2;
                    tc.ItemSize = new Size(0, 1);
                    tc.SizeMode = TabSizeMode.Fixed;
                }
            }
        }
    }
}

V.2 รูปแบบ ที่ 2

 foreach (Control control in crystalReportViewer1.Controls)
            {

                if (control is CrystalDecisions.Windows.Forms.PageView)
                {

                    TabControl tab = (TabControl)(CrystalDecisions.Windows.Forms.PageView)control).Controls[0];

                    tab.ItemSize = new Size(0, 1);

                    tab.SizeMode = TabSizeMode.Fixed;

                    tab.Appearance = TabAppearance.Buttons;

                }

            }
ref : http://stackoverflow.com/questions/561586/how-can-i-remove-the-main-tab-in-crystal-report-viewer

1 comment: