示例#1
0
        /// <summary>
        /// Gets a string format with specified settings.
        /// </summary>
        /// <param name="align">Text alignment information on the vertical plane.</param>
        /// <param name="lineAlign">Line alignment on the horizontal plane.</param>
        /// <param name="trimming"><b>StringTrimming</b> enumeration.</param>
        /// <param name="flags"><b>StringFormatFlags</b> enumeration that contains formatting information.</param>
        /// <param name="firstTab">The number of spaces between the beginning of a line of text and the first tab stop.</param>
        /// <param name="tabWidth">Distance between tab stops.</param>
        /// <param name="defaultTab">Default distance between default tabs stops.</param>
        /// <returns>The <b>StringFormat</b> object.</returns>
        public StringFormat GetStringFormat(StringAlignment align, StringAlignment lineAlign,
                                            StringTrimming trimming, StringFormatFlags flags, float firstTab, FloatCollection tabWidth,
                                            float defaultTab)
        {
            int hash = align.GetHashCode() ^ (lineAlign.GetHashCode() << 2) ^ (trimming.GetHashCode() << 5) ^
                       (flags.GetHashCode() << 16) ^ (100 - firstTab).GetHashCode() ^ tabWidth.GetHashCode();
            StringFormat result = stringFormats[hash] as StringFormat;

            if (result == null)
            {
                result               = new StringFormat();
                result.Alignment     = align;
                result.LineAlignment = lineAlign;
                result.Trimming      = trimming;
                result.FormatFlags   = flags;
                float[] tabStops = new float[64];
                // fixed issue 2823
                tabStops[0] = firstTab;
                for (int i = 1; i < 64; i++)
                {
                    if (i > tabWidth.Count)
                    {
                        tabStops[i] = defaultTab;
                        continue;
                    }
                    tabStops[i] = tabWidth[i - 1];
                }
                result.SetTabStops(0, tabStops);
                stringFormats[hash] = result;
            }
            return(result);
        }
示例#2
0
        private void pbPreview_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            g.SmoothingMode = SmoothingMode.HighQuality;
            PictureBox pb   = (PictureBox)sender;
            RectangleF rect = new RectangleF(0, 0, pb.Width, pb.Height);

            try
            {
                using (Font font = text.Font())
                {
                    using (Brush brush = text.FontBrush())
                    {
                        StringFormatFlags options = text.Vertical ?
                                                    StringFormatFlags.DirectionVertical : (StringFormatFlags)0;
                        using (StringFormat format = new StringFormat(options))
                        {
                            format.Alignment     = text.Alignment;
                            format.LineAlignment = text.LineAlignment;
                            g.DrawString("Съешь ещё этих хрустящих французских булочек...",
                                         font, brush, rect, format);
                        }
                    }
                }
            }
            catch
            {
                g.DrawString("Начертание не поддерживается.", SystemFonts.DialogFont,
                             Brushes.Black, rect);
            }
        }
示例#3
0
文件: TextFont.cs 项目: giszzt/GeoSOS
 /// <summary>
 /// Assigns the parameters from the specifed StringFormat class to the members of
 /// this TextFont.
 /// </summary>
 /// <param name="format">The StringFormat to apply to this object</param>
 public void SetFormat(StringFormat format)
 {
     _alignment     = format.Alignment;
     _flags         = format.FormatFlags;
     _lineAlignment = format.LineAlignment;
     _trimming      = format.Trimming;
 }
示例#4
0
            // Note: The following GDI+ StringFormat -> GDI TextFormatFlags mappings are taken from
            // http://msdn.microsoft.com/msdnmag/issues/06/03/TextRendering/default.aspx?fig=true#fig4
            private static TextFormatFlags TranslateFormatFlagsForGdi(StringFormatFlags formatFlags)
            {
                TextFormatFlags flags = 0;

                // Note: FitBlackBox is actually misnamed and is really NoFitBlackBox
                if ((formatFlags & StringFormatFlags.FitBlackBox) == StringFormatFlags.FitBlackBox)
                {
                    flags |= TextFormatFlags.NoPadding;
                }

                if ((formatFlags & StringFormatFlags.DirectionRightToLeft) == StringFormatFlags.DirectionRightToLeft)
                {
                    flags |= TextFormatFlags.RightToLeft;
                }

                if ((formatFlags & StringFormatFlags.NoClip) == StringFormatFlags.NoClip)
                {
                    flags |= TextFormatFlags.NoClipping;
                }

                if ((formatFlags & StringFormatFlags.LineLimit) == StringFormatFlags.LineLimit)
                {
                    flags |= TextFormatFlags.TextBoxControl;
                }

                if ((formatFlags & StringFormatFlags.NoWrap) == StringFormatFlags.NoWrap)
                {
                    flags |= TextFormatFlags.SingleLine;
                }

                return(flags);
            }
        private void DrawLabelPaint(object sender, PaintEventArgs arg)
        {
            Label  drawlabel = sender as Label;
            int    index     = drawlabel.Name.IndexOf("|");
            string text      = drawlabel.Name.Substring(index + 1);

            if (text.Length <= 0)
            {
                return;
            }
            Graphics g = arg.Graphics;

            g.Clear(drawlabel.BackColor);
            StringFormat sf = new StringFormat();

            sf.LineAlignment = StringAlignment.Center;
            sf.Alignment     = StringAlignment.Center;
            StringFormatFlags strflags = (StringFormatFlags)drawlabel.Tag;

            if ((strflags & StringFormatFlags.DirectionVertical) == StringFormatFlags.DirectionVertical)
            {
                strflags    |= StringFormatFlags.NoWrap;
                sf.Alignment = StringAlignment.Far;
            }
            sf.FormatFlags = strflags;
            g.DrawString(text, drawlabel.Font, new SolidBrush(drawlabel.ForeColor), arg.ClipRectangle, sf);
        }
        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
        {
            edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

            if (edSvc != null)
            {
                StringFormatFlags formatflag = (StringFormatFlags)value;

                ListBox box = new ListBox();

                box.BorderStyle = BorderStyle.None;

                box.Click += new EventHandler(box_Click);

                box.Items.AddRange(new string[] { "Default", "Right To Left", "Vertical", "NoWrap" });

                SetSelectFlag(formatflag, box);

                edSvc.DropDownControl(box);

                if (box.SelectedIndex >= 0)
                {
                    return(GetStringFormat(box));
                }
            }

            return(value);
        }
示例#7
0
        private static void DrawText(Graphics g, string strText, int x,
                                     int y, Font font, Color clrForeground, bool bRtl)
        {
            // With ClearType on, text drawn using Graphics.DrawString
            // looks better than TextRenderer.DrawText;
            // https://sourceforge.net/p/keepass/discussion/329220/thread/06ef4466/

            /* // On Windows 2000 the DrawText method taking a Point doesn't
             * // work by design, see MSDN:
             * // http://msdn.microsoft.com/en-us/library/ms160657.aspx
             * if(WinUtil.IsWindows2000)
             *      TextRenderer.DrawText(g, strText, font, new Rectangle(pt.X, pt.Y,
             *              nWidth - pt.X - 1, nHeight - pt.Y - 1), clrForeground, tff);
             * else
             *      TextRenderer.DrawText(g, strText, font, pt, clrForeground, tff); */

            using (SolidBrush br = new SolidBrush(clrForeground))
            {
                StringFormatFlags sff = (StringFormatFlags.FitBlackBox |
                                         StringFormatFlags.NoClip);
                if (bRtl)
                {
                    sff |= StringFormatFlags.DirectionRightToLeft;
                }

                using (StringFormat sf = new StringFormat(sff))
                {
                    g.DrawString(strText, font, br, x, y, sf);
                }
            }
        }
示例#8
0
        /// <summary>
        /// Draws the given string just like the Graphics.DrawString(). It changes the StringFormat to set the NoWrap flag if required.
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="s"></param>
        /// <param name="font"></param>
        /// <param name="brush"></param>
        /// <param name="layoutRectangle"></param>
        /// <param name="canWrap"></param>
        protected void DrawString(Graphics graphics, string s, Font font, Brush brush, RectangleF layoutRectangle, bool canWrap)
        {
            StringFormatFlags orig = this.StringFormat.FormatFlags;

            if (!canWrap)
            {
                StringFormat.FormatFlags = StringFormat.FormatFlags | StringFormatFlags.NoWrap;
            }

            try
            {
                graphics.DrawString(s, font, brush, layoutRectangle, this.StringFormat);
            }
            catch (Exception e)
            {
                e.Data.Add("s", s);
                e.Data.Add("Font", font.ToString());
                e.Data.Add("Brush", brush.ToString());
                e.Data.Add("Rectangle", layoutRectangle.ToString());
                e.Data.Add("canWrap", canWrap);
                throw;
            }

            if (!canWrap)
            {
                StringFormat.FormatFlags = orig;
            }
        }
示例#9
0
        public override void DrawClippedText(ref DrawTextArgs args, int x, int y, float maxWidth, float maxHeight)
        {
            if (!args.SkipPartsCheck)
            {
                GetTextParts(args.Text);
            }

            Brush             shadowBrush = GetOrCreateBrush(FastColour.Black);
            StringFormatFlags flags       = format.FormatFlags;

            format.FormatFlags |= StringFormatFlags.NoWrap;
            format.Trimming     = StringTrimming.EllipsisCharacter;
            float textX = x;

            for (int i = 0; i < parts.Count; i++)
            {
                TextPart   part      = parts[i];
                Brush      textBrush = GetOrCreateBrush(part.Col);
                RectangleF rect      = new RectangleF(textX + Offset, y + Offset, maxWidth, maxHeight);
                if (args.UseShadow)
                {
                    g.DrawString(part.Text, args.Font, shadowBrush, rect, format);
                }

                rect = new RectangleF(textX, y, maxWidth, maxHeight);
                g.DrawString(part.Text, args.Font, textBrush, rect, format);
                textX += g.MeasureString(part.Text, args.Font, Int32.MaxValue, format).Width;
            }
            format.Trimming    = StringTrimming.None;
            format.FormatFlags = flags;
        }
示例#10
0
        /// <summary>
        /// Centralize the string format settings. Does the work of checking for user
        /// overrides, and if they're not present, setting the cell alignment to match
        /// (somewhat) the source control's string alignment.
        /// </summary>
        /// <param name="alignment">String alignment</param>
        /// <param name="flags">String format flags</param>
        /// <param name="controlstyle">DataGridView style to apply (if available)</param>
        /// <param name="overrideformat">True if user overrode alignment or flags</param>
        /// <returns></returns>
        private static StringFormat managestringformat(StringAlignment alignment, StringFormatFlags flags,
                                                       DataGridViewCellStyle controlstyle, bool overrideformat)
        {
            // start with the provided
            StringFormat format = new StringFormat();

            format.Trimming    = StringTrimming.Word;
            format.Alignment   = alignment;
            format.FormatFlags = flags;

            // if the format was overridded by the user, make no adjustments
            if (!overrideformat)
            {
                // check to see if a style is provided
                if (null != controlstyle)
                {
                    // Adjust the format based on the control settings, bias towards centered
                    DataGridViewContentAlignment cellalign = controlstyle.Alignment;
                    if (cellalign.ToString().Contains("Middle"))
                    {
                        format.Alignment = StringAlignment.Center;
                    }
                    else if (cellalign.ToString().Contains("Right"))
                    {
                        format.Alignment = StringAlignment.Near;
                    }
                    else if (cellalign.ToString().Contains("Left"))
                    {
                        format.Alignment = StringAlignment.Far;
                    }
                }
            }

            return(format);
        }
 public StiStringFormatGeom(StringFormat sf)
 {
     this.Alignment     = sf.Alignment;
     this.FormatFlags   = sf.FormatFlags;
     this.HotkeyPrefix  = sf.HotkeyPrefix;
     this.LineAlignment = sf.LineAlignment;
     this.Trimming      = sf.Trimming;
 }
 public StringFormat(StringFormatFlags options, int language)
 {
     int status = SafeNativeMethods.Gdip.GdipCreateStringFormat(options, language, out this.nativeFormat);
     if (status != 0)
     {
         throw SafeNativeMethods.Gdip.StatusException(status);
     }
 }
示例#13
0
		public StringFormat(StringFormatFlags options) {
			this.native = LibIGraph.CreateStringFormat
				(StringAlignment.Near, options, StringAlignment.Near, StringTrimming.None);
			this.trimming = StringTrimming.None;
			this.alignment = StringAlignment.Near;
			this.lineAlignment = StringAlignment.Near;
			this.stringFormatFlags = options;
		}
示例#14
0
        public void FormatFlags_Set_GetReturnsExpected(StringFormatFlags formatFlags)
        {
            var format = new StringFormat {
                FormatFlags = formatFlags
            };

            Assert.Equal(formatFlags, format.FormatFlags);
        }
		public StringFormat(StringFormatFlags options, int lang) {
			_alignment = StringAlignment.Near;
			_digitSubstituteLanguage = lang;
			_digitSubstituteMethod = StringDigitSubstitute.User;
			_flags = options;
			_hotkeyPrefix = HotkeyPrefix.None;
			_lineAlignment = StringAlignment.Near;
			_trimming = StringTrimming.Character;
		}
示例#16
0
        public static StringFormat CreateGenericTypographic()
        {
            StringFormatFlags formatFlags = StringFormatFlags.FitBlackBox
                                            | StringFormatFlags.LineLimit | StringFormatFlags.NoClip;
            var sf = new StringFormat(formatFlags, 0);

            sf.Trimming = StringTrimming.None;
            return(sf);
        }
示例#17
0
        /// <summary>
        /// Initializes a new instance of the <see cref='StringFormat'/> class with the specified
        /// <see cref='System.Drawing.StringFormatFlags'/> and language.
        /// </summary>
        public StringFormat(StringFormatFlags options, int language)
        {
            int status = SafeNativeMethods.Gdip.GdipCreateStringFormat(options, language, out nativeFormat);

            if (status != SafeNativeMethods.Gdip.Ok)
            {
                throw SafeNativeMethods.Gdip.StatusException(status);
            }
        }
示例#18
0
 public StringFormat(StringFormatFlags options)
 {
     this.native = LibIGraph.CreateStringFormat
                       (StringAlignment.Near, options, StringAlignment.Near, StringTrimming.None);
     this.trimming          = StringTrimming.None;
     this.alignment         = StringAlignment.Near;
     this.lineAlignment     = StringAlignment.Near;
     this.stringFormatFlags = options;
 }
示例#19
0
        public CreateStringFormatArgs(StringTrimming trimming, StringAlignment alignment, StringAlignment lineAlignment, StringFormatFlags flags)
        {
            Trimming      = trimming;
            Alignment     = alignment;
            LineAlignment = lineAlignment;
            Flags         = flags;

            _hash = ComputeHash();
        }
示例#20
0
 public BaseWrite(string value, Font font, StringFormatFlags formatFlags, StringAlignment alignment, StringAlignment linealigment)
 {
     Value        = value;
     FormatFlags  = formatFlags;
     Alignment    = alignment;
     Linealigment = linealigment;
     FontSize     = font.Size;
     FontFamily   = font.FontFamily.Name;
 }
示例#21
0
 private static bool AddFlag(ref StringFormatFlags formatFlags, StringFormatFlags flag)
 {
     if ((formatFlags & flag) == flag)
     {
         return(false);
     }
     formatFlags |= flag;
     return(true);
 }
示例#22
0
 private static bool RemoveFlag(ref StringFormatFlags formatFlags, StringFormatFlags flag)
 {
     if ((formatFlags & flag) != flag)
     {
         return(false);
     }
     formatFlags ^= flag;
     return(true);
 }
示例#23
0
        internal StringFormat GetStringFormat(GraphicCache cache, StringFormatFlags flags, float scale)
        {
            if (RightToLeft)
            {
                flags |= StringFormatFlags.DirectionRightToLeft;
            }

            return(cache.GetStringFormat(StringAlignment.Near, StringAlignment.Near, StringTrimming.None, flags, 0 * scale, 0 * scale));
        }
示例#24
0
        /// <summary>
        /// 显示文本,默认黑色
        /// </summary>
        /// <param name="grf"></param>
        /// <param name="drawString"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="drawFont"></param>
        /// <param name="StringFlag"></param>
        public static void DrawString(Graphics grf, string drawString, float x, float y,
                                      Font drawFont, StringFormatFlags StringFlag)
        {
            SolidBrush   drawBrush  = new SolidBrush(System.Drawing.Color.Black);
            StringFormat drawFormat = new StringFormat();

            drawFormat.FormatFlags = StringFlag;
            grf.DrawString(drawString, drawFont, drawBrush, x, y, drawFormat);
        }
示例#25
0
 public StringFormat(StringFormatFlags options, int lang)
 {
     _alignment = StringAlignment.Near;
     _digitSubstituteLanguage = lang;
     _digitSubstituteMethod   = StringDigitSubstitute.User;
     _flags         = options;
     _hotkeyPrefix  = HotkeyPrefix.None;
     _lineAlignment = StringAlignment.Near;
     _trimming      = StringTrimming.Character;
 }
示例#26
0
        /// <summary>
        /// Centralize the string format settings. Does the work of checking for user
        /// overrides, and if they're not present, setting the cell alignment to match
        /// (somewhat) the source control's string alignment.
        /// </summary>
        /// <param name="alignment">String alignment</param>
        /// <param name="flags">String format flags</param>
        /// <param name="controlstyle">DataGridView style to apply (if available)</param>
        /// <param name="overrideformat">True if user overrode alignment or flags</param>
        /// <returns></returns>
        private static StringFormat managestringformat(StringAlignment alignment, StringFormatFlags flags)
        {
            // start with the provided
            StringFormat format = new StringFormat();

            format.Trimming    = StringTrimming.Word;
            format.Alignment   = alignment;
            format.FormatFlags = flags;

            return(format);
        }
示例#27
0
        public void Ctor_Options_Language(StringFormatFlags options, int language)
        {
            var format = new StringFormat(options, language);

            Assert.Equal(StringAlignment.Near, format.Alignment);
            Assert.Equal(0, format.DigitSubstitutionLanguage);
            Assert.Equal(StringDigitSubstitute.User, format.DigitSubstitutionMethod);
            Assert.Equal(options, format.FormatFlags);
            Assert.Equal(HotkeyPrefix.None, format.HotkeyPrefix);
            Assert.Equal(StringAlignment.Near, format.LineAlignment);
            Assert.Equal(StringTrimming.Character, format.Trimming);
        }
		public StringFormat (StringFormat source) {
			if (source == null)
				throw new ArgumentNullException("format");

			_alignment = source.LineAlignment;
			_digitSubstituteLanguage = source.DigitSubstitutionLanguage;
			_digitSubstituteMethod = source.DigitSubstitutionMethod;
			_flags = source.FormatFlags;
			_hotkeyPrefix = source.HotkeyPrefix;
			_lineAlignment = source.LineAlignment;
			_trimming = source.Trimming;
		}
	private StringFormat(bool typographic)
			{
				if(typographic)
				{
					this.options = (StringFormatFlags.LineLimit |
					                StringFormatFlags.NoClip);
				}
				else
				{
					this.trimming = StringTrimming.Character;
				}
			}
示例#30
0
 private StringFormat(bool typographic)
 {
     if (typographic)
     {
         this.options = (StringFormatFlags.LineLimit |
                         StringFormatFlags.NoClip);
         this.IsTypographic = true;
     }
     else
     {
         this.trimming = StringTrimming.Character;
     }
 }
        private void CreateFormatString(StringAlignment textStringAlignment, StringAlignment lineStringAlignment, bool directionRightToLeft)
        {
            this.m_stringFormat               = new StringFormat(StringFormat.GenericDefault);
            this.m_stringFormat.Alignment     = textStringAlignment;
            this.m_stringFormat.LineAlignment = lineStringAlignment;
            this.m_stringFormat.Trimming      = StringTrimming.Word;
            StringFormatFlags stringFormatFlags = this.m_stringFormat.FormatFlags;

            stringFormatFlags &= ~StringFormatFlags.NoWrap;
            stringFormatFlags |= StringFormatFlags.LineLimit;
            this.UpdateFormatFlags(ref stringFormatFlags, true, directionRightToLeft);
            this.m_stringFormat.FormatFlags = stringFormatFlags;
        }
示例#32
0
        private void CreateFormatString(StringAlignment textStringAlignment, StringAlignment lineStringAlignment, bool directionRightToLeft)
        {
            m_stringFormat               = new StringFormat(StringFormat.GenericDefault);
            m_stringFormat.Alignment     = textStringAlignment;
            m_stringFormat.LineAlignment = lineStringAlignment;
            m_stringFormat.Trimming      = StringTrimming.Word;
            StringFormatFlags formatFlags = m_stringFormat.FormatFlags;

            formatFlags &= ~StringFormatFlags.NoWrap;
            formatFlags |= StringFormatFlags.LineLimit;
            UpdateFormatFlags(ref formatFlags, setWritingMode: true, directionRightToLeft);
            m_stringFormat.FormatFlags = formatFlags;
        }
示例#33
0
 public TextFormatInfo(Font font, StringFormat format, SizeF size, Color textColor, Color shadowColor, PointF shadowOffset)
 {
     FontFamilyName = font.FontFamily.Name;
     FontSize       = font.Size;
     FontStyle      = font.Style;
     Alignment      = format.Alignment;
     LineAlignment  = format.LineAlignment;
     FormatFlags    = format.FormatFlags;
     Trimming       = format.Trimming;
     Size           = size;
     TextColor      = textColor;
     ShadowColor    = shadowColor;
     ShadowOffset   = shadowOffset;
 }
        public void SetFormatFlags(Directions direction, bool setWritingMode, bool newFormatStrings)
        {
            bool directionRightToLeft = false;

            if (direction == Directions.RTL)
            {
                directionRightToLeft = true;
            }
            this.NewFormatStrings(newFormatStrings);
            StringFormatFlags formatFlags = this.m_stringFormat.FormatFlags;

            this.UpdateFormatFlags(ref formatFlags, setWritingMode, directionRightToLeft);
            this.m_stringFormat.FormatFlags = formatFlags;
        }
示例#35
0
        public void Enums()
        {
            YamlSerializer <StringFormatFlags> serializer = new YamlSerializer <StringFormatFlags>();

            StringFormatFlags flags = StringFormatFlags.NoClip | StringFormatFlags.NoFontFallback;

            StringWriter buffer = new StringWriter();

            serializer.Serialize(buffer, flags);

            StringFormatFlags deserialized = serializer.Deserialize(new StringReader(buffer.ToString()));

            Assert.AreEqual(flags, deserialized, "The value is incorrect.");
        }
        /// <summary>
        /// Initializes a new instance of <see cref="T:Dataweb.NShape.WinFormsUI.VerticalTabControl" />.
        /// </summary>
        public VerticalTabControl()
        {
            InitializeComponent();
            SetStyle(ControlStyles.AllPaintingInWmPaint |
                        ControlStyles.OptimizedDoubleBuffer |
                        ControlStyles.ResizeRedraw,
                        true);
            UpdateStyles();
            IntegralHeight = false;

            this.formatterFlags = 0 | StringFormatFlags.NoWrap;
            this.formatter = new StringFormat(formatterFlags);
            this.formatter.Trimming = StringTrimming.EllipsisCharacter;
            this.formatter.Alignment = StringAlignment.Center;
            this.formatter.LineAlignment = StringAlignment.Center;
        }
	public StringFormat(StringFormat format)
			{
				if(format == null)
				{
					throw new ArgumentNullException("format");
				}
				this.options = format.options;
				this.language = format.language;
				this.alignment = format.alignment;
				this.digitMethod = format.digitMethod;
				this.hotkeyPrefix = format.hotkeyPrefix;
				this.lineAlignment = format.lineAlignment;
				this.trimming = format.trimming;
				this.ranges = format.ranges;
				this.firstTabOffset = format.firstTabOffset;
				this.tabStops = format.tabStops;
			}
 public StringFormat(StringFormatFlags options) : this(options, 0)
 {
 }
示例#39
0
文件: Gdiplus.cs 项目: JianwenSun/cc
 internal static extern int GdipGetStringFormatFlags(HandleRef format, out StringFormatFlags result);
示例#40
0
 Dim sf As New StringFormat(StringFormatFlags.NoWrap)
 sf.LineAlignment = StringAlignment.Center
 public StringFormat(StringFormatFlags options)
 {
 }
        /// <summary>
        /// Constructor for DGVPrinter
        /// </summary>
        public sbDataGridPrinter()
        {
            // create print document
            printDoc = new PrintDocument();
            printDoc.PrintPage += new PrintPageEventHandler(printDoc_PrintPage);
            printDoc.BeginPrint += new PrintEventHandler(printDoc_BeginPrint);
            printmargins = new Margins(60, 60, 40, 40);

            // set default fonts
            pagenofont = new Font("Tahoma", 8, FontStyle.Regular, GraphicsUnit.Point);
            pagenocolor = Color.Black;
            titlefont = new Font("Tahoma", 18, FontStyle.Bold, GraphicsUnit.Point);
            titlecolor = Color.Black;
            subtitlefont = new Font("Tahoma", 12, FontStyle.Bold, GraphicsUnit.Point);
            subtitlecolor = Color.Black;
            footerfont = new Font("Tahoma", 10, FontStyle.Bold, GraphicsUnit.Point);
            footercolor = Color.Black;

            // set default string formats
            titlealignment = StringAlignment.Center;
            titleformatflags = StringFormatFlags.NoWrap | StringFormatFlags.LineLimit | StringFormatFlags.NoClip;

            subtitlealignment = StringAlignment.Center;
            subtitleformatflags = StringFormatFlags.NoWrap | StringFormatFlags.LineLimit | StringFormatFlags.NoClip;

            footeralignment = StringAlignment.Center;
            footerformatflags = StringFormatFlags.NoWrap | StringFormatFlags.LineLimit | StringFormatFlags.NoClip;

            pagenumberalignment = StringAlignment.Far;
            pagenumberformatflags = StringFormatFlags.NoWrap | StringFormatFlags.LineLimit | StringFormatFlags.NoClip;

            headercellalignment = StringAlignment.Near;
            headercellformatflags = StringFormatFlags.NoWrap | StringFormatFlags.LineLimit | StringFormatFlags.NoClip;

            cellalignment = StringAlignment.Near;
            cellformatflags = StringFormatFlags.NoWrap | StringFormatFlags.LineLimit | StringFormatFlags.NoClip;
        }
示例#43
0
 /// <summary>
 /// Assigns the parameters from the specifed StringFormat class to the members of
 /// this TextFont.
 /// </summary>
 /// <param name="format">The StringFormat to apply to this object</param>
 public void SetFormat(StringFormat format)
 {
     _alignment = format.Alignment;
     _flags = format.FormatFlags;
     _lineAlignment = format.LineAlignment;
     _trimming = format.Trimming;
 }
示例#44
0
		public StringFormat (StringFormatFlags options)
		{
			Status status = GDIPlus.GdipCreateStringFormat (options, GDIPlus.LANG_NEUTRAL, out nativeStrFmt);
			GDIPlus.CheckStatus (status);			
		}
 public StringFormat(StringFormatFlags options, int language)
     : this(options)
 {
 }
示例#46
0
 public static extern void StringFormat_SetFormatFlags(IntPtr stringFormat, StringFormatFlags formatFlags);
示例#47
0
		private static bool AddFlag(ref StringFormatFlags formatFlags, StringFormatFlags flag) {
			if ((formatFlags & flag) == flag) return false;
			formatFlags |= flag;
			return true;
		}
        /// <summary>
        /// Centralize the string format settings. Does the work of checking for user
        /// overrides, and if they're not present, setting the cell alignment to match
        /// (somewhat) the source control's string alignment.
        /// </summary>
        /// <param name="alignment">String alignment</param>
        /// <param name="flags">String format flags</param>
        /// <param name="controlstyle">DataGridView style to apply (if available)</param>
        /// <param name="overrideformat">True if user overrode alignment or flags</param>
        /// <returns></returns>
        private static StringFormat managestringformat(StringAlignment alignment, StringFormatFlags flags,
            DataGridViewCellStyle controlstyle, bool overrideformat)
        {
            // start with the provided
            StringFormat format = new StringFormat();
            format.Trimming = StringTrimming.Word;
            format.Alignment = alignment;
            format.FormatFlags = flags;
            format.Trimming = StringTrimming.Character;

            // if the format was overridded by the user, make no adjustments
            if (!overrideformat)
            {
                // check to see if a style is provided
                if (null != controlstyle)
                {
                    // Adjust the format based on the control settings, bias towards centered
                    DataGridViewContentAlignment cellalign = controlstyle.Alignment;
                    if (cellalign.ToString().Contains("Center")) format.Alignment = StringAlignment.Center;
                    else if (cellalign.ToString().Contains("Left")) format.Alignment = StringAlignment.Near;
                    else if (cellalign.ToString().Contains("Right")) format.Alignment = StringAlignment.Far;
                }
            }

            return format;
        }
 public StringFormat(StringFormatFlags options)
     : this()
 {
     formatFlags = options;
 }
示例#50
0
        private void Configure()
        {
            // brush
            _color = Color.Black;

            // font
            _familyName = FontFamily.GenericSansSerif.Name;
            _size = 8;
            _style = FontStyle.Regular;

            // format
            StringFormat temp = new StringFormat();
            _alignment = temp.Alignment;
            _flags = temp.FormatFlags;
            _lineAlignment = temp.LineAlignment;
            _trimming = temp.Trimming;
            temp.Dispose();
        }
示例#51
0
		// StringFormat
		private void CheckStringFormat (IntPtr sf, StringFormatFlags exepcted_flags, StringTrimming expected_trimmings)
		{
			StringAlignment sa = StringAlignment.Center;
			Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipGetStringFormatAlign (IntPtr.Zero, out sa), "GdipGetStringFormatAlign-null");
			Assert.AreEqual (Status.Ok, GDIPlus.GdipGetStringFormatAlign (sf, out sa), "GdipGetStringFormatAlign");
			Assert.AreEqual (StringAlignment.Near, sa, "StringAlignment-1");

			StringAlignment la = StringAlignment.Center;
			Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipGetStringFormatLineAlign (IntPtr.Zero, out la), "GdipGetStringFormatLineAlign-null");
			Assert.AreEqual (Status.Ok, GDIPlus.GdipGetStringFormatLineAlign (sf, out la), "GdipGetStringFormatLineAlign");
			Assert.AreEqual (StringAlignment.Near, la, "StringAlignment-2");

			StringFormatFlags flags = StringFormatFlags.DirectionRightToLeft;
			Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipGetStringFormatFlags (IntPtr.Zero, out flags), "GdipGetStringFormatFlags-null");
			Assert.AreEqual (Status.Ok, GDIPlus.GdipGetStringFormatFlags (sf, out flags), "GdipGetStringFormatFlags");
			Assert.AreEqual (exepcted_flags, flags, "StringFormatFlags");

			HotkeyPrefix hotkey = HotkeyPrefix.Show;
			Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipGetStringFormatHotkeyPrefix (IntPtr.Zero, out hotkey), "GdipGetStringFormatHotkeyPrefix-null");
			Assert.AreEqual (Status.Ok, GDIPlus.GdipGetStringFormatHotkeyPrefix (sf, out hotkey), "GdipGetStringFormatHotkeyPrefix");
			Assert.AreEqual (HotkeyPrefix.None, hotkey, "HotkeyPrefix");

			StringTrimming trimming = StringTrimming.None;
			Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipGetStringFormatTrimming (IntPtr.Zero, out trimming), "GdipGetStringFormatTrimming-null");
			Assert.AreEqual (Status.Ok, GDIPlus.GdipGetStringFormatTrimming (sf, out trimming), "GdipGetStringFormatTrimming");
			Assert.AreEqual (expected_trimmings, trimming, "StringTrimming");

			StringDigitSubstitute sub = StringDigitSubstitute.Traditional;
			Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipGetStringFormatDigitSubstitution (IntPtr.Zero, 0, out sub), "GdipGetStringFormatDigitSubstitution-null");
			Assert.AreEqual (Status.Ok, GDIPlus.GdipGetStringFormatDigitSubstitution (sf, 0, out sub), "GdipGetStringFormatDigitSubstitution");
			Assert.AreEqual (StringDigitSubstitute.User, sub, "StringDigitSubstitute");

			int count;
			Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipGetStringFormatMeasurableCharacterRangeCount (IntPtr.Zero, out count), "GdipGetStringFormatMeasurableCharacterRangeCount-null");
			Assert.AreEqual (Status.Ok, GDIPlus.GdipGetStringFormatMeasurableCharacterRangeCount (sf, out count), "GdipGetStringFormatMeasurableCharacterRangeCount");
			Assert.AreEqual (0, count, "count");
		}
        /// <summary>
        /// Print a header or footer section. Used for page numbers and titles
        /// </summary>
        /// <param name="g">Graphic context to print in</param>
        /// <param name="pos">Track vertical space used; 'y' location</param>
        /// <param name="text">String to print</param>
        /// <param name="font">Font to use for printing</param>
        /// <param name="color">Color to print in</param>
        /// <param name="alignment">Alignment - print to left, center or right</param>
        /// <param name="flags">String format flags</param>
        /// <param name="useroverride">True if the user overrode the alignment or flags</param>
        /// <param name="margins">The table's print margins</param>
        private void printsection(Graphics g, ref float pos, string text,
            Font font, Color color, StringAlignment alignment, StringFormatFlags flags,
            bool useroverride, Margins margins)
        {
            // string formatting setup
            StringFormat printformat = managestringformat(alignment, flags, null, useroverride);

            // measure string
            SizeF printsize = g.MeasureString(text, font, printWidth, printformat);

            // build area to print within
            RectangleF printarea = new RectangleF((float)margins.Left, pos, (float)printWidth,
               printsize.Height);

            // do the actual print
            g.DrawString(text, font, new SolidBrush(color), printarea, printformat);

            // track "used" vertical space
            pos += printsize.Height;
        }
示例#53
0
 public static extern IntPtr CreateStringFormat(StringAlignment alignment, StringFormatFlags formatFlags, StringAlignment lineAlignment, StringTrimming stringTrimming);
	public StringFormat(StringFormatFlags options, int language)
			{
				this.options = options;
				this.language = language;
				this.trimming = StringTrimming.Character;
			}
示例#55
0
        /// <summary>
        /// Initializes a new instance of <see cref="T:Dataweb.NShape.WinFormsUI.DesignPresenter" />.
        /// </summary>
        public DesignPresenter()
        {
            SetStyle(ControlStyles.ResizeRedraw
                | ControlStyles.AllPaintingInWmPaint
                | ControlStyles.OptimizedDoubleBuffer
                | ControlStyles.SupportsTransparentBackColor
                , true);
            UpdateStyles();

            // Initialize Components
            InitializeComponent();
            infoGraphics = Graphics.FromHwnd(Handle);

            this.matrix = new Matrix();
            this.formatterFlags = 0 | StringFormatFlags.NoWrap;
            this.formatter = new StringFormat(formatterFlags);
            this.formatter.Trimming = StringTrimming.EllipsisCharacter;
            this.formatter.Alignment = StringAlignment.Center;
            this.formatter.LineAlignment = StringAlignment.Center;

            propertyGrid.Site = this.Site;
            styleListBox.BackColor = SelectedItemColor;
        }
	public StringFormat(StringFormatFlags options)
			{
				this.options = options;
				this.trimming = StringTrimming.Character;
				
			}
示例#57
0
		public StringFormat(StringFormatFlags options, int language)
		{
			Status status = GDIPlus.GdipCreateStringFormat (options, language, out nativeStrFmt);        			
			GDIPlus.CheckStatus (status);
		}
示例#58
0
		internal static extern Status GdipCreateStringFormat(StringFormatFlags formatAttributes,  int language, out IntPtr native);
示例#59
0
		private static bool RemoveFlag(ref StringFormatFlags formatFlags, StringFormatFlags flag) {
			if ((formatFlags & flag) != flag) return false;
			formatFlags ^= flag;
			return true;
		}
示例#60
0
		internal static extern Status GdipGetStringFormatFlags(IntPtr format, out StringFormatFlags flags);