// shows PrintOptionsDialog and prints selected style if user clicks Ok button private void InternalPrint() { // setup print context PrintContextType context = PrintContextType.DateRange; if (_schedule.SelectedAppointment != null) { context |= PrintContextType.Appointment; } // show PrintOptionsDialog PrintOptionsDialog form = new PrintOptionsDialog(this, CurrentStyle, context); form.StartDate = _schedule.VisibleDates[0]; form.EndDate = _schedule.VisibleDates[_schedule.VisibleDates.Count - 1]; bool?result = form.ShowDialog(); if (result.HasValue && result.Value) { // user clicks Ok // set PrintStyle properties according to user settings in a dialog CurrentStyle = form.SelectedStyle; HidePrivateAppointments = form.HidePrivateAppointments; SetupPrintContext(CurrentStyle, form.StartDate, form.EndDate); // print the document PrintDocument.Print(new System.Drawing.Printing.PrinterSettings()); _currentAppointments = null; } }
/// <summary> /// Initializes a new instance of the <see cref="PrintOptionsForm"/> form. /// </summary> /// <param name="info">The <see cref="PrintInfo"/> object.</param> /// <param name="defaultStyle">The <see cref="PrintStyle"/> object which should be selected initially.</param> /// <param name="printContext">The <see cref="PrintContextType"/> value, determining the filter of styles which should be shown in a form.</param> public PrintOptionsDialog(PrintInfo info, PrintStyle defaultStyle, PrintContextType printContext) { InitializeComponent(); _context = printContext; _info = info; foreach (PrintStyle ps in _info.PrintStyles) { if ((_context & ps.Context) != 0) { lstStyles.Items.Add(ps); } } if (defaultStyle != null && lstStyles.Items.Count > 0) { lstStyles.SelectedItem = defaultStyle; } _hidePrivateAppointmentsInitial = HidePrivateAppointments = _info.HidePrivateAppointments; }