เพิ่ม code ดังนี้
private void MDIMain_Resize(object sender, EventArgs e)
{
this.FormBorderStyle = FormBorderStyle.Sizable;
this.Width = Screen.PrimaryScreen.Bounds.Width;
this.Height = Screen.PrimaryScreen.WorkingArea.Height;
}
form.ShowInTaskbar = false;
public partial class Form1 : Form
{
Form2 f2;
public Form1()
{
InitializeComponent();
f2 = new Form2();
f2.Owner = this; // <-- This is the important thing
f2.Show();
}
}
Example :private void ShowInTaskBarEx() { Form myForm = new Form(); myForm.Text = "My Form"; myForm.SetBounds(10,10,200,200); myForm.FormBorderStyle = FormBorderStyle.FixedDialog; myForm.MinimizeBox = false; myForm.MaximizeBox = false; // Do not allow form to be displayed in taskbar. myForm.ShowInTaskbar = false; myForm.ShowDialog(); }
ref : http://msdn.microsoft.com/en-us/library/system.windows.forms.form.showintaskbar(v=vs.80).aspx
private void PrintReport(string printerName) { PageMargins margins; // Get the PageMargins structure and set the // margins for the report. margins = Report.PrintOptions.PageMargins; margins.bottomMargin = 350; margins.leftMargin = 350; margins.rightMargin = 350; margins.topMargin = 350; // Apply the page margins. Report.PrintOptions.ApplyPageMargins(margins); // Select the printer. Report.PrintOptions.PrinterName = printerName; // Print the report. Set the startPageN and endPageN // parameters to 0 to print all pages. Report.PrintToPrinter(1, false,0,0); }
crReportDocument.PrintToPrinter(nCopy, false, sPage, ePage);
private void button2_Click(object sender, System.EventArgs e)
{
//Open the PrintDialog
this.printDialog1.Document = this.printDocument1;
DialogResult dr = this.printDialog1.ShowDialog();
if(dr == DialogResult.OK)
{
//Get the Copy times
int nCopy = this.printDocument1.PrinterSettings.Copies;
//Get the number of Start Page
int sPage = this.printDocument1.PrinterSettings.FromPage;
//Get the number of End Page
int ePage = this.printDocument1.PrinterSettings.ToPage;
//Get the printer name
string PrinterName = this.printDocument1.PrinterSettings.PrinterName;
crReportDocument = new ReportDocument();
//Create an instance of a report
crReportDocument = new Chart();
try
{
//Set the printer name to print the report to. By default the sample
//report does not have a defult printer specified. This will tell the
//engine to use the specified printer to print the report. Print out
//a test page (from Printer properties) to get the correct value.
crReportDocument.PrintOptions.PrinterName = PrinterName;
//Start the printing process. Provide details of the print job
//using the arguments.
crReportDocument.PrintToPrinter(nCopy, false, sPage, ePage);
//Let the user know that the print job is completed
MessageBox.Show("Report finished printing!");
}
catch(Exception err)
{
MessageBox.Show(err.ToString());
}
}
}
// 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;
}
}
}
}
}
{
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