public static void Resize(this Image source, String newFilename, Size newSize, long quality, ContentAlignment contentAlignment, ThumbMode mode) { Image image = source.Resize(newSize, quality, contentAlignment, mode); using (EncoderParameters encoderParams = new EncoderParameters(1)) { using (EncoderParameter parameter = (encoderParams.Param[0] = new EncoderParameter(Encoder.Quality, quality))) { ImageCodecInfo encoder = null; //取得擴展名 string ext = Path.GetExtension(newFilename); if (string.IsNullOrEmpty(ext)) ext = ".jpg"; //根據擴展名得到解碼、編碼器 foreach (ImageCodecInfo codecInfo in ImageCodecInfo.GetImageEncoders()) { if (Regex.IsMatch(codecInfo.FilenameExtension, string.Format(@"(;|^)\*\{0}(;|$)", ext), RegexOptions.IgnoreCase)) { encoder = codecInfo; break; } } DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(newFilename)); if(dir.Exists == false) dir.Create(); image.Save(newFilename, encoder, encoderParams); } } }
public BaseTextItem():base() { this.dataType = "System.String"; this.stringFormat = StringFormat.GenericTypographic; this.contentAlignment = ContentAlignment.TopLeft; this.stringTrimming = StringTrimming.None; VisibleInReport = true; }
/// <summary> /// Creates an instance of Watermarker class. /// </summary> public ApplyWatermark () { Color = Color.Aquamarine; Font = new Font(FontFamily.GenericSansSerif, 16); WatermarkText = "(c) ESRI Inc."; TextAlignment = ContentAlignment.BottomLeft; }
public void DrawText(Point p, string font, int size, FontStyle fontStyle, Color fill, ContentAlignment alignment, object text) { Dictionary<ContentAlignment, XAttribute> alignmentTransform = new Dictionary<ContentAlignment, XAttribute> { { ContentAlignment.MiddleLeft, new XAttribute("text-anchor", "start")}, { ContentAlignment.MiddleCenter, new XAttribute("text-anchor", "middle")}, { ContentAlignment.MiddleRight, new XAttribute("text-anchor", "end")} }; Dictionary<FontStyle, XAttribute> fontWeightTransform = new Dictionary<FontStyle, XAttribute> { { FontStyle.Regular, new XAttribute("font-weight", "normal")}, { FontStyle.Bold, new XAttribute("font-weight", "bold")}, }; root.Add(new XElement(@namespace + "text", new XAttribute("x", p.X ), new XAttribute("y", p.Y ), new XAttribute("fill", ColorTranslator.ToHtml(fill)), new XAttribute("stroke", ColorTranslator.ToHtml(fill)), new XAttribute("font-size", size), new XAttribute("font-family", font), new XAttribute("stroke-width", 0), alignmentTransform[alignment], fontWeightTransform[fontStyle], text )); }
public static PointF GetContentPosition(ContentAlignment alignment, SizeF size, SizeF containerSize) { return new PointF( GetContentPositionX(alignment, size, containerSize), GetContentPositionY(alignment, size, containerSize) ); }
internal static LayoutOptions CommonLayout(Rectangle clientRectangle, Padding padding, bool isDefault, Font font, string text, bool enabled, ContentAlignment textAlign, RightToLeft rtl) { return new LayoutOptions { client = LayoutUtils.DeflateRect(clientRectangle, padding), padding = padding, growBorderBy1PxWhenDefault = true, isDefault = isDefault, borderSize = 2, paddingSize = 0, maxFocus = true, focusOddEvenFixup = false, font = font, text = text, imageSize = Size.Empty, checkSize = 0, checkPaddingSize = 0, checkAlign = ContentAlignment.TopLeft, imageAlign = ContentAlignment.MiddleCenter, textAlign = textAlign, hintTextUp = false, shadowedText = !enabled, layoutRTL = RightToLeft.Yes == rtl, textImageRelation = TextImageRelation.Overlay, useCompatibleTextRendering = false }; }
private TextFormatFlags TextAlignToFormatFlags(ContentAlignment align) { switch (align) { case ContentAlignment.MiddleCenter: return TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter; case ContentAlignment.BottomCenter: return TextFormatFlags.HorizontalCenter | TextFormatFlags.Bottom; case ContentAlignment.BottomLeft: return TextFormatFlags.Left | TextFormatFlags.Bottom; case ContentAlignment.BottomRight: return TextFormatFlags.Right | TextFormatFlags.Bottom; case ContentAlignment.MiddleLeft: return TextFormatFlags.VerticalCenter | TextFormatFlags.Left; case ContentAlignment.MiddleRight: return TextFormatFlags.VerticalCenter | TextFormatFlags.Right; case ContentAlignment.TopCenter: return TextFormatFlags.Top | TextFormatFlags.HorizontalCenter; case ContentAlignment.TopLeft: return TextFormatFlags.Top | TextFormatFlags.Left; case ContentAlignment.TopRight: return TextFormatFlags.Top | TextFormatFlags.Right; } return TextFormatFlags.HorizontalCenter | TextFormatFlags.Top; }
protected void reset() { _alignment = ContentAlignment.MiddleLeft; setColor(SystemColors.WindowText); setBackground(SystemColors.Window); setFont(SystemFonts.DefaultFont); }
private int DefaultBaselineOffset(ContentAlignment alignment, FlatStyle flatStyle) { if ((alignment & DesignerUtils.anyMiddleAlignment) != ((ContentAlignment) 0)) { return 0; } if ((flatStyle == FlatStyle.Standard) || (flatStyle == FlatStyle.Popup)) { if ((alignment & DesignerUtils.anyTopAlignment) == ((ContentAlignment) 0)) { return -4; } return 4; } if (flatStyle == FlatStyle.System) { if ((alignment & DesignerUtils.anyTopAlignment) == ((ContentAlignment) 0)) { return -3; } return 3; } if (flatStyle != FlatStyle.Flat) { return 0; } if ((alignment & DesignerUtils.anyTopAlignment) == ((ContentAlignment) 0)) { return -5; } return 5; }
/// <summary> /// 合并图像 /// </summary> /// <param name="imageBackground"></param> /// <param name="imageForeground"></param> /// <param name="alignment"></param> /// <returns></returns> public static Image CombineImage(Image imageBackground, Image imageForeground, ContentAlignment alignment) { Image imageBk = imageBackground.Clone() as Image; Graphics g = Graphics.FromImage(imageBk); Point point; switch (alignment) { case ContentAlignment.TopLeft: point = new Point(0, 0); break; case ContentAlignment.TopRight: point = new Point(imageBackground.Width - imageForeground.Width, 0); break; case ContentAlignment.BottomLeft: point = new Point(0, imageBackground.Height - imageForeground.Height); break; case ContentAlignment.BottomRight: point = new Point(imageBackground.Width - imageForeground.Width, imageBackground.Height - imageForeground.Height); break; case ContentAlignment.TopCenter: point = new Point(imageBackground.Width / 2 - imageForeground.Width / 2, 0); break; case ContentAlignment.BottomCenter: point = new Point(imageBackground.Width / 2 - imageForeground.Width / 2, imageBackground.Height - imageForeground.Height); break; default: throw new NotSupportedException("Not supported alignment"); } g.DrawImage(imageForeground, point); return imageBk; }
/// <summary> /// Initializes a new instance of the <see cref="Switcher"/> class. /// </summary> /// <param name="serviceProvider"><para>Requires:</para> /// <para><see cref="INuGenRadioButtonRenderer"/></para> /// <para><see cref="INuGenRadioButtonLayoutManager"/></para> /// <para><see cref="INuGenButtonStateService"/></para> /// <para><see cref="INuGenControlStateService"/></para> /// </param> /// <param name="associatedAlignment"></param> /// <exception cref="ArgumentNullException"><paramref name="serviceProvider"/> is <see langword="null"/>.</exception> public Switcher(INuGenServiceProvider serviceProvider, ContentAlignment associatedAlignment) : base(serviceProvider) { _assoicatedAlignment = associatedAlignment; this.CheckAlign = ContentAlignment.MiddleCenter; this.Dock = DockStyle.Fill; }
protected ButtonBase() : base() { flat_style = FlatStyle.Standard; flat_button_appearance = new FlatButtonAppearance (this); this.image_key = string.Empty; this.text_image_relation = TextImageRelation.Overlay; this.use_mnemonic = true; use_visual_style_back_color = true; image_index = -1; image = null; image_list = null; image_alignment = ContentAlignment.MiddleCenter; ImeMode = ImeMode.Disable; text_alignment = ContentAlignment.MiddleCenter; is_default = false; is_pressed = false; text_format = new StringFormat(); text_format.Alignment = StringAlignment.Center; text_format.LineAlignment = StringAlignment.Center; text_format.HotkeyPrefix = HotkeyPrefix.Show; text_format.FormatFlags |= StringFormatFlags.LineLimit; text_format_flags = TextFormatFlags.HorizontalCenter; text_format_flags |= TextFormatFlags.VerticalCenter; text_format_flags |= TextFormatFlags.TextBoxControl; SetStyle (ControlStyles.ResizeRedraw | ControlStyles.Opaque | ControlStyles.UserMouse | ControlStyles.SupportsTransparentBackColor | ControlStyles.CacheText | ControlStyles.OptimizedDoubleBuffer, true); SetStyle (ControlStyles.StandardClick, false); }
private byte[] GetSubImageBuffer(RunLengthTwoParts twoPartBuffer, NikseBitmap nbmp, Paragraph p, ContentAlignment alignment) { var ms = new MemoryStream(); // sup picture datasize WriteEndianWord(twoPartBuffer.Length + 34, ms); // first display control sequence table address int startDisplayControlSequenceTableAddress = twoPartBuffer.Length + 4; WriteEndianWord(startDisplayControlSequenceTableAddress, ms); // Write image const int imageTopFieldDataAddress = 4; ms.Write(twoPartBuffer.Buffer1, 0, twoPartBuffer.Buffer1.Length); int imageBottomFieldDataAddress = 4 + twoPartBuffer.Buffer1.Length; ms.Write(twoPartBuffer.Buffer2, 0, twoPartBuffer.Buffer2.Length); // Write zero delay ms.WriteByte(0); ms.WriteByte(0); // next display control sequence table address (use current is last) WriteEndianWord(startDisplayControlSequenceTableAddress + 24, ms); // start of display control sequence table address // Control command start if (p.Forced) ms.WriteByte(0); // ForcedStartDisplay==0 else ms.WriteByte(1); // StartDisplay==1 // Control command 3 = SetColor WriteColors(ms); // 3 bytes // Control command 4 = SetContrast WriteContrast(ms); // 3 bytes // Control command 5 = SetDisplayArea WriteDisplayArea(ms, nbmp, alignment); // 7 bytes // Control command 6 = SetPixelDataAddress WritePixelDataAddress(ms, imageTopFieldDataAddress, imageBottomFieldDataAddress); // 5 bytes // Control command exit ms.WriteByte(255); // 1 byte // Control Sequence Table // Write delay - subtitle duration WriteEndianWord(Convert.ToInt32(p.Duration.TotalMilliseconds * 90.0 - 1023) >> 10, ms); // next display control sequence table address (use current is last) WriteEndianWord(startDisplayControlSequenceTableAddress + 24, ms); // start of display control sequence table address // Control command 2 = StopDisplay ms.WriteByte(2); // extra byte - for compatability with gpac/MP4BOX ms.WriteByte(255); // 1 byte return ms.ToArray(); }
/// <summary> /// calculates the position of an element depending on the desired alignment within a RectangleF /// </summary> /// <param name="currentRect">the bounds of the element to be aligned</param> /// <param name="targetRect">the rectangle reference for aligment of the element</param> /// <param name="alignment">the System.Drawing.ContentAlignment value indicating how the element is to be aligned should the width or height differ from targetSize</param> /// <returns>a new RectangleF object with Location aligned aligned to targetRect</returns> public static RectangleF GetAlignedRectangle(RectangleF currentRect, RectangleF targetRect, ContentAlignment alignment) { RectangleF newRect = new RectangleF(targetRect.Location, currentRect.Size); switch(alignment) { case ContentAlignment.TopCenter: newRect.X = (targetRect.Width - currentRect.Width) / 2; break; case ContentAlignment.TopRight: newRect.X = (targetRect.Width - currentRect.Width); break; case ContentAlignment.MiddleLeft: newRect.Y = (targetRect.Height - currentRect.Height) / 2; break; case ContentAlignment.MiddleCenter: newRect.Y = (targetRect.Height - currentRect.Height) / 2; newRect.X = (targetRect.Width - currentRect.Width) / 2; break; case ContentAlignment.MiddleRight: newRect.Y = (targetRect.Height - currentRect.Height) / 2; newRect.X = (targetRect.Width - currentRect.Width); break; case ContentAlignment.BottomLeft: newRect.Y = (targetRect.Height - currentRect.Height); break; case ContentAlignment.BottomCenter: newRect.Y = (targetRect.Height - currentRect.Height); newRect.X = (targetRect.Width - currentRect.Width) / 2; break; case ContentAlignment.BottomRight: newRect.Y = (targetRect.Height - currentRect.Height); newRect.X = (targetRect.Width - currentRect.Width); break; } return newRect; }
public NotificationForm(int duration, ContentAlignment placement, Size size, NotificationFormConfig config) { InitializeComponent(); ToastConfig = config; textFont = new Font("Arial", 10); if (config.Image != null) { config.Image = ImageHelpers.ResizeImageLimit(config.Image, size); config.Image = ImageHelpers.DrawCheckers(config.Image); size = new Size(config.Image.Width + 2, config.Image.Height + 2); } else if (!string.IsNullOrEmpty(config.Text)) { textRenderSize = Helpers.MeasureText(config.Text, textFont, size.Width - textPadding * 2); size = new Size(textRenderSize.Width + textPadding * 2, textRenderSize.Height + textPadding * 2 + 2); } SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); Size = size; Point position = Helpers.GetPosition(placement, new Point(windowOffset, windowOffset), Screen.PrimaryScreen.WorkingArea.Size, Size); Location = new Point(Screen.PrimaryScreen.WorkingArea.X + position.X, Screen.PrimaryScreen.WorkingArea.Y + position.Y); tDuration.Interval = duration; tDuration.Start(); }
public NotificationForm(int duration, ContentAlignment placement, Size size, NotificationFormConfig config) { InitializeComponent(); SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); ToastConfig = config; textFont = new Font("Arial", 10); if (config.Image != null) { config.Image = ImageHelpers.ResizeImageLimit(config.Image, size); config.Image = ImageHelpers.DrawCheckers(config.Image); size = new Size(config.Image.Width + 2, config.Image.Height + 2); } else if (!string.IsNullOrEmpty(config.Text)) { textRenderSize = Helpers.MeasureText(config.Text, textFont, size.Width - textPadding * 2); size = new Size(textRenderSize.Width + textPadding * 2, textRenderSize.Height + textPadding * 2 + 2); } Point position = Helpers.GetPosition(placement, new Point(windowOffset, windowOffset), Screen.PrimaryScreen.WorkingArea.Size, size); NativeMethods.SetWindowPos(Handle, (IntPtr)SpecialWindowHandles.HWND_TOPMOST, position.X + Screen.PrimaryScreen.WorkingArea.X, position.Y + Screen.PrimaryScreen.WorkingArea.Y, size.Width, size.Height, SetWindowPosFlags.SWP_NOACTIVATE); if (duration <= 0) { DurationEnd(); } else { tDuration.Interval = duration; tDuration.Start(); } }
public TextFormatting(TextFormatting aCopy) { m_alignment = aCopy.m_alignment; m_foreColor = aCopy.m_foreColor; m_backColor = aCopy.m_backColor; m_padding = aCopy.m_padding; }
/// <summary> /// 图片水印处理方法 /// </summary> /// <param name="path">需要加载水印的图片路径(绝对路径)</param> /// <param name="waterpath">水印图片(绝对路径)</param> /// <param name="align">水印位置(传送正确的代码)</param> public static string ImageWatermark(string path, string waterpath, ContentAlignment align) { string kz_name = Path.GetExtension(path); if (kz_name == ".jpg" || kz_name == ".bmp" || kz_name == ".jpeg") { DateTime time = DateTime.Now; string filename = "" + time.Year.ToString() + time.Month.ToString() + time.Day.ToString() + time.Hour.ToString() + time.Minute.ToString() + time.Second.ToString() + time.Millisecond.ToString(); Image img = Bitmap.FromFile(path); Image waterimg = Image.FromFile(waterpath); Graphics g = Graphics.FromImage(img); ArrayList loca = GetLocation(align, img, waterimg); g.DrawImage(waterimg, new Rectangle(int.Parse(loca[0].ToString()), int.Parse(loca[1].ToString()), waterimg.Width, waterimg.Height)); waterimg.Dispose(); g.Dispose(); string newpath = Path.GetDirectoryName(path) + filename + kz_name; img.Save(newpath); img.Dispose(); File.Copy(newpath, path, true); if (File.Exists(newpath)) { File.Delete(newpath); } } return path; }
public Separator() { SetStyle(ControlStyles.ResizeRedraw, true); m_orientation = Orientation.Horizontal; m_alignment = ContentAlignment.MiddleCenter; OnResize(EventArgs.Empty); }
public BaseTextItem(){ DefaultSize = GlobalValues.PreferedSize; Size = GlobalValues.PreferedSize; BackColor = Color.White; contentAlignment = ContentAlignment.TopLeft; TypeDescriptor.AddProvider(new TextItemTypeProvider(), typeof(BaseTextItem)); }
public static StringAlignments FromContentAlignment(ContentAlignment ca) { Int32 lNum = (Int32)Math.Log((Double)ca, 2); StringAlignments sa = new StringAlignments(); sa.LineAlignment = (StringAlignment)(lNum / 4); sa.Alignment = (StringAlignment)(lNum % 4); return sa; }
public DataPanelViewGroupRowControl(string title, int rowCount, bool isShowGroupTotal, ContentAlignment textAlign, int left) : this() { this.isShowGroupTotal = isShowGroupTotal; SetTitle(title, rowCount); lblTitle.Padding = new Padding(left, 0 ,0 ,0); lblTitle.TextAlign = textAlign; }
// Contructor. public CheckBox() { Appearance = Appearance.Normal; checkAlign = ContentAlignment.MiddleLeft; TextAlign = ContentAlignment.MiddleLeft; autoCheck = true; SetStyle(ControlStyles.StandardClick | ControlStyles.StandardDoubleClick, false); }
public StaticLabel() { _clientRect = new Rectangle(0, 0, _defaultWidth, _defaultHeight); ResizeMode = ResizeMode.Both; _name = "StaticLabel"; _text = "Label"; _font = null; _alignment = ContentAlignment.MiddleLeft; }
public static int ContentAlignmentToIndex(ContentAlignment alignment) { int num = xContentAlignmentToIndex(((int) alignment) & 15); int num2 = xContentAlignmentToIndex((((int) alignment) >> 4) & 15); int num3 = xContentAlignmentToIndex((((int) alignment) >> 8) & 15); int num4 = (((((num2 != 0) ? 4 : 0) | ((num3 != 0) ? 8 : 0)) | num) | num2) | num3; num4--; return num4; }
public static DropForm GetInstance(int size, int offset, ContentAlignment alignment, int opacity, int hoverOpacity) { if (instance == null || instance.IsDisposed) { instance = new DropForm(size, offset, alignment, opacity, hoverOpacity); } return instance; }
/// <summary> /// Creates a new instance of LabelAlignmentControl /// </summary> public LabelAlignmentPicker() { _value = ContentAlignment.MiddleCenter; _padding = 5; _buttons = new Dictionary<ContentAlignment, LabelAlignmentButton>(); _exitTimer = new Timer(); _exitTimer.Interval = 100; _exitTimer.Tick += ExitTimerTick; }
/// <summary> /// Adjust image drawing area for both aspect ratio and content alignment /// </summary> /// <param name="ImageWidthPix">Image width in pixels.</param> /// <param name="ImageHeightPix">Image height in pixels.</param> /// <param name="DrawArea">Drawing area rectangle</param> /// <param name="Alignment">Content alignment.</param> /// <returns>Adjusted drawing area rectangle</returns> public static PdfRectangle ImageArea( Int32 ImageWidthPix, Int32 ImageHeightPix, PdfRectangle DrawArea, ContentAlignment Alignment ) { return(ImageArea(ImageWidthPix, ImageHeightPix, DrawArea.Left, DrawArea.Bottom, DrawArea.Width, DrawArea.Height, Alignment)); }
public LabelSettings(IBrushSettings background, IPenSettings borderPen, IFontSettings font, IBrushSettings fontBrush, ContentAlignment contentAlignment) { Background = background; BorderPen = borderPen; Font = font; FontBrush = fontBrush; ContentAlignment = contentAlignment; }
public static void Add(Control parent, Label content, string text, Point position, Size size, ContentAlignment alignment) { content.Text = text; content.Location = position; content.Size = size; content.TextAlign = alignment; parent.Controls.Add(content); }
//******************************************************************************************* /// <summary> /// /// </summary> /// <param name="align"></param> /// <param name="img"></param> /// <param name="rc"></param> /// <returns></returns> //******************************************************************************************* public static Point ConAlignToImgPosition(ContentAlignment align, Image img, Rectangle rc) { return(ConAlignToImgPosition(align, img, rc, 0)); }
// Draw some text along a line segment. // Leave char_num pointing to the next character to be drawn. // Leave start_point holding the last point used. private void DrawTextOnSegment(Graphics gr, Brush brush, Font font, string txt, ref int first_ch, ref PointF start_point, PointF end_point, ContentAlignment alignment, GraphicsPath resultPath = null) { var kp = new PointF[] { new PointF(1f, 1f) }; gr.Transform.TransformPoints(kp); var dx = end_point.X - start_point.X; var dy = end_point.Y - start_point.Y; var dist = (float)Math.Sqrt(dx * dx + dy * dy); dist /= kp[0].X; // компенсанция выравнивания текста по линии от масштабирования канвы dx /= dist; dy /= dist; // See how many characters will fit. int last_ch = first_ch; while (last_ch < txt.Length) { var test_string = txt.Substring(first_ch, last_ch - first_ch + 1); if (gr.MeasureString(test_string, font).Width > dist) { // This is one too many characters. last_ch--; break; } last_ch++; } if (last_ch < first_ch) { return; } if (last_ch >= txt.Length) { last_ch = txt.Length - 1; } var chars_that_fit = txt.Substring(first_ch, last_ch - first_ch + 1); var hy = 0f; if (alignment == ContentAlignment.MiddleLeft || alignment == ContentAlignment.MiddleCenter || alignment == ContentAlignment.MiddleRight) { hy = -gr.MeasureString(chars_that_fit, font).Height / 2; } else if (alignment == ContentAlignment.TopLeft || alignment == ContentAlignment.TopCenter || alignment == ContentAlignment.TopRight) { hy = -gr.MeasureString(chars_that_fit, font).Height; } hy *= kp[0].Y; // компенсанция выравнивания текста по линии от масштабирования канвы var angle = (float)(180 * Math.Atan2(dy, dx) / Math.PI); if (resultPath != null) { using (var path = new GraphicsPath()) { using (var m = new Matrix()) { m.Translate(0, hy); m.Rotate(angle, MatrixOrder.Append); m.Translate(start_point.X, start_point.Y, MatrixOrder.Append); path.AddString(chars_that_fit, font.FontFamily, (int)font.Style, font.Size, Point.Empty, null); var pts = path.PathPoints; m.TransformPoints(pts); using (var transpath = new GraphicsPath(pts, path.PathTypes)) resultPath.AddPath(transpath, false); } } } else { // Rotate and translate to position the characters. GraphicsState state = gr.Save(); gr.TranslateTransform(0, hy, MatrixOrder.Append); gr.RotateTransform(angle, MatrixOrder.Append); gr.TranslateTransform(start_point.X, start_point.Y, MatrixOrder.Append); // Draw the characters that fit. gr.DrawString(chars_that_fit, font, brush, 0, 0); // Restore the saved state. gr.Restore(state); } // Update first_ch and start_point. first_ch = last_ch + 1; // временно подменим пробелы на подчёркивания, для корректного измерения длины var text_width = gr.MeasureString(chars_that_fit.Replace(' ', '_'), font).Width; start_point = new PointF( start_point.X + dx * text_width, start_point.Y + dy * text_width); }
public void RelativeAlign(Control control, ContentAlignment alignment, int distance) { var baseBounds = control.RectangleToScreen(control.DisplayRectangle); var screenBounds = SystemInformation.VirtualScreen; var thisBounds = DisplayRectangle; switch (alignment) { case ContentAlignment.TopLeft: case ContentAlignment.TopCenter: case ContentAlignment.TopRight: Top = baseBounds.Top - distance - thisBounds.Height; break; case ContentAlignment.MiddleLeft: case ContentAlignment.MiddleCenter: case ContentAlignment.MiddleRight: Top = baseBounds.Top + baseBounds.Height / 2 - thisBounds.Height / 2; break; case ContentAlignment.BottomLeft: case ContentAlignment.BottomCenter: case ContentAlignment.BottomRight: Top = baseBounds.Bottom + distance; break; } switch (alignment) { case ContentAlignment.TopLeft: case ContentAlignment.MiddleLeft: case ContentAlignment.BottomLeft: Left = baseBounds.Left - distance - thisBounds.Width; break; case ContentAlignment.TopCenter: case ContentAlignment.MiddleCenter: case ContentAlignment.BottomCenter: Left = baseBounds.Left + baseBounds.Width / 2 - thisBounds.Width / 2; break; case ContentAlignment.TopRight: case ContentAlignment.MiddleRight: case ContentAlignment.BottomRight: Left = baseBounds.Right + distance; break; } if (Left < 0) { Left = 0; } if (Right > screenBounds.Width) { Left = screenBounds.Width - Width; } if (Top < 0) { Top = 0; } if (Bottom > screenBounds.Height) { Top = screenBounds.Height - Height; } }
public static StringFormat BuildStringFormat(StringTrimming stringTrimming, ContentAlignment alignment) { StringFormat format = StringFormat.GenericTypographic; format.Trimming = stringTrimming; format.FormatFlags = StringFormatFlags.LineLimit; if (alignment <= ContentAlignment.MiddleCenter) { switch (alignment) { case ContentAlignment.TopLeft: { format.Alignment = StringAlignment.Near; format.LineAlignment = StringAlignment.Near; return(format); } case ContentAlignment.TopCenter: { format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Near; return(format); } case (ContentAlignment.TopCenter | ContentAlignment.TopLeft): { return(format); } case ContentAlignment.TopRight: { format.Alignment = StringAlignment.Far; format.LineAlignment = StringAlignment.Near; return(format); } case ContentAlignment.MiddleLeft: { format.Alignment = StringAlignment.Near; format.LineAlignment = StringAlignment.Center; return(format); } case ContentAlignment.MiddleCenter: { format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Center; return(format); } } return(format); } if (alignment <= ContentAlignment.BottomLeft) { if (alignment == ContentAlignment.MiddleRight) { format.Alignment = StringAlignment.Far; format.LineAlignment = StringAlignment.Center; return(format); } if (alignment != ContentAlignment.BottomLeft) { return(format); } } else { if (alignment != ContentAlignment.BottomCenter) { if (alignment == ContentAlignment.BottomRight) { format.Alignment = StringAlignment.Far; format.LineAlignment = StringAlignment.Far; } return(format); } format.Alignment = StringAlignment.Center; format.LineAlignment = StringAlignment.Far; return(format); } format.Alignment = StringAlignment.Near; format.LineAlignment = StringAlignment.Far; return(format); }
void DrawImageForPrint(object sender, PrintPageEventArgs e) { // Create the output settins SurfaceOutputSettings printOutputSettings = new SurfaceOutputSettings(OutputFormat.png, 100, false); ApplyEffects(printOutputSettings); Image image; bool disposeImage = ImageOutput.CreateImageFromSurface(surface, printOutputSettings, out image); try { ContentAlignment alignment = conf.OutputPrintCenter ? ContentAlignment.MiddleCenter : ContentAlignment.TopLeft; // prepare timestamp float footerStringWidth = 0; float footerStringHeight = 0; string footerString = null; //DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString(); if (conf.OutputPrintFooter) { footerString = FilenameHelper.FillPattern(conf.OutputPrintFooterPattern, captureDetails, false); using (Font f = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular)) { footerStringWidth = e.Graphics.MeasureString(footerString, f).Width; footerStringHeight = e.Graphics.MeasureString(footerString, f).Height; } } // Get a rectangle representing the printable Area RectangleF pageRect = e.PageSettings.PrintableArea; if (e.PageSettings.Landscape) { float origWidth = pageRect.Width; pageRect.Width = pageRect.Height; pageRect.Height = origWidth; } // Subtract the dateString height from the available area, this way the area stays free pageRect.Height -= footerStringHeight; GraphicsUnit gu = GraphicsUnit.Pixel; RectangleF imageRect = image.GetBounds(ref gu); // rotate the image if it fits the page better if (conf.OutputPrintAllowRotate) { if ((pageRect.Width > pageRect.Height && imageRect.Width < imageRect.Height) || (pageRect.Width < pageRect.Height && imageRect.Width > imageRect.Height)) { image.RotateFlip(RotateFlipType.Rotate90FlipNone); imageRect = image.GetBounds(ref gu); if (alignment.Equals(ContentAlignment.TopLeft)) { alignment = ContentAlignment.TopRight; } } } RectangleF printRect = new RectangleF(0, 0, imageRect.Width, imageRect.Height); // scale the image to fit the page better if (conf.OutputPrintAllowEnlarge || conf.OutputPrintAllowShrink) { SizeF resizedRect = ScaleHelper.GetScaledSize(imageRect.Size, pageRect.Size, false); if ((conf.OutputPrintAllowShrink && resizedRect.Width < printRect.Width) || conf.OutputPrintAllowEnlarge && resizedRect.Width > printRect.Width) { printRect.Size = resizedRect; } } // align the image printRect = ScaleHelper.GetAlignedRectangle(printRect, new RectangleF(0, 0, pageRect.Width, pageRect.Height), alignment); if (conf.OutputPrintFooter) { //printRect = new RectangleF(0, 0, printRect.Width, printRect.Height - (dateStringHeight * 2)); using (Font f = new Font(FontFamily.GenericSansSerif, 10, FontStyle.Regular)) { e.Graphics.DrawString(footerString, f, Brushes.Black, pageRect.Width / 2 - (footerStringWidth / 2), pageRect.Height); } } e.Graphics.DrawImage(image, printRect, imageRect, GraphicsUnit.Pixel); } finally { if (disposeImage && image != null) { image.Dispose(); image = null; } } }
public void DrawString(string text, Font font, Color color, float x, float y, float width, float height, ContentAlignment align, object material = null) { if (text == null || font == null) { return; } if (UE.Event.current.type != UE.EventType.repaint) { return; } // TODO: material not supported. // Set align. var uAlign = UE.TextAnchor.UpperLeft; switch (align) { case ContentAlignment.BottomCenter: uAlign = UE.TextAnchor.LowerCenter; break; case ContentAlignment.BottomLeft: uAlign = UE.TextAnchor.LowerLeft; break; case ContentAlignment.BottomRight: uAlign = UE.TextAnchor.LowerRight; break; case ContentAlignment.MiddleCenter: uAlign = UE.TextAnchor.MiddleCenter; break; case ContentAlignment.MiddleLeft: uAlign = UE.TextAnchor.MiddleLeft; break; case ContentAlignment.MiddleRight: uAlign = UE.TextAnchor.MiddleRight; break; case ContentAlignment.TopCenter: uAlign = UE.TextAnchor.UpperCenter; break; case ContentAlignment.TopLeft: uAlign = UE.TextAnchor.UpperLeft; break; case ContentAlignment.TopRight: uAlign = UE.TextAnchor.UpperRight; break; } var labelSkin = UE.GUI.skin.label; int guiSkinFontSizeBuffer = GUI_SetFont(labelSkin, font); UE.GUI.color = color.ToUnityColor(); labelSkin.alignment = uAlign; textContent.text = text; // It's faster to invoke less methods and use your own GUIContent. Not that much, but anyway. UE.GUI.Label(new UE.Rect(x, y, width, height), textContent, labelSkin); labelSkin.fontSize = guiSkinFontSizeBuffer; }
public static bool IsVerticalAlignment(ContentAlignment align) { Debug.Assert(align != ContentAlignment.MiddleCenter, "Result is ambiguous with an alignment of MiddleCenter."); return((align & (ContentAlignment.TopCenter | ContentAlignment.BottomCenter)) != 0); }
/// <summary> /// 在矩形指定位置划出指定大小的区域 /// </summary> /// <param name="size">大小</param> /// <param name="rect">矩形</param> /// <param name="align">对齐方式</param> /// <returns>划定区域</returns> public static Rectangle Align(Size size, Rectangle rect, ContentAlignment align) { return(VAlign(size, HAlign(size, rect, align), align)); }
public static StringFormat GetStringFormat(ContentAlignment contentAlignment) { if (!Enum.IsDefined(typeof(ContentAlignment), (int)contentAlignment)) { throw new InvalidEnumArgumentException("contentAlignment", (int)contentAlignment, typeof(ContentAlignment)); } StringFormat stringFormat = new StringFormat(); switch (contentAlignment) { case ContentAlignment.MiddleCenter: stringFormat.LineAlignment = StringAlignment.Center; stringFormat.Alignment = StringAlignment.Center; break; case ContentAlignment.MiddleLeft: stringFormat.LineAlignment = StringAlignment.Center; stringFormat.Alignment = StringAlignment.Near; break; case ContentAlignment.MiddleRight: stringFormat.LineAlignment = StringAlignment.Center; stringFormat.Alignment = StringAlignment.Far; break; case ContentAlignment.TopCenter: stringFormat.LineAlignment = StringAlignment.Near; stringFormat.Alignment = StringAlignment.Center; break; case ContentAlignment.TopLeft: stringFormat.LineAlignment = StringAlignment.Near; stringFormat.Alignment = StringAlignment.Near; break; case ContentAlignment.TopRight: stringFormat.LineAlignment = StringAlignment.Near; stringFormat.Alignment = StringAlignment.Far; break; case ContentAlignment.BottomCenter: stringFormat.LineAlignment = StringAlignment.Far; stringFormat.Alignment = StringAlignment.Center; break; case ContentAlignment.BottomLeft: stringFormat.LineAlignment = StringAlignment.Far; stringFormat.Alignment = StringAlignment.Near; break; case ContentAlignment.BottomRight: stringFormat.LineAlignment = StringAlignment.Far; stringFormat.Alignment = StringAlignment.Far; break; } return(stringFormat); }
/* * GetImageBounds */ /// <summary> /// </summary> public static Rectangle GetImageBounds(Rectangle itemBounds, Image itemImage, ContentAlignment imageAlign) { if (itemImage != null) { if ((imageAlign & NuGenControlPaint.AnyRight) > 0) { return(new Rectangle( itemBounds.Right - 3 - itemImage.Width, itemBounds.Top + (itemBounds.Height - itemImage.Height) / 2, itemImage.Width, itemImage.Height )); } return(new Rectangle( itemBounds.Left + 3, itemBounds.Top + (itemBounds.Height - itemImage.Height) / 2, itemImage.Width, itemImage.Height )); } return(Rectangle.Empty); }
private void DrawIcon(Graphics g) { if (this.Image != null) { int width = this._imagesize; int height = this._imagesize; if (this._imagesize == 0) { width = this._image.Width; height = this._image.Height; } Rectangle clientRectangle = base.ClientRectangle; Point point = new Point(2, (clientRectangle.Height - this._imagesize) / 2); int num = 0; ContentAlignment imageAlign = base.ImageAlign; if (imageAlign <= ContentAlignment.MiddleCenter) { switch (imageAlign) { case ContentAlignment.TopLeft: { point = new Point(num, num); break; } case ContentAlignment.TopCenter: { Rectangle rectangle = base.ClientRectangle; point = new Point((rectangle.Width - width) / 2, num); break; } case ContentAlignment.TopLeft | ContentAlignment.TopCenter: { break; } case ContentAlignment.TopRight: { Rectangle clientRectangle1 = base.ClientRectangle; point = new Point(clientRectangle1.Width - width - num, num); break; } default: { if (imageAlign == ContentAlignment.MiddleLeft) { Rectangle rectangle1 = base.ClientRectangle; point = new Point(num, (rectangle1.Height - height) / 2); break; } else if (imageAlign == ContentAlignment.MiddleCenter) { int width1 = (base.ClientRectangle.Width - width) / 2; Rectangle clientRectangle2 = base.ClientRectangle; point = new Point(width1, (clientRectangle2.Height - height) / 2); break; } else { break; } } } } else if (imageAlign <= ContentAlignment.BottomLeft) { if (imageAlign == ContentAlignment.MiddleRight) { Rectangle rectangle2 = base.ClientRectangle; Rectangle clientRectangle3 = base.ClientRectangle; point = new Point(rectangle2.Width - width - num, (clientRectangle3.Height - height) / 2); } else if (imageAlign == ContentAlignment.BottomLeft) { Rectangle rectangle3 = base.ClientRectangle; point = new Point(num, rectangle3.Height - height - num); } } else if (imageAlign == ContentAlignment.BottomCenter) { int num1 = (base.ClientRectangle.Width - width) / 2; Rectangle clientRectangle4 = base.ClientRectangle; point = new Point(num1, clientRectangle4.Height - height - num); } else if (imageAlign == ContentAlignment.BottomRight) { Rectangle rectangle4 = base.ClientRectangle; Rectangle clientRectangle5 = base.ClientRectangle; point = new Point(rectangle4.Width - width - num, clientRectangle5.Height - height - num); } point.Y = point.Y + 1; if (this._nofocus == null) { if (this.Theme == MetroThemeStyle.Dark) { g.DrawImage((!this.isHovered || this.isPressed ? this._darklightimg : this._darkimg), new Rectangle(point, new System.Drawing.Size(width, height))); return; } g.DrawImage((!this.isHovered || this.isPressed ? this._lightlightimg : this._lightimg), new Rectangle(point, new System.Drawing.Size(width, height))); return; } if (this.Theme == MetroThemeStyle.Dark) { g.DrawImage((!this.isHovered || this.isPressed ? this._nofocus : this._darkimg), new Rectangle(point, new System.Drawing.Size(width, height))); return; } g.DrawImage((!this.isHovered || this.isPressed ? this._nofocus : this._image), new Rectangle(point, new System.Drawing.Size(width, height))); } }
public static Size Print(Point location, ContentAlignment alignment, string text, params object[] args) { return(Print(location.X, location.Y, alignment, text, args)); }
public static void DrawText(this SKCanvas canvas, string text, Rectangle bounds, Control control, ContentAlignment alignment) => canvas.DrawText(text, control.CurrentStyle.GetFont(), control.LogicalToDeviceUnits(control.CurrentStyle.GetFontSize()), bounds, control.CurrentStyle.GetForegroundColor(), alignment);
/// <summary> /// Shows the tips. /// </summary> /// <param name="frm">The FRM.</param> /// <param name="strMsg">The string MSG.</param> /// <param name="intAutoColseTime">The int automatic colse time.</param> /// <param name="blnShowCoseBtn">if set to <c>true</c> [BLN show cose BTN].</param> /// <param name="align">The align.</param> /// <param name="point">The point.</param> /// <param name="mode">The mode.</param> /// <param name="size">The size.</param> /// <param name="state">The state.</param> /// <param name="color">The color.</param> /// <returns>FrmTips.</returns> public static FrmTips ShowTips( Form frm, string strMsg, int intAutoColseTime = 0, bool blnShowCoseBtn = true, ContentAlignment align = ContentAlignment.BottomLeft, Point?point = null, TipsSizeMode mode = TipsSizeMode.Small, Size?size = null, TipsState state = TipsState.Default) { if (m_lastTips.Key == strMsg + state && !m_lastTips.Value.IsDisposed && m_lastTips.Value.Visible) { m_lastTips.Value.ResetTimer(); return(m_lastTips.Value); } else { FrmTips frmTips = new FrmTips(); switch (mode) { case TipsSizeMode.Small: frmTips.Size = new Size(350, 35); break; case TipsSizeMode.Medium: frmTips.Size = new Size(350, 50); break; case TipsSizeMode.Large: frmTips.Size = new Size(350, 65); break; case TipsSizeMode.None: if (!size.HasValue) { frmTips.Size = new Size(350, 35); } else { frmTips.Size = size.Value; } break; } frmTips.BackColor = Color.FromArgb((int)state); if (state == TipsState.Default) { frmTips.lblMsg.ForeColor = SystemColors.ControlText; } else { frmTips.lblMsg.ForeColor = Color.White; } switch (state) { case TipsState.Default: frmTips.pctStat.Image = HZH_Controls.Properties.Resources.alarm; break; case TipsState.Success: frmTips.pctStat.Image = HZH_Controls.Properties.Resources.success; break; case TipsState.Info: frmTips.pctStat.Image = HZH_Controls.Properties.Resources.alarm; break; case TipsState.Warning: frmTips.pctStat.Image = HZH_Controls.Properties.Resources.warning; break; case TipsState.Error: frmTips.pctStat.Image = HZH_Controls.Properties.Resources.error; break; default: frmTips.pctStat.Image = HZH_Controls.Properties.Resources.alarm; break; } frmTips.lblMsg.Text = strMsg; frmTips.CloseTime = intAutoColseTime; frmTips.btnClose.Visible = blnShowCoseBtn; frmTips.ShowAlign = align; frmTips.Owner = frm; FrmTips.m_lstTips.Add(frmTips); FrmTips.ReshowTips(); frmTips.Show(frm); if (frm != null && !frm.IsDisposed) { ControlHelper.SetForegroundWindow(frm.Handle); } //frmTips.BringToFront(); m_lastTips = new KeyValuePair <string, FrmTips>(strMsg + state, frmTips); return(frmTips); } }
internal TextFormatFlags TextFormatFlagsForAlignmentGDI(ContentAlignment align) { return(this.TranslateAlignmentForGDI(align)); }
public LegendCell(LegendCellType cellType, string text, ContentAlignment alignment) : base(null) { this.Intitialize(cellType, text, alignment); }
public static bool IsHorizontalAlignment(ContentAlignment align) { return(!IsVerticalAlignment(align)); }
public static TextFormatFlags GetTextFormatFlags(ContentAlignment textAlign) { return(GetTextFormatFlags(textAlign, false)); }
public static TextFormatFlags GetTextFormatFlags(ContentAlignment textAlign, bool WrapToLine) { TextFormatFlags textFormatFlag = TextFormatFlags.Default; switch (WrapToLine) { case false: { textFormatFlag = TextFormatFlags.EndEllipsis; break; } case true: { textFormatFlag = TextFormatFlags.WordBreak; break; } } ContentAlignment contentAlignment = textAlign; if (contentAlignment <= ContentAlignment.MiddleCenter) { switch (contentAlignment) { case ContentAlignment.TopLeft: { textFormatFlag = textFormatFlag; break; } case ContentAlignment.TopCenter: { textFormatFlag = textFormatFlag | TextFormatFlags.HorizontalCenter; break; } case ContentAlignment.TopLeft | ContentAlignment.TopCenter: { break; } case ContentAlignment.TopRight: { textFormatFlag = textFormatFlag | TextFormatFlags.Right; break; } default: { if (contentAlignment == ContentAlignment.MiddleLeft) { textFormatFlag = textFormatFlag | TextFormatFlags.VerticalCenter; break; } else if (contentAlignment == ContentAlignment.MiddleCenter) { textFormatFlag = textFormatFlag | TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter; break; } else { break; } } } } else if (contentAlignment <= ContentAlignment.BottomLeft) { if (contentAlignment == ContentAlignment.MiddleRight) { textFormatFlag = textFormatFlag | TextFormatFlags.Right | TextFormatFlags.VerticalCenter; } else if (contentAlignment == ContentAlignment.BottomLeft) { textFormatFlag = textFormatFlag | TextFormatFlags.Bottom; } } else if (contentAlignment == ContentAlignment.BottomCenter) { textFormatFlag = textFormatFlag | TextFormatFlags.Bottom | TextFormatFlags.HorizontalCenter; } else if (contentAlignment == ContentAlignment.BottomRight) { textFormatFlag = textFormatFlag | TextFormatFlags.Bottom | TextFormatFlags.Right; } return(textFormatFlag); }
public ContentAlignment PublicRtlTranslateContent(ContentAlignment align) { return(base.RtlTranslateContent(align)); }
public static StringFormat GetStringFormat(ContentAlignment textAlign) { StringFormat stringFormat = new StringFormat() { Trimming = StringTrimming.EllipsisCharacter }; ContentAlignment contentAlignment = textAlign; if (contentAlignment <= ContentAlignment.MiddleCenter) { switch (contentAlignment) { case ContentAlignment.TopLeft: { stringFormat.Alignment = StringAlignment.Near; stringFormat.LineAlignment = StringAlignment.Near; break; } case ContentAlignment.TopCenter: { stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Near; break; } case ContentAlignment.TopLeft | ContentAlignment.TopCenter: { break; } case ContentAlignment.TopRight: { stringFormat.Alignment = StringAlignment.Far; stringFormat.LineAlignment = StringAlignment.Near; break; } default: { if (contentAlignment == ContentAlignment.MiddleLeft) { stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Near; break; } else if (contentAlignment == ContentAlignment.MiddleCenter) { stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Center; break; } else { break; } } } } else if (contentAlignment <= ContentAlignment.BottomLeft) { if (contentAlignment == ContentAlignment.MiddleRight) { stringFormat.Alignment = StringAlignment.Center; stringFormat.LineAlignment = StringAlignment.Far; } else if (contentAlignment == ContentAlignment.BottomLeft) { stringFormat.Alignment = StringAlignment.Far; stringFormat.LineAlignment = StringAlignment.Near; } } else if (contentAlignment == ContentAlignment.BottomCenter) { stringFormat.Alignment = StringAlignment.Far; stringFormat.LineAlignment = StringAlignment.Center; } else if (contentAlignment == ContentAlignment.BottomRight) { stringFormat.Alignment = StringAlignment.Far; stringFormat.LineAlignment = StringAlignment.Far; } return(stringFormat); }
private static Point GetWatermarkStartingPoint(float watermarkWidth, float watermarkHeight, float imageWidth, float imageHeight, ContentAlignment watermarkLocation, float borderPercent) { Point startingPoint = new Point(); switch (watermarkLocation) { case ContentAlignment.TopLeft: startingPoint.X = (int)(imageWidth * borderPercent); startingPoint.Y = (int)(imageHeight * borderPercent); break; case ContentAlignment.TopCenter: startingPoint.X = (int)(imageWidth - watermarkWidth) / 2; startingPoint.Y = (int)(imageHeight * borderPercent); break; case ContentAlignment.TopRight: startingPoint.X = (int)(imageWidth - watermarkWidth - (imageWidth * borderPercent)); startingPoint.Y = (int)(imageHeight * borderPercent); break; case ContentAlignment.MiddleLeft: startingPoint.X = (int)(imageWidth * borderPercent); startingPoint.Y = (int)(imageHeight - watermarkHeight) / 2; break; case ContentAlignment.MiddleCenter: startingPoint.X = (int)(imageWidth - watermarkWidth) / 2; startingPoint.Y = (int)(imageHeight - watermarkHeight) / 2; break; case ContentAlignment.MiddleRight: startingPoint.X = (int)(imageWidth - watermarkWidth - (imageWidth * borderPercent)); startingPoint.Y = (int)(imageHeight - watermarkHeight) / 2; break; case ContentAlignment.BottomLeft: startingPoint.X = (int)(imageWidth * borderPercent); startingPoint.Y = (int)(imageHeight - watermarkHeight - (imageHeight * borderPercent)); break; case ContentAlignment.BottomCenter: startingPoint.X = (int)(imageWidth - watermarkWidth) / 2; startingPoint.Y = (int)(imageHeight - watermarkHeight - (imageHeight * borderPercent)); break; case ContentAlignment.BottomRight: startingPoint.X = (int)(imageWidth - watermarkWidth - (imageWidth * borderPercent)); startingPoint.Y = (int)(imageHeight - watermarkHeight - (imageHeight * borderPercent)); break; default: startingPoint.X = (int)(imageWidth * borderPercent); startingPoint.Y = (int)(imageHeight * borderPercent); break; } return(startingPoint); }
public static Rectangle Align(Size alignThis, Rectangle withinThis, ContentAlignment align) { return(VAlign(alignThis, HAlign(alignThis, withinThis, align), align)); }
public override SizeF Arrange(RectangleF bounds) { SizeF finalSize = bounds.Size; if (this.lastFinalSize != finalSize || this.isDirty) { this.lastFinalSize = finalSize; this.Measure(finalSize); } SizeF fieldSize = finalSize; RectangleF layoutField = new RectangleF(bounds.Location, finalSize); RectangleF imageBounds = RectangleF.Empty; RectangleF textBounds = RectangleF.Empty; SizeF textSize = SizeF.Empty; SizeF imageSize = SizeF.Empty; ContentAlignment imageAlign = this.owner.ImageAlignment; ContentAlignment textAlign = this.owner.TextAlignment; TextImageRelation textImageRelation = this.owner.TextImageRelation; if (this.owner.RightToLeft) { imageAlign = TelerikAlignHelper.RtlTranslateContent(imageAlign); textAlign = TelerikAlignHelper.RtlTranslateContent(textAlign); textImageRelation = TelerikAlignHelper.RtlTranslateRelation(textImageRelation); } if ((this.left != null) && (this.owner.Image == null)) { this.left.Arrange(layoutField); if (this.right != null) { this.right.Arrange(layoutField); } return(finalSize); } if (this.right != null && (string.IsNullOrEmpty(this.owner.Text) || !this.owner.DrawText)) { this.right.Arrange(layoutField); if (this.left != null) { this.left.Arrange(layoutField); } return(finalSize); } imageSize = this.GetInvariantLength(Size.Ceiling(this.left.DesiredSize), this.left.Margin); textSize = this.GetInvariantLength(Size.Ceiling(this.right.DesiredSize), this.right.Margin); // Subtract the image size from the whole field size SizeF textSizeLeft = LayoutUtils.SubAlignedRegion(fieldSize, imageSize, textImageRelation); // Create a new size based on the text size and the image size SizeF newSize = LayoutUtils.AddAlignedRegion(textSize, imageSize, textImageRelation); // The new field which is a union of the new sizes RectangleF maxFieldRectangle = Rectangle.Empty; maxFieldRectangle.Size = LayoutUtils.UnionSizes(fieldSize, newSize); maxFieldRectangle.X += layoutField.X; maxFieldRectangle.Y += layoutField.Y; // Image doesn't overlay text bool imageAlignNoOverlay = (TelerikAlignHelper.ImageAlignToRelation(imageAlign) & textImageRelation) != TextImageRelation.Overlay; // Text doesn't overlay image bool textAlignNoOverlay = (TelerikAlignHelper.TextAlignToRelation(textAlign) & textImageRelation) != TextImageRelation.Overlay; if (imageAlignNoOverlay) { LayoutUtils.SplitRegion(maxFieldRectangle, imageSize, (AnchorStyles)textImageRelation, out imageBounds, out textBounds); } else if (textAlignNoOverlay) { LayoutUtils.SplitRegion(maxFieldRectangle, textSize, (AnchorStyles)LayoutUtils.GetOppositeTextImageRelation(textImageRelation), out textBounds, out imageBounds); } else { // Both image overlays text and text overlays image if (textImageRelation == TextImageRelation.Overlay) { LayoutUtils.SplitRegion(maxFieldRectangle, imageSize, (AnchorStyles)textImageRelation, out imageBounds, out textBounds); } else { RectangleF alignedField = LayoutUtils.Align(newSize, maxFieldRectangle, ContentAlignment.MiddleCenter); LayoutUtils.SplitRegion(alignedField, imageSize, (AnchorStyles)textImageRelation, out imageBounds, out textBounds); LayoutUtils.ExpandRegionsToFillBounds(maxFieldRectangle, (AnchorStyles)textImageRelation, ref imageBounds, ref textBounds); } } /////////////////////////////////////////////////////////////////////////// //set image and text bounds according the size of the field if ((textImageRelation == TextImageRelation.TextBeforeImage) || (textImageRelation == TextImageRelation.ImageBeforeText)) { float num1 = Math.Min(textBounds.Bottom, layoutField.Bottom); textBounds.Y = Math.Max(Math.Min(textBounds.Y, layoutField.Y + ((layoutField.Height - textBounds.Height) / 2)), layoutField.Y); textBounds.Height = num1 - textBounds.Y; } if ((textImageRelation == TextImageRelation.TextAboveImage) || (textImageRelation == TextImageRelation.ImageAboveText)) { float num2 = Math.Min(textBounds.Right, layoutField.Right); textBounds.X = Math.Max(Math.Min(textBounds.X, layoutField.X + ((layoutField.Width - textBounds.Width) / 2)), layoutField.X); textBounds.Width = num2 - textBounds.X; } if ((textImageRelation == TextImageRelation.ImageBeforeText) && (imageBounds.Size.Width != 0)) { imageBounds.Width = Math.Max(0, Math.Min(fieldSize.Width - textBounds.Width, imageBounds.Width)); textBounds.X = imageBounds.X + imageBounds.Width; } if ((textImageRelation == TextImageRelation.ImageAboveText) && (imageBounds.Size.Height != 0)) { imageBounds.Height = Math.Max(0, Math.Min(fieldSize.Height - textBounds.Height, imageBounds.Height)); textBounds.Y = imageBounds.Y + imageBounds.Height; } textBounds = RectangleF.Intersect(textBounds, layoutField); //align image and if its size is greater than the field's size it is become offseted as much as the difference RectangleF newImageBounds = LayoutUtils.Align(imageSize, imageBounds, imageAlign); if (newImageBounds.Width > imageBounds.Width) { newImageBounds.X = imageBounds.Width - imageSize.Width; } if (newImageBounds.Height > imageBounds.Height) { newImageBounds.Y = imageBounds.Height - imageSize.Height; } textBounds = LayoutUtils.Align(textSize, textBounds, textAlign); //textBounds.Offset(layoutField.Location); //imageBounds.Offset(layoutField.Location); ///////////////////////////////////////////////////////////////////////// textBounds.Size = SizeF.Subtract(textBounds.Size, this.left.Margin.Size); imageBounds.Size = SizeF.Subtract(imageBounds.Size, this.right.Margin.Size); this.left.Arrange(imageBounds); this.right.Arrange(textBounds); return(finalSize); }
public ToolStripItemTextRenderEventArgs(Graphics g, ToolStripItem item, string text, Rectangle textRectangle, Color textColor, Font textFont, ContentAlignment textAlign) : base(g, item) { throw null; }
/* * GetTextRectangle */ /// <summary> /// </summary> public static Rectangle GetTextBounds(Rectangle itemBounds, Rectangle imageBounds, ContentAlignment textAlign) { if ((textAlign & NuGenControlPaint.AnyRight) > 0) { if (!imageBounds.IsEmpty) { return(new Rectangle( itemBounds.Left + 1, itemBounds.Top, itemBounds.Width - (itemBounds.Right - imageBounds.Left) - 1, itemBounds.Height )); } return(itemBounds); } return(new Rectangle( imageBounds.Right + 1, itemBounds.Top, itemBounds.Width - imageBounds.Right - 1, itemBounds.Height )); }
/// <summary> /// This class represents all the information to render the ToolStrip /// </summary> public ToolStripItemTextRenderEventArgs(Graphics g, ToolStripItem item, string text, Rectangle textRectangle, Color textColor, Font textFont, ContentAlignment textAlign) : base(g, item) { Text = text; TextRectangle = textRectangle; DefaultTextColor = textColor; TextFont = textFont; TextFormat = ToolStripItemInternalLayout.ContentAlignToTextFormat(textAlign, item.RightToLeft == RightToLeft.Yes); TextFormat = (item.ShowKeyboardCues) ? TextFormat : TextFormat | TextFormatFlags.HidePrefix; TextDirection = item.TextDirection; }
public static void DrawTexturePixeledAlignment(Texture2D tex, ContentAlignment alignment, float x, float y, int layer = -1, bool flipY = false) { DrawTexturePixeledAlignment(tex, alignment, x, y, Color4.White, 0.0f, 1.0f, layer, flipY); }
public static Rectangle Align(Size alignThis, Rectangle withinThis, ContentAlignment align) { return(LayoutUtils.VAlign(alignThis, LayoutUtils.HAlign(alignThis, withinThis, align), align)); }
/// <summary> /// Displays the message on the indicated line /// </summary> /// <param name="line">The line to display the message on</param> /// <param name="message">The message to display</param> public override void SetLine(int line, string message, ContentAlignment aAlignment) { if (line >= lines) { Log.Error("DM140GINK.SetLine: error bad line number" + line); return; } try { // Write message vfd.writeLine(line, RemoveDiacritics(message)); //Volume calculation int vol = VolumeHandler.Instance.Volume / 2730; // Display symbols // LiveTV, LiveRadio vfd.updateSymbol(control.VFDSymbols.Antenna, false); // DVD if (g_Player.IsDVD) { vfd.updateSymbol(control.VFDSymbols.DVD, true); } else { vfd.updateSymbol(control.VFDSymbols.DVD, false); } // CDA if (g_Player.IsCDA) { vfd.updateSymbol(control.VFDSymbols.CD, true); } else { vfd.updateSymbol(control.VFDSymbols.CD, false); } // Video if ((g_Player.IsVideo || g_Player.IsTVRecording) & !(g_Player.IsDVD || g_Player.IsCDA)) { vfd.updateSymbol(control.VFDSymbols.V, true); } else { vfd.updateSymbol(control.VFDSymbols.V, false); } // Play if (g_Player.Playing & !g_Player.Paused & (g_Player.Speed == 1) & !g_Player.IsDVDMenu) { vfd.updateSymbol(control.VFDSymbols.Play, true); } else { vfd.updateSymbol(control.VFDSymbols.Play, false); } // Pause if (g_Player.Paused) { vfd.updateSymbol(control.VFDSymbols.Pause, true); } else { vfd.updateSymbol(control.VFDSymbols.Pause, false); } // Forward if (g_Player.Speed > 1) { vfd.updateSymbol(control.VFDSymbols.Forward, true); } else { vfd.updateSymbol(control.VFDSymbols.Forward, false); } // Rewind if (g_Player.Speed < -1) { vfd.updateSymbol(control.VFDSymbols.Rewind, true); } else { vfd.updateSymbol(control.VFDSymbols.Rewind, false); } // Volume vfd.setVolume(vol); // Mute if (VolumeHandler.Instance.IsMuted) { vfd.updateSymbol(control.VFDSymbols.Mute, true); } else { vfd.updateSymbol(control.VFDSymbols.Mute, false); } // Recording in progress vfd.updateSymbol(control.VFDSymbols.REC, false); } catch (Exception ex) { Log.Error(ex); } }