/// <summary> /// </summary> /// <param name="control"></param> internal void setEditControlProperties(MgTextBox control) { //fixed defect #142195 ContentAlignment contentAlignment = Manager.GetSpecialEditLeftAlign() ? ContentAlignment.TopLeft : ContentAlignment; ControlUtils.SetContentAlignment(control, contentAlignment); //For defect #77033, it is needed that setTextProperties will be called after setting the border (pl refer //Fix Instructions for problem details). //But, this created problem for automated tests and defect #109374 was opened for the same (pl refer //Fix Instructions for problem details). //So, applying the fix for #77033 only if AllowTesting=No. if (GuiUtils.AccessTest) { setTextProperties(control, Text); } if ((control).BorderStyle != (_showBorder ? BorderStyle.FixedSingle : BorderStyle.None)) { ControlUtils.SetBorder(control, ShowBorder); } if (!GuiUtils.AccessTest) { setTextProperties(control, Text); } GuiUtilsBase.setImeMode(control, _imeMode); }
/// <summary> /// Draw the text. /// </summary> /// <param name="hdc"></param> /// <param name="color"></param> /// <param name="rect"></param> /// <param name="topOffset"></param> /// <param name="orientation"></param> /// <param name="fontDescription"></param> /// <param name="text"></param> /// <param name="contentAlignment"></param> /// <param name="flags"></param> public static void DrawText(IntPtr hdc, Color color, Rectangle rect, int topOffset, int orientation, FontDescription fontDescription, String text, ContentAlignment contentAlignment, int flags, bool rightToLeft) { NativeWindowCommon.SetBkMode(hdc, NativeWindowCommon.TRANSPARENT); NativeWindowCommon.SetTextColor(hdc, ColorTranslator.ToWin32(color)); #if !PocketPC // QCR #439182 & 430913: the font is used for a control before even being initialized. // TODO: We need a better fix that avoids calling get_Font() for logical controls that are not initialized properly. if (fontDescription == null) { fontDescription = new FontDescription(Control.DefaultFont); } #endif NativeWindowCommon.RECT rc = new NativeWindowCommon.RECT(); rc.left = rect.Left; rc.right = rect.Right; rc.top = rect.Top + topOffset; rc.bottom = rect.Bottom; #if !PocketPC if (orientation != 0) { PrintRotatedText(hdc, fontDescription, orientation, text, rect, contentAlignment, rc, rightToLeft); } else #endif { IntPtr hFont = fontDescription.FontHandle; NativeWindowCommon.SelectObject(hdc, hFont); NativeWindowCommon.DrawText(hdc, text, text.Length, ref rc, flags); } }
/// <summary> /// translate ContentAlignment to VerticalAlignment /// </summary> /// <param name="contentAlignment"></param> /// <returns></returns> public static VerticalAlignment ContentAlignment2VerticalAlignment(ContentAlignment contentAlignment) { VerticalAlignment verticalAlignment = VerticalAlignment.Top; switch (contentAlignment) { case ContentAlignment.BottomCenter: case ContentAlignment.BottomLeft: case ContentAlignment.BottomRight: verticalAlignment = VerticalAlignment.Bottom; break; case ContentAlignment.MiddleCenter: case ContentAlignment.MiddleLeft: case ContentAlignment.MiddleRight: verticalAlignment = VerticalAlignment.Center; break; case ContentAlignment.TopCenter: case ContentAlignment.TopLeft: case ContentAlignment.TopRight: verticalAlignment = VerticalAlignment.Top; break; } return(verticalAlignment); }
/// <summary> /// translate ContentAlignment to HorizontalAlignment /// </summary> /// <param name="contentAlignment"></param> /// <returns></returns> public static HorizontalAlignment ContentAlignment2HorizontalAlignment(ContentAlignment contentAlignment) { HorizontalAlignment horizontalAlignment = HorizontalAlignment.Left; switch (contentAlignment) { case ContentAlignment.BottomCenter: case ContentAlignment.MiddleCenter: case ContentAlignment.TopCenter: horizontalAlignment = HorizontalAlignment.Center; break; case ContentAlignment.BottomLeft: case ContentAlignment.MiddleLeft: case ContentAlignment.TopLeft: horizontalAlignment = HorizontalAlignment.Left; break; case ContentAlignment.BottomRight: case ContentAlignment.MiddleRight: case ContentAlignment.TopRight: horizontalAlignment = HorizontalAlignment.Right; break; default: break; } return(horizontalAlignment); }
/// <summary> /// Gets the text information. /// </summary> /// <param name="g"></param> /// <param name="rect"></param> /// <param name="color"></param> /// <param name="fontDescription"></param> /// <param name="text"></param> /// <param name="multiLine"></param> /// <param name="contentAlignment"></param> /// <param name="enabled"></param> /// <param name="wordWrap"></param> /// <param name="addNoPrefixFlag"></param> /// <param name="addNoClipping"></param> /// <param name="rightToLeft"></param> /// <param name="calcVerticalAligmentInMultiLine"></param> /// <param name="topOffset"></param> /// <param name="flags"></param> public static void GetTextInformation(Graphics g, ref Rectangle rect, ref Color color, FontDescription fontDescription, String text, bool multiLine, ContentAlignment contentAlignment, bool enabled, bool wordWrap, bool addNoPrefixFlag, bool addNoClipping, bool rightToLeft, bool calcVerticalAligmentInMultiLine, out int topOffset, out int flags) { flags = CalcFlags(g, ref rect, ref color, multiLine, contentAlignment, enabled, wordWrap, addNoPrefixFlag, addNoClipping, rightToLeft); topOffset = CalcTopOffset(g, ref rect, fontDescription, text, multiLine, contentAlignment, calcVerticalAligmentInMultiLine, flags); }
public HeaderSection(string text, int cxWidth, int iImage, Bitmap bitmap, ContentAlignment enContentAlign, LeftRightAlignment enImageAlign, object tag) : this(text, cxWidth, iImage, bitmap, enContentAlign, enImageAlign) { _SetTag(tag); }
public HeaderSection(string text, int cxWidth, int iImage, Bitmap bitmap, ContentAlignment enContentAlign, LeftRightAlignment enImageAlign) : this(text, cxWidth, iImage, bitmap, enContentAlign) { ContentAlignment = enContentAlign; }
public HeaderSection(string text, int cxWidth, int iImage, Bitmap bitmap, RightToLeft enRightToLeft, ContentAlignment enContentAlign, LeftRightAlignment enImageAlign, HeaderSectionSortMarks enSortMark, object tag) : this(text, cxWidth, iImage, bitmap, enContentAlign, enImageAlign, tag) { _SetSortMark(enSortMark); }
protected override void OnPaint(PaintEventArgs e) { //Simulate Transparency if (BackColor == Color.Transparent) { #if !PocketPC if (Parent is ISupportsTransparentChildRendering) { ((ISupportsTransparentChildRendering)Parent).TransparentChild = this; } System.Drawing.Drawing2D.GraphicsContainer g = e.Graphics.BeginContainer(); Rectangle translateRect = this.Bounds; e.Graphics.TranslateTransform(-Left, -Top); PaintEventArgs pe = new PaintEventArgs(e.Graphics, translateRect); this.InvokePaintBackground(Parent, pe); this.InvokePaint(Parent, pe); //fixed bug#:796041, the forgound not need to display //this.InvokePaint(Parent, pe); e.Graphics.ResetTransform(); e.Graphics.EndContainer(g); pe.Dispose(); if (Parent is ISupportsTransparentChildRendering) { ((ISupportsTransparentChildRendering)Parent).TransparentChild = null; } #endif } ControlRenderer.FillRectAccordingToGradientStyle(e.Graphics, ClientRectangle, BackColor, LinkColor, 0, false, GradientColor, GradientStyle); ContentAlignment newTextAlign = ControlUtils.GetOrgContentAligment(RightToLeft, TextAlign); FontDescription font = new FontDescription(Font); ControlRenderer.PrintText(e.Graphics, ClientRectangle, LinkColor, font, Text, false, newTextAlign, Enabled, true, !UseMnemonic, false, (RightToLeft == RightToLeft.Yes)); //fixed bug #:765815 : when parking on hypertext button,focus need to seen on text on the button (not on entire button) if (Focused) { Size textExt = Utils.GetTextExt(Font, Text, this); // get the display the focus on the text of the control Rectangle textRect = ControlUtils.GetFocusRect(this, ClientRectangle, newTextAlign, textExt); //ass offset, it will look as in online textRect.Inflate(2, 2); textRect.Width -= 2; textRect.Height -= 1; textRect.X = Math.Max(1, textRect.X); textRect.Y = Math.Max(1, textRect.Y); textRect.Width = Math.Min(textRect.Width, ClientRectangle.Width - textRect.X); textRect.Height = Math.Min(textRect.Height, ClientRectangle.Height - textRect.Y); ControlPaint.DrawFocusRectangle(e.Graphics, textRect); } }
/// <summary> /// Draw the text supporting clipping according to ClipRegion. /// </summary> /// <param name="g"></param> /// <param name="color"></param> /// <param name="rect"></param> /// <param name="topOffset"></param> /// <param name="orientation"></param> /// <param name="fontDescription"></param> /// <param name="text"></param> /// <param name="contentAlignment"></param> /// <param name="flags"></param> public static void ClipSupportingDrawText(Graphics g, Color color, Rectangle rect, int topOffset, int orientation, FontDescription fontDescription, String text, ContentAlignment contentAlignment, int flags, bool rightToLeft) { IntPtr region = IntPtr.Zero; IntPtr currentclippedRegion = g.Clip.GetHrgn(g); bool IsRegionInfinite = g.Clip.IsInfinite(g); IntPtr hdc = g.GetHdc(); NativeWindowCommon.SetBkMode(hdc, NativeWindowCommon.TRANSPARENT); NativeWindowCommon.SetTextColor(hdc, ColorTranslator.ToWin32(color)); // Text rectangle as clip Region IntPtr clipRegion = NativeWindowCommon.CreateRectRgn(rect.Left, rect.Top, rect.Right, rect.Bottom); // If Text starts above control, it needs to clip if (topOffset < 0) { // if current graphics is already clipped, then we need to merge with current text rectangle clip if (!IsRegionInfinite) { NativeWindowCommon.CombineRgn(currentclippedRegion, currentclippedRegion, clipRegion, NativeWindowCommon.RGN_AND); } } if (IsRegionInfinite) { // If there is no clip region on graphics, set text rectangle as clip region region = clipRegion; } else if (currentclippedRegion != IntPtr.Zero) { // use intersected region as clip region region = currentclippedRegion; } // Select resultant clipped region on DC if (region != IntPtr.Zero) { NativeWindowCommon.SelectClipRgn(hdc, region); } if (clipRegion != IntPtr.Zero) { NativeWindowCommon.DeleteObject(clipRegion); } // Draw text DrawText(hdc, color, rect, topOffset, orientation, fontDescription, text, contentAlignment, flags, rightToLeft); // release objects g.ReleaseHdc(hdc); if (currentclippedRegion != IntPtr.Zero) { g.Clip.ReleaseHrgn(currentclippedRegion); } }
/// <summary> /// translate ContentAlignment to TextFlags /// </summary> /// <param name="contentAlignment"></param> /// <returns></returns> public static TextFormatFlags ContentAlignment2TextFlags(ContentAlignment contentAlignment) { TextFormatFlags tff = 0; switch (contentAlignment) { case ContentAlignment.BottomCenter: tff |= TextFormatFlags.HorizontalCenter | TextFormatFlags.Bottom; break; case ContentAlignment.MiddleCenter: tff |= TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter; break; case ContentAlignment.TopCenter: tff |= TextFormatFlags.HorizontalCenter | TextFormatFlags.Top; break; case ContentAlignment.BottomLeft: tff |= TextFormatFlags.Left | TextFormatFlags.Bottom;; break; case ContentAlignment.MiddleLeft: tff |= TextFormatFlags.Left | TextFormatFlags.VerticalCenter;; break; case ContentAlignment.TopLeft: tff |= TextFormatFlags.Left | TextFormatFlags.Top; break; case ContentAlignment.BottomRight: tff |= TextFormatFlags.Right | TextFormatFlags.Bottom;; break; case ContentAlignment.MiddleRight: tff |= TextFormatFlags.Right | TextFormatFlags.VerticalCenter;; break; case ContentAlignment.TopRight: tff |= TextFormatFlags.Right | TextFormatFlags.Top; break; default: break; } return(tff); }
/// <summary></summary> /// <param name="contentAlignment"></param> /// <param name="wordWrap"></param> /// <param name="MultiLine"></param> /// <returns></returns> public static TextFormatFlags GetTextFlags(ContentAlignment contentAlignment, bool wordWrap, bool multiLine, bool addNoPrefixFlag, bool addNoClipping, bool rightToLeft) { TextFormatFlags textFormatFlags = new TextFormatFlags(); textFormatFlags |= TextFormatFlags.NoPadding; if (addNoPrefixFlag) { textFormatFlags |= TextFormatFlags.NoPrefix; } textFormatFlags |= controls.utils.Utils.ContentAlignment2TextFlags(contentAlignment); if (wordWrap) { textFormatFlags |= TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl; } if (!multiLine) { textFormatFlags |= TextFormatFlags.SingleLine; } if (addNoClipping) { textFormatFlags |= TextFormatFlags.NoClipping; } if (rightToLeft) { textFormatFlags |= TextFormatFlags.RightToLeft; } textFormatFlags |= TextFormatFlags.ExpandTabs; return(textFormatFlags); }
/// <summary> /// static method for printing text /// </summary> /// <param name="g"></param> /// <param name="rect"></param> /// <param name="color"></param> /// <param name="fontDescription"></param> /// <param name="text"></param> /// <param name="MultiLine"></param> /// <param name="contentAlignment"></param> /// <param name="enabled"></param> /// <param name="wordWrap"></param> /// <param name="AddNoPrefixFlag"></param> /// <param name="AddNoClipping"></param> /// <param name="rightToLeft"></param> public static void PrintText(Graphics g, Rectangle rect, Color color, FontDescription fontDescription, String text, bool multiLine, ContentAlignment contentAlignment, bool enabled, bool wordWrap, bool addNoPrefixFlag, bool addNoClipping, bool rightToLeft, bool calcVerticalAligmentInMultiLine, int orientation, bool clipSupport) { if (!String.IsNullOrEmpty(text)) { int topOffset, flags; GetTextInformation(g, ref rect, ref color, fontDescription, text, multiLine, contentAlignment, enabled, wordWrap, addNoPrefixFlag, addNoClipping, rightToLeft, calcVerticalAligmentInMultiLine, out topOffset, out flags); #if !PocketPC if (clipSupport) { ClipSupportingDrawText(g, color, rect, topOffset, orientation, fontDescription, text, contentAlignment, flags, rightToLeft); } else #endif { IntPtr hdc = g.GetHdc(); DrawText(hdc, color, rect, topOffset, orientation, fontDescription, text, contentAlignment, flags, rightToLeft); g.ReleaseHdc(hdc); } } }
/// <summary> /// Calculate top offset for text information /// </summary> /// <param name="g"></param> /// <param name="rect"></param> /// <param name="fontDescription"></param> /// <param name="text"></param> /// <param name="multiLine"></param> /// <param name="contentAlignment"></param> /// <param name="calcVerticalAligmentInMultiLine"></param> /// <param name="flags"></param> /// <returns></returns> private static int CalcTopOffset(Graphics g, ref Rectangle rect, FontDescription fontDescription, string text, bool multiLine, ContentAlignment contentAlignment, bool calcVerticalAligmentInMultiLine, int flags) { int topOffset = 0; if (calcVerticalAligmentInMultiLine && multiLine && (contentAlignment == ContentAlignment.BottomCenter || contentAlignment == ContentAlignment.BottomLeft || contentAlignment == ContentAlignment.BottomRight || contentAlignment == ContentAlignment.MiddleCenter || contentAlignment == ContentAlignment.MiddleLeft || contentAlignment == ContentAlignment.MiddleRight)) { NativeWindowCommon.RECT retCalcTextRect; Utils.CalcTextRect(g, rect, fontDescription, text, flags, out retCalcTextRect); if (contentAlignment == ContentAlignment.BottomCenter || contentAlignment == ContentAlignment.BottomLeft || contentAlignment == ContentAlignment.BottomRight) { topOffset = rect.Bottom - (retCalcTextRect.bottom - retCalcTextRect.top); } else { topOffset = rect.Height - (((rect.Bottom - rect.Top) / 2) + ((retCalcTextRect.bottom - retCalcTextRect.top) / 2)); } } return(topOffset); }
/// <summary> /// Calculate flags for text information /// </summary> /// <param name="g"></param> /// <param name="rect"></param> /// <param name="color"></param> /// <param name="multiLine"></param> /// <param name="contentAlignment"></param> /// <param name="enabled"></param> /// <param name="wordWrap"></param> /// <param name="addNoPrefixFlag"></param> /// <param name="addNoClipping"></param> /// <param name="rightToLeft"></param> /// <returns></returns> private static int CalcFlags(Graphics g, ref Rectangle rect, ref Color color, bool multiLine, ContentAlignment contentAlignment, bool enabled, bool wordWrap, bool addNoPrefixFlag, bool addNoClipping, bool rightToLeft) { int flags = 0; flags = (int)Utils.GetTextFlags(contentAlignment, wordWrap, multiLine, addNoPrefixFlag, addNoClipping, rightToLeft); #if !PocketPC color = Utils.GetNearestColor(g, (enabled ? color : SystemColors.GrayText)); rect.Offset(new Point((int)g.Transform.OffsetX, (int)g.Transform.OffsetY)); #else color = enabled ? color : SystemColors.GrayText; #endif return(flags); }
/// <summary> /// /// </summary> /// <param name="g"></param> /// <param name="rect"></param> /// <param name="color"></param> /// <param name="fontDescription"></param> /// <param name="text"></param> /// <param name="multiLine"></param> /// <param name="contentAlignment"></param> /// <param name="enabled"></param> /// <param name="wordWrap"></param> /// <param name="addNoPrefixFlag"></param> /// <param name="addNoClipping"></param> /// <param name="rightToLeft"></param> /// <param name="calcVerticalAligmentInMultiLine"></param> public static void PrintText(Graphics g, Rectangle rect, Color color, FontDescription fontDescription, String text, bool multiLine, ContentAlignment contentAlignment, bool enabled, bool wordWrap, bool addNoPrefixFlag, bool addNoClipping, bool rightToLeft, bool calcVerticalAligmentInMultiLine) { PrintText(g, rect, color, fontDescription, text, multiLine, contentAlignment, enabled, wordWrap, addNoPrefixFlag, addNoClipping, rightToLeft, calcVerticalAligmentInMultiLine, 0, false); }
/// <summary> /// /// </summary> /// <param name="hdc"></param> /// <param name="fontDescription"></param> /// <param name="orientation"></param> /// <param name="text"></param> /// <param name="rectangle"></param> /// <param name="contentAlignment"></param> /// <param name="rect"></param> internal static void PrintRotatedText(IntPtr hdc, FontDescription fontDescription, int orientation, string text, Rectangle rectangle, ContentAlignment contentAlignment, NativeWindowCommon.RECT rect, bool rightToLeft) { IntPtr hFont; Point point; // get the original font and its LOGFONT NativeWindowCommon.LOGFONT logfont = fontDescription.LogFont; // Set the rotation angle logfont.lfEscapement = logfont.lfOrientation = orientation; // create the new, rotated font hFont = NativeWindowCommon.CreateFontIndirect(logfont); NativeWindowCommon.SelectObject(hdc, hFont); point = CalculateStartCoordinates(hdc, rectangle, orientation, text, contentAlignment); uint fuOptions = NativeWindowCommon.ETO_CLIPPED; if (rightToLeft) { fuOptions = NativeWindowCommon.ETO_RTLREADING; } NativeWindowCommon.ExtTextOut(hdc, point.X, point.Y, fuOptions, ref rect, text, (uint)text.Length, null); NativeWindowCommon.DeleteObject(hFont); }
/// <summary> /// code from gui_dc_calc_start_point /// </summary> /// <param name="hdc"></param> /// <param name="rectangle"></param> /// <param name="orientation"></param> /// <param name="str"></param> /// <param name="contentAlignment"></param> /// <returns></returns> public static Point CalculateStartCoordinates(IntPtr hdc, Rectangle rectangle, long orientation, string str, ContentAlignment contentAlignment) { int txt; Point Start = new Point(); HorizontalAlignment horizontalAlignment = Utils.ContentAlignment2HorizontalAlignment(contentAlignment); VerticalAlignment verticalAlignment = Utils.ContentAlignment2VerticalAlignment(contentAlignment); NativeWindowCommon.SIZE size = new NativeWindowCommon.SIZE(); NativeWindowCommon.GetTextExtentPoint32(hdc, str, str.Length, out size); switch (orientation) { case 450: txt = (int)Math.Sqrt((double)size.cx * size.cx / 2); if (verticalAlignment == VerticalAlignment.Bottom) { Start.Y = rectangle.Bottom - size.cy / 2; } else if (verticalAlignment == VerticalAlignment.Center) { Start.Y = rectangle.Top + ((rectangle.Bottom - rectangle.Top - size.cy / 2 + txt) / 2); } else { Start.Y = rectangle.Top + txt; } if (horizontalAlignment == HorizontalAlignment.Right) { Start.X = rectangle.Right - txt - size.cy / 2; } else if (horizontalAlignment == HorizontalAlignment.Center) { Start.X = rectangle.Left + ((rectangle.Right - rectangle.Left - size.cy / 2 - txt) / 2); } else { Start.X = rectangle.Left; } break; case 900: if (verticalAlignment == VerticalAlignment.Bottom) { Start.Y = rectangle.Bottom; } else if (verticalAlignment == VerticalAlignment.Center) { Start.Y = rectangle.Top + ((rectangle.Bottom - rectangle.Top + size.cx) / 2); } else { Start.Y = rectangle.Top + size.cx; } if (horizontalAlignment == HorizontalAlignment.Right) { Start.X = rectangle.Right - size.cy; } else if (horizontalAlignment == HorizontalAlignment.Center) { Start.X = rectangle.Left + ((rectangle.Right - rectangle.Left - size.cy) / 2); } else { Start.X = rectangle.Left; } break; case 1350: txt = (int)Math.Sqrt((double)size.cx * size.cx / 2); if (verticalAlignment == VerticalAlignment.Bottom) { Start.Y = rectangle.Bottom; } else if (verticalAlignment == VerticalAlignment.Center) { Start.Y = rectangle.Top + ((rectangle.Bottom - rectangle.Top + size.cy / 2 + txt) / 2); } else { Start.Y = rectangle.Top + txt + size.cy / 2; } if (horizontalAlignment == HorizontalAlignment.Right) { Start.X = rectangle.Right - size.cy / 2; } else if (horizontalAlignment == HorizontalAlignment.Center) { Start.X = rectangle.Left + ((rectangle.Right - rectangle.Left - size.cy / 2 + txt) / 2); } else { Start.X = rectangle.Left + txt; } break; case 1800: if (verticalAlignment == VerticalAlignment.Bottom) { Start.Y = rectangle.Bottom; } else if (verticalAlignment == VerticalAlignment.Center) { Start.Y = rectangle.Top + ((rectangle.Bottom - rectangle.Top + size.cy) / 2); } else { Start.Y = rectangle.Top + size.cy; } if (horizontalAlignment == HorizontalAlignment.Right) { Start.X = rectangle.Right; } else if (horizontalAlignment == HorizontalAlignment.Center) { Start.X = rectangle.Left + ((rectangle.Right - rectangle.Left + size.cx) / 2); } else { Start.X = rectangle.Left + size.cx; } break; case 2250: txt = (int)Math.Sqrt((double)size.cx * size.cx / 2); if (verticalAlignment == VerticalAlignment.Bottom) { Start.Y = rectangle.Bottom - txt; } else if (verticalAlignment == VerticalAlignment.Center) { Start.Y = rectangle.Top + ((rectangle.Bottom - rectangle.Top + size.cy / 2 - txt) / 2); } else { Start.Y = rectangle.Top + size.cy / 2; } if (horizontalAlignment == HorizontalAlignment.Right) { Start.X = rectangle.Right; } else if (horizontalAlignment == HorizontalAlignment.Center) { Start.X = rectangle.Left + ((rectangle.Right - rectangle.Left + size.cy / 2 + txt) / 2); } else { Start.X = rectangle.Left + txt + size.cy / 2; } break; case 2700: if (verticalAlignment == VerticalAlignment.Bottom) { Start.Y = rectangle.Bottom - size.cx; } else if (verticalAlignment == VerticalAlignment.Center) { Start.Y = rectangle.Top + ((rectangle.Bottom - rectangle.Top - size.cx) / 2); } else { Start.Y = rectangle.Top; } if (horizontalAlignment == HorizontalAlignment.Right) { Start.X = rectangle.Right; } else if (horizontalAlignment == HorizontalAlignment.Center) { Start.X = rectangle.Left + ((rectangle.Right - rectangle.Left + size.cy) / 2); } else { Start.X = rectangle.Left + size.cy; } break; case 3150: txt = (int)Math.Sqrt((double)size.cx * size.cx / 2); if (verticalAlignment == VerticalAlignment.Bottom) { Start.Y = rectangle.Bottom - txt - size.cy / 2; } else if (verticalAlignment == VerticalAlignment.Center) { Start.Y = rectangle.Top + ((rectangle.Bottom - rectangle.Top - size.cy / 2 - txt) / 2); } else { Start.Y = rectangle.Top; } if (horizontalAlignment == HorizontalAlignment.Right) { Start.X = rectangle.Right - txt; } else if (horizontalAlignment == HorizontalAlignment.Center) { Start.X = rectangle.Left + ((rectangle.Right - rectangle.Left + size.cy / 2 - txt) / 2); } else { Start.X = rectangle.Left + size.cy / 2; } break; default: break; } return(Start); }
/// <summary>paint the push button control /// Can be called from : /// 1. push control with property 'ButtonStyle' = button /// 2. CheckBox control with property appearance = button /// 3. Radio control with property appearance = button /// </summary> /// <param name="mgButton"></param> /// <param name="e"></param> private static void DrawText(Control control, PaintEventArgs e) { Debug.Assert(control.Visible); bool restoreClip = false; Region r = e.Graphics.Clip; bool isImage = false; ContentAlignment textAlign = ContentAlignment.MiddleLeft; RightToLeft rightToLeft = RightToLeft.No; String Text = ((IDisplayInfo)control).TextToDisplay; if (Text == null) { return; } Rectangle displayRect = control.ClientRectangle; #if PocketPC if (control is MgButtonBase) { isImage = ((MgButtonBase)control).BackgroundImage != null; textAlign = ((MgButtonBase)control).TextAlign; rightToLeft = ((MgButtonBase)control).RightToLeft; } else if (control is MgCheckBox) { isImage = ((MgCheckBox)control).Image != null; textAlign = ((MgCheckBox)control).TextAlign; rightToLeft = ((MgCheckBox)control).RightToLeft; } else { Debug.Assert(false); } #else if (control is ButtonBase) { if (control is IImageProperty) { isImage = ((IImageProperty)control).Image != null; } else { isImage = ((ButtonBase)control).BackgroundImage != null; } textAlign = ((ButtonBase)control).TextAlign; rightToLeft = ((ButtonBase)control).RightToLeft; } else { Debug.Assert(false); } #endif // The runtime engine sends the alignment in reverse order if rightToLeft=Yes. // This is because the .net framework need it to be in the reverse order when rightToLeft=Yes. // So, when we paint the control, we should convert it back to the original alignment. textAlign = ControlUtils.GetOrgContentAligment(rightToLeft, textAlign); if (!isImage) { //2. get the display rect displayRect = GetTextRect(control); if (control is MgPushButton) { restoreClip = true; using (Region TextRegion = new Region(displayRect)) { e.Graphics.Clip = TextRegion; } } } bool isMultiLine = ControlUtils.GetIsMultiLine(control); bool RTL = rightToLeft == RightToLeft.Yes ? true : false; //4. display the text of the control FontDescription font = new FontDescription(control.Font); ControlRenderer.PrintText(e.Graphics, displayRect, control.ForeColor, font, Text, isMultiLine, textAlign, control.Enabled, false, false, false, RTL, true); if (restoreClip) { e.Graphics.Clip = r; } //focus rect should not be drawn for image button. if (!ControlUtils.IsImageButton(control)) { if (control.Focused) { displayRect.Inflate(-1, -1); ControlPaint.DrawFocusRectangle(e.Graphics, displayRect); } } }