예제 #1
0
        private bool getValues(out Size pageSize, out Thickness pageMargins)
        {
            pageSize = new Size(); pageMargins = new Thickness();

            DiuToCentimetersConverter converter = new DiuToCentimetersConverter();

            try
            {
                double pageWidth        = (double)converter.ConvertBack(_pageWidthTextBox.Text, typeof(bool), null, CultureInfo.CurrentCulture);
                double pageHeight       = (double)converter.ConvertBack(_pageHeightTextBox.Text, typeof(bool), null, CultureInfo.CurrentCulture);
                double pageMarginTop    = (double)converter.ConvertBack(_pageMarginTopTextBox.Text, typeof(bool), null, CultureInfo.CurrentCulture);
                double pageMarginBottom = (double)converter.ConvertBack(_pageMarginBottomTextBox.Text, typeof(bool), null, CultureInfo.CurrentCulture);
                double pageMarginLeft   = (double)converter.ConvertBack(_pageMarginLeftTextBox.Text, typeof(bool), null, CultureInfo.CurrentCulture);
                double pageMarginRight  = (double)converter.ConvertBack(_pageMarginRightTextBox.Text, typeof(bool), null, CultureInfo.CurrentCulture);

                if (pageWidth < 0 || pageHeight < 0)
                {
                    ExceptionManager.ShowWarningDialog("Page dimensions cannot be negative.");
                    return(false);
                }

                if (pageMarginTop < 0 || pageMarginRight < 0 || pageMarginLeft < 0 || pageMarginBottom < 0)
                {
                    ExceptionManager.ShowWarningDialog("Page margins cannot be negative.");
                    return(false);
                }

                if (pageMarginTop + pageMarginBottom > pageHeight || pageMarginLeft + pageMarginRight > pageWidth)
                {
                    ExceptionManager.ShowWarningDialog("Page margins are larger than page size.");
                    return(false);
                }

                pageSize    = new Size(pageWidth, pageHeight);
                pageMargins = new Thickness(pageMarginLeft, pageMarginTop, pageMarginRight, pageMarginBottom);
                return(true);
            }
            catch (FormatException)
            {
                ExceptionManager.ShowWarningDialog("One or more fields are not valid.");
            }
            catch (OverflowException)
            {
                ExceptionManager.ShowWarningDialog("One or more fields are not valid.");
            }
            return(false);
        }
예제 #2
0
        private bool getValues(out Size pageSize, out Thickness pageMargins)
        {
            pageSize    = new Size();
            pageMargins = new Thickness();

            DiuToCentimetersConverter converter = new DiuToCentimetersConverter();

            try
            {
                double pageWidth        = (double)converter.ConvertBack(this._pageWidthTextBox.Text, typeof(bool), null, CultureInfo.CurrentCulture);
                double pageHeight       = (double)converter.ConvertBack(this._pageHeightTextBox.Text, typeof(bool), null, CultureInfo.CurrentCulture);
                double pageMarginTop    = (double)converter.ConvertBack(this._pageMarginTopTextBox.Text, typeof(bool), null, CultureInfo.CurrentCulture);
                double pageMarginBottom = (double)converter.ConvertBack(this._pageMarginBottomTextBox.Text, typeof(bool), null, CultureInfo.CurrentCulture);
                double pageMarginLeft   = (double)converter.ConvertBack(this._pageMarginLeftTextBox.Text, typeof(bool), null, CultureInfo.CurrentCulture);
                double pageMarginRight  = (double)converter.ConvertBack(this._pageMarginRightTextBox.Text, typeof(bool), null, CultureInfo.CurrentCulture);

                if (pageWidth < 0 || pageHeight < 0)
                {
                    _MsgBox.Show(string.Format(MiniUML.Framework.Local.Strings.STR_MSG_PAGE_HEIGHT_WIDTH_NEGATIVE, pageWidth, pageHeight),
                                 MiniUML.Framework.Local.Strings.STR_MSG_Warning_Caption,
                                 MsgBox.MsgBoxButtons.OK, MsgBox.MsgBoxImage.Warning);

                    return(false);
                }

                if (pageMarginTop < 0 || pageMarginRight < 0 || pageMarginLeft < 0 || pageMarginBottom < 0)
                {
                    _MsgBox.Show(string.Format(MiniUML.Framework.Local.Strings.STR_MSG_PAGE_MARGINS_NEGATIVE),
                                 MiniUML.Framework.Local.Strings.STR_MSG_Warning_Caption,
                                 MsgBox.MsgBoxButtons.OK, MsgBox.MsgBoxImage.Warning);

                    return(false);
                }

                if (pageMarginTop + pageMarginBottom > pageHeight || pageMarginLeft + pageMarginRight > pageWidth)
                {
                    _MsgBox.Show(string.Format(MiniUML.Framework.Local.Strings.STR_MSG_PAGE_MARGIN_LARGER_THAN_PAGESIZE),
                                 MiniUML.Framework.Local.Strings.STR_MSG_Warning_Caption,
                                 MsgBox.MsgBoxButtons.OK, MsgBox.MsgBoxImage.Warning);

                    return(false);
                }

                pageSize    = new Size(pageWidth, pageHeight);
                pageMargins = new Thickness(pageMarginLeft, pageMarginTop, pageMarginRight, pageMarginBottom);
                return(true);
            }
            catch (FormatException)
            {
                _MsgBox.Show(string.Format(MiniUML.Framework.Local.Strings.STR_MSG_PAGE_DEFINITION_FIELD_INVALID),
                             MiniUML.Framework.Local.Strings.STR_MSG_Warning_Caption,
                             MsgBox.MsgBoxButtons.OK, MsgBox.MsgBoxImage.Warning);
            }
            catch (OverflowException)
            {
                _MsgBox.Show(string.Format(MiniUML.Framework.Local.Strings.STR_MSG_PAGE_DEFINITION_FIELD_INVALID),
                             MiniUML.Framework.Local.Strings.STR_MSG_Warning_Caption,
                             MsgBox.MsgBoxButtons.OK, MsgBox.MsgBoxImage.Warning);
            }

            return(false);
        }