示例#1
0
        /// <summary>
        /// Sets the control text alignment.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="control">The control.</param>
        private void SetTextAlignment(List <string> writer, Control control)
        {
            PropertyInfo textAlignment = control.GetType().GetProperty("TextAlign");

            if (textAlignment != null)
            {
                object alignmentValue = textAlignment.GetValue(control, null);

                if (alignmentValue is HorizontalAlignment)
                {
                    HorizontalAlignment alignment = (HorizontalAlignment)alignmentValue;
                    writer.Add(string.Format("		this.{0}.setHorizontalAlignment(SwingConstants.{1});", control.Name, alignmentValue.ToString().ToUpper()));
                }
                else if (alignmentValue is ContentAlignment)
                {
                    ContentAlignment alignment = (ContentAlignment)alignmentValue;

                    string verticalAlignment   = alignment.ToString().Replace("Center", string.Empty).Replace("Left", string.Empty).Replace("Right", string.Empty);
                    string horizontalAlignment = alignment.ToString().Replace("Bottom", string.Empty).Replace("Middle", string.Empty).Replace("Top", string.Empty);

                    verticalAlignment = verticalAlignment == "Middle" ? "Center" : verticalAlignment;

                    writer.Add(string.Format("		this.{0}.setVerticalAlignment(SwingConstants.{1});", control.Name, verticalAlignment.ToUpper()));
                    writer.Add(string.Format("		this.{0}.setHorizontalAlignment(SwingConstants.{1});", control.Name, horizontalAlignment.ToUpper()));
                }
            }
        }
示例#2
0
        internal static void DrawContent(string Text, Image Image, ContentAlignment TextAlign, ContentAlignment ImageAlign, ExBrush[] brushes, Graphics g, Rectangle r, Font f, int alpha)
        {
            StringFormat sf = new StringFormat();

            if (TextAlign.ToString().StartsWith("Top"))
            {
                sf.LineAlignment = StringAlignment.Near;
            }
            else if (TextAlign.ToString().StartsWith("Middle"))
            {
                sf.LineAlignment = StringAlignment.Center;
            }
            else
            {
                sf.LineAlignment = StringAlignment.Far;
            }

            if (TextAlign.ToString().EndsWith("Center"))
            {
                sf.Alignment = StringAlignment.Center;
            }
            else if (TextAlign.ToString().EndsWith("Left"))
            {
                sf.Alignment = StringAlignment.Near;
            }
            else
            {
                sf.Alignment = StringAlignment.Far;
            }

            foreach (ExBrush brush in brushes)
            {
                brush.SetAlpha(alpha);
                brush.DrawText(g, r, Text, f, sf);
            }

            if (Image != null && (Image.Width * Image.Height > 0))
            {
                Rectangle imgrect = r;
                imgrect = HAlignWithin(Image.Size, imgrect, ImageAlign);
                imgrect = VAlignWithin(Image.Size, imgrect, ImageAlign);

                ColorMatrix cm = new ColorMatrix();
                cm.Matrix33 = ((float)alpha / 255);
                ImageAttributes ia = new ImageAttributes();
                ia.SetColorMatrix(cm);

                g.DrawImage(Image, imgrect, 0, 0, Image.Width, Image.Height, GraphicsUnit.Pixel, ia);
            }
        }
示例#3
0
        public static Vector2 GetContentAlign(Rectangle bounds, ContentAlignment align, Vector2 objSize)
        {
            float  x        = 0;
            float  y        = 0;
            string alignStr = align.ToString().ToLower();

            if (alignStr.Contains("left"))
            {
                x = bounds.X;
            }
            if (alignStr.Contains("center"))
            {
                x = bounds.Width / 2 + bounds.X - objSize.X / 2;
            }
            if (alignStr.Contains("right"))
            {
                x = bounds.X + bounds.Width - objSize.X;
            }

            if (alignStr.Contains("top"))
            {
                y = bounds.Y;
            }
            if (alignStr.Contains("middle"))
            {
                y = bounds.Height / 2 + bounds.Y - objSize.Y / 2;
            }
            if (alignStr.Contains("bottom"))
            {
                y = bounds.Y + bounds.Height - objSize.Y;
            }

            return(new Vector2(x, y));
        }
示例#4
0
        private void btStandart_Click(object sender, EventArgs e)
        {
            // отримання значення переліку ContentAligment
            Array values = Enum.GetValues(currAligment.GetType());

            // читання поточної позиції в переліку
            // і циклічне повернення
            currEnumPos++;
            if (currEnumPos >= values.Length)
            {
                currEnumPos = 0;
            }

            // читання поточного значення переліку
            currAligment =
                (ContentAlignment)Enum.Parse(currAligment.GetType(),
                                             values.GetValue(currEnumPos).ToString());

            // вивід тексту и його вирівнювання на btStandart
            btStandart.TextAlign = currAligment;
            btStandart.Text      = currAligment.ToString();

            // розміщення піктограми на btImage
            btImage.ImageAlign = currAligment;
        }
示例#5
0
 protected virtual ContentAlignment GetImageAlignment()
 {
     foreach (RadToggleButton control in (ArrangedElementCollection)this.tableLayoutPanel2.Controls)
     {
         if (control.IsChecked)
         {
             string str = control.Name.Split(new string[1] {
                 "Button"
             }, StringSplitOptions.RemoveEmptyEntries)[1];
             IEnumerator enumerator = Enum.GetValues(typeof(ContentAlignment)).GetEnumerator();
             try
             {
                 while (enumerator.MoveNext())
                 {
                     ContentAlignment current = (ContentAlignment)enumerator.Current;
                     if (current.ToString() == str)
                     {
                         return(current);
                     }
                 }
                 break;
             }
             finally
             {
                 (enumerator as IDisposable)?.Dispose();
             }
         }
     }
     return(ContentAlignment.MiddleCenter);
 }
        protected void btnStandard_Click(object sender, System.EventArgs e)
        {
            // Get all possible values
            // of the ContentAlignment enum.
            Array values = Enum.GetValues(currAlignment.GetType());

            // Bump the current position in the enum.
            // & check for wrap around.
            currEnumPos++;
            if (currEnumPos >= values.Length)
            {
                currEnumPos = 0;
            }

            // Bump the current enum value.
            currAlignment = (ContentAlignment)ContentAlignment.Parse(currAlignment.GetType(),
                                                                     values.GetValue(currEnumPos).ToString());
            btnStandard.TextAlign = currAlignment;

            // Paint enum value name on button.
            btnStandard.Text = currAlignment.ToString();

            // Now assign the location of the ICON on
            // btnImage...
            btnImage.ImageAlign = currAlignment;
        }
示例#7
0
        internal static void DrawContent(string Text, Image Image, ContentAlignment TextAlign, ContentAlignment ImageAlign, ExBrush[] brushes, Graphics g, Rectangle r, Font f)
        {
            StringFormat sf = new StringFormat();

            if (TextAlign.ToString().StartsWith("Top"))
            {
                sf.LineAlignment = StringAlignment.Near;
            }
            else if (TextAlign.ToString().StartsWith("Middle"))
            {
                sf.LineAlignment = StringAlignment.Center;
            }
            else
            {
                sf.LineAlignment = StringAlignment.Far;
            }

            if (TextAlign.ToString().EndsWith("Center"))
            {
                sf.Alignment = StringAlignment.Center;
            }
            else if (TextAlign.ToString().EndsWith("Left"))
            {
                sf.Alignment = StringAlignment.Near;
            }
            else
            {
                sf.Alignment = StringAlignment.Far;
            }

            foreach (ExBrush brush in brushes)
            {
                brush.DrawText(g, r, Text, f, sf);
            }

            if (Image != null && (Image.Width * Image.Height > 0))
            {
                Rectangle imgrect = r;
                imgrect = HAlignWithin(Image.Size, imgrect, ImageAlign);
                imgrect = VAlignWithin(Image.Size, imgrect, ImageAlign);

                g.DrawImage(Image, imgrect);
            }
        }
示例#8
0
 private void button2_Click(object sender, EventArgs e)
 {
     if (_position >= _array.Length)
     {
         _position = 0;
     }
     _aligment          = (ContentAlignment)Enum.Parse(_aligment.GetType(), _array.GetValue(_position).ToString());
     button3.TextAlign  = _aligment;
     button3.ImageAlign = _aligment;
     button3.Text       = _aligment.ToString();
     _position++;
 }
 protected override void OnPaint(PaintEventArgs pe)
 {
     base.OnPaint(pe);
     if (_drawText)
     {
         drawString(pe.Graphics, Text, Font, _textAligment.ToString());
     }
     if (_drawImage && _image != null)
     {
         float drawHeight = Height / 2 - _imageSize.Height / 2;
         pe.Graphics.DrawImage(_selected || (_mouseHovering && _useActiveImageWhileHovering) ? (_selectedImage != null ? _selectedImage : _image) : _image, drawHeight, drawHeight, _imageSize.Width, _imageSize.Height);
     }
 }
示例#10
0
    protected void btnStandard_Click(object sender, System.EventArgs e)
    {
        Array values = Enum.GetValues(currAlignment.GetType());

        currEnumPos++;
        if (currEnumPos >= values.Length)
        {
            currEnumPos = 0;
        }

        currAlignment = (ContentAlignment)ContentAlignment.Parse(currAlignment.GetType(),
                                                                 values.GetValue(currEnumPos).ToString());
        btnStandard.TextAlign = currAlignment;

        btnStandard.Text = currAlignment.ToString();
    }
示例#11
0
        private void setCA()
        {
            this.lblSelected.Text = ca.ToString();
            unpressAll();

            switch (ca)
            {
            case ContentAlignment.TopLeft:
                tl.IsPressed = true;
                break;

            case ContentAlignment.TopCenter:
                tc.IsPressed = true;
                break;

            case ContentAlignment.TopRight:
                tr.IsPressed = true;
                break;

            case ContentAlignment.MiddleLeft:
                ml.IsPressed = true;
                break;

            case ContentAlignment.MiddleCenter:
                mc.IsPressed = true;
                break;

            case ContentAlignment.MiddleRight:
                mr.IsPressed = true;
                break;

            case ContentAlignment.BottomLeft:
                bl.IsPressed = true;
                break;

            case ContentAlignment.BottomCenter:
                bc.IsPressed = true;
                break;

            case ContentAlignment.BottomRight:
                br.IsPressed = true;
                break;
            }
        }
示例#12
0
 /// <summary>
 /// 將字劃到圖形內
 /// </summary>
 /// <param name="image"></param>
 /// <param name="text"></param>
 /// <param name="font"></param>
 /// <param name="textColor"></param>
 /// <param name="site"></param>
 public static void DrawTextInPicture(Image image, string text, Font font, Color textColor, ContentAlignment site)
 {
     using (Graphics drawing = Graphics.FromImage(image))
     {
         drawing.SmoothingMode     = SmoothingMode.AntiAlias;
         drawing.InterpolationMode = InterpolationMode.HighQualityBicubic;
         drawing.PixelOffsetMode   = PixelOffsetMode.HighQuality;
         using (Brush textBrush = new SolidBrush(textColor))
             using (StringFormat sf = new StringFormat())
             {
                 string siteName = site.ToString();
                 sf.LineAlignment = siteName.StartsWith("Top") ? StringAlignment.Near : siteName.StartsWith("Middle") ? StringAlignment.Center : StringAlignment.Far;
                 sf.Alignment     = siteName.EndsWith("Left") ? StringAlignment.Near : siteName.EndsWith("Center") ? StringAlignment.Center : StringAlignment.Far;
                 Rectangle rectf = new Rectangle(0, 0, image.Width, image.Height);
                 drawing.DrawString(text, font, textBrush, rectf, sf);
             }
         drawing.Flush();
     }
 }
示例#13
0
        private void resizeTextBox()
        {
            //box.BackColor = Color.Aqua;
            const int padding   = 5;
            int       numLines  = box.GetLineFromCharIndex(box.TextLength) + 1;
            int       border    = box.Height - box.ClientSize.Height;
            int       heightBox = box.Font.Height * numLines + padding + border;

            if (heightBox + _radius > Height)
            {
                box.Height     = Height - _radius - 2;
                box.ScrollBars = ScrollBars.Vertical;
            }
            else
            {
                box.Height     = heightBox;
                box.ScrollBars = ScrollBars.None;
            }
            box.Width = Width - (int)(_radius * 2);
            int y = 0;

            if (_textAlign.ToString().Contains("Top"))
            {
                y = 2;
            }
            if (_textAlign.ToString().Contains("Mid"))
            {
                y = (Height - box.Height) / 2;
            }
            if (_textAlign.ToString().Contains("Bottom"))
            {
                y = (Height - box.Height) - 2 /*- _radius / 2+2*/;
            }
            if (_textAlign.ToString().Contains("Left"))
            {
                box.TextAlign = HorizontalAlignment.Left;
            }
            if (_textAlign.ToString().Contains("Center"))
            {
                box.TextAlign = HorizontalAlignment.Center;
            }
            if (_textAlign.ToString().Contains("Right"))
            {
                box.TextAlign = HorizontalAlignment.Right;
            }
            box.Location = new Point(_radius, y);
        }
示例#14
0
        private void setAlignmentPosition(ContentAlignment alignment)
        {
            //Hacky way to determine alignment via string parsing, rather than a ton of if/elseif
            this.alignment = alignment;
            string alignmentStr = alignment.ToString();

            Vector2 position = relativePosition;

            //Vertical Alignment
            if (alignmentStr.Contains("Top"))
            {
                position.Y = 0f;
            }
            else if (alignmentStr.Contains("Middle"))
            {
                position.Y = (float)Math.Round((Parent.Height / 2f) - (Height / 2f));
            }
            else if (alignmentStr.Contains("Bottom"))
            {
                position.Y = Parent.Height - Height;
            }

            //Horizontal Alignment
            if (alignmentStr.Contains("Left"))
            {
                position.X = 0f;
            }
            else if (alignmentStr.Contains("Center"))
            {
                position.X = (float)Math.Round((Parent.Width / 2f) - (Width / 2f));
            }
            else if (alignmentStr.Contains("Right"))
            {
                position.X = Parent.Width - Width;
            }

            Position = position;
        }
示例#15
0
        public override Bitmap DrawButton()
        {
            if (Width > 0 & Height > 0)
            {
                Bitmap mybitmap = new Bitmap(1, 1);

                if (TextHeight > 0)
                {
                    Graphics   g       = null;
                    SolidBrush mybrush = new SolidBrush(GetButtonColor());

                    int    drawHeight = 0;
                    string drawString = ForceCaps ? Text.ToUpper() : Text;

                    FontData fontDims = GetFontDimensions(font, drawString);
                    if (fontDims.Height == 0)
                    {
                        fontDims        = new FontData();
                        fontDims.Height = Height;
                    }
                    TextVisible = false;
                    mybitmap    = new Bitmap(Size.Width, fontDims.Height);
                    g           = Graphics.FromImage(mybitmap);

                    if (Text.ToUpper().Contains("Q"))
                    {
                        drawHeight = fontDims.Height - (fontDims.Height / 10);
                        Height     = mybitmap.Height;
                    }
                    else
                    {
                        drawHeight = fontDims.Height;
                        Height     = drawHeight;
                    }

                    //Set graphics to use smoothing
                    g.SmoothingMode   = SmoothingMode.AntiAlias;
                    g.PixelOffsetMode = PixelOffsetMode.HighQuality;

                    //Draw black background
                    g.FillRectangle(Brushes.Black, 0, 0, mybitmap.Width, mybitmap.Height);
                    g.FillRectangle(mybrush, drawHeight + 6, 0, (Width - (drawHeight * 2)) - 12, drawHeight); // full middle bar

                    switch (buttonType)
                    {
                    case TextButtonType.DoublePills:
                        g.FillEllipse(mybrush, 0, 0, drawHeight, drawHeight);                        // left pill
                        g.FillRectangle(mybrush, drawHeight / 2, 0, drawHeight / 2, drawHeight);     // left pill bulk
                        g.FillEllipse(mybrush, Width - drawHeight, 0, drawHeight, drawHeight);       // right pill
                        g.FillRectangle(mybrush, Width - drawHeight, 0, drawHeight / 2, drawHeight); // right pill bulk
                        break;

                    case TextButtonType.LeftPill:
                        g.FillEllipse(mybrush, 0, 0, drawHeight, drawHeight);                    // left pill
                        g.FillRectangle(mybrush, drawHeight / 2, 0, drawHeight / 2, drawHeight); // left pill bulk
                        g.FillRectangle(mybrush, Width - drawHeight, 0, drawHeight, drawHeight); // right pill bulk
                        break;

                    case TextButtonType.RightPill:
                        g.FillRectangle(mybrush, 0, 0, drawHeight, drawHeight);                      // left pill bulk
                        g.FillEllipse(mybrush, Width - drawHeight, 0, drawHeight, drawHeight);       // right pill
                        g.FillRectangle(mybrush, Width - drawHeight, 0, drawHeight / 2, drawHeight); // right pill bulk
                        break;

                    case TextButtonType.NoPills:
                        g.FillRectangle(mybrush, 0, 0, drawHeight, drawHeight);                  // left pill bulk
                        g.FillRectangle(mybrush, Width - drawHeight, 0, drawHeight, drawHeight); // right pill bulk
                        break;
                    }

                    if (!string.IsNullOrEmpty(Text))
                    {
                        if (buttonTextAlign.ToString().ToLower().Contains("right"))
                        {
                            g.FillRectangle(Brushes.Black, Width - ((fontDims.Width + drawHeight) + 12), 0, fontDims.Width + 6, drawHeight);
                            g.DrawString(drawString, font, Brushes.Orange, Width - (((fontDims.Width + fontDims.Left) + drawHeight) + 6), -fontDims.Top);
                        }

                        if (buttonTextAlign.ToString().ToLower().Contains("left"))
                        {
                            g.FillRectangle(Brushes.Black, drawHeight + 6, 0, fontDims.Width + 6, drawHeight);
                            g.DrawString(drawString, font, Brushes.Orange, (drawHeight - fontDims.Left) + 6, -fontDims.Top);
                        }

                        if (buttonTextAlign.ToString().ToLower().Contains("center"))
                        {
                            g.FillRectangle(Brushes.Black, (Width / 2) - ((fontDims.Width + 12) / 2), 0, fontDims.Width + 12, drawHeight);
                            g.DrawString(drawString, font, Brushes.Orange, ((Width / 2) - (fontDims.Width / 2)) - fontDims.Left, -fontDims.Top);
                        }
                    }
                }
                return(mybitmap);
            }
            else
            {
                return(new Bitmap(1, 1));
            }
        }
示例#16
0
        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
            roundedRect = new RoundedBorder(Width, Height, radius);
            e.Graphics.FillRectangle(Brushes.Transparent, ClientRectangle);

            int R1 = (active1.R + inactive1.R) / 2;
            int G1 = (active1.G + inactive1.G) / 2;
            int B1 = (active1.B + inactive1.B) / 2;

            int R2 = (active2.R + inactive2.R) / 2;
            int G2 = (active2.G + inactive2.G) / 2;
            int B2 = (active2.B + inactive2.B) / 2;

            Rectangle rect = new Rectangle(0, 0, Width, Height);

            if (this.Enabled)
            {
                if (state == MouseState.Leave)
                {
                    using (LinearGradientBrush inactiveGB = new LinearGradientBrush(rect, inactive1, inactive2, gradientAngle))
                        e.Graphics.FillPath(inactiveGB, roundedRect.Path);
                }
                else if (state == MouseState.Enter)
                {
                    using (LinearGradientBrush activeGB = new LinearGradientBrush(rect, active1, active2, gradientAngle))
                        e.Graphics.FillPath(activeGB, roundedRect.Path);
                }
                else if (state == MouseState.Down)
                {
                    using (LinearGradientBrush downGB = new LinearGradientBrush(rect, Color.FromArgb(R1, G1, B1), Color.FromArgb(R2, G2, B2), gradientAngle))
                        e.Graphics.FillPath(downGB, roundedRect.Path);
                }
                if (stroke)
                {
                    using (Pen pen = new Pen(strokeColor, 1))
                        using (GraphicsPath path = new RoundedBorder(Width - (radius > 0 ? 0 : 1), Height - (radius > 0 ? 0 : 1), radius).Path)
                            e.Graphics.DrawPath(pen, path);
                }
            }
            else
            {
                Color linear1 = Color.FromArgb(190, 190, 190);
                Color linear2 = Color.FromArgb(210, 210, 210);
                using (LinearGradientBrush inactiveGB = new LinearGradientBrush(rect, linear1, linear2, 90f))
                {
                    e.Graphics.FillPath(inactiveGB, roundedRect.Path);
                    e.Graphics.DrawPath(new Pen(inactiveGB), roundedRect.Path);
                }
            }

            Size newSize = Size;

            //newSize.Width = newSize.Width - Padding.Left - Padding.Right;
            float[] getSize  = NewFontSize(e.Graphics, newSize, Font, Text);
            float   fontSize = getSize[0];
            Font    newFont  = Font;

            if (_autoSizeFont)
            {
                newFont    = new Font(Font.FontFamily, fontSize, Font.Style);
                getSize[1] = measureSizeF(e.Graphics, newFont, Text).Width;
                getSize[2] = measureSizeF(e.Graphics, newFont, Text).Height;
            }

            Rectangle       rrRectangle = ClientRectangle;
            StringAlignment horAlgnmt   = StringAlignment.Center;
            StringAlignment verAlgnmt   = StringAlignment.Center;
            int             selisihH    = (int)((ClientRectangle.Width - getSize[1]) / 2);
            int             selisihV    = (int)((ClientRectangle.Height - getSize[2]) / 2);

            if (_textAlign.ToString().Contains("Left"))
            {
                horAlgnmt = StringAlignment.Near;
            }

            if (_textAlign.ToString().Contains("Right"))
            {
                horAlgnmt = StringAlignment.Far;
            }
            if (_textAlign.ToString().Contains("Top"))
            {
                verAlgnmt = StringAlignment.Near;
            }

            if (_textAlign.ToString().Contains("Bottom"))
            {
                verAlgnmt = StringAlignment.Far;
            }
            if (_Picon != null)
            {
                int locX = ClientRectangle.Width / 2 - _Picon.Width / 2;
                int locY = ClientRectangle.Height / 2 - _Picon.Height / 2;
                if (_iconPosition == Position.FollowLeft && _textAlign.ToString().Contains("Center"))
                {
                    locX = (int)(ClientRectangle.Width - getSize[1]) / 2 - _Picon.Width;
                    locX = locX > Padding.Left + 5 ? locX : Padding.Left + 5;
                }
                else if (_iconPosition == Position.FollowLeft && _textAlign.ToString().Contains("Right"))
                {
                    locX = (int)(ClientRectangle.Width - getSize[1] - _Picon.Width);
                    locX = locX > Padding.Left + 5 ? locX : Padding.Left + 5;
                }
                else if (_iconPosition == Position.FollowRight && _textAlign.ToString().Contains("Center"))
                {
                    locX = (int)((ClientRectangle.Width + getSize[1]) / 2);
                    int tempX = ClientRectangle.Width - _Picon.Width - 5 - Padding.Right;
                    locX = locX > tempX ? tempX:locX;
                }
                else if (_iconPosition == Position.FollowRight && _textAlign.ToString().Contains("Left"))
                {
                    locX = (int)(getSize[1] + 5);
                    int tempX = ClientRectangle.Width - _Picon.Width - 5 - Padding.Right;
                    locX = locX > tempX ? tempX : locX;
                }
                else if (_iconPosition == Position.FollowTop && _textAlign.ToString().Contains("Middle"))
                {
                    locY = (int)((ClientRectangle.Height - getSize[2]) / 2) - _Picon.Height;
                    locY = locY > Padding.Top + 5 ? locY : Padding.Top + 5;
                }
                else if (_iconPosition == Position.FollowTop && _textAlign.ToString().Contains("Bottom"))
                {
                    locY = (int)(ClientRectangle.Height - getSize[2] - _Picon.Height);
                    int tempY = ClientRectangle.Width - _Picon.Width - 5 - Padding.Right;
                    locY = locY > Padding.Top + 5 ? locY : Padding.Top + 5;
                }
                else if (_iconPosition == Position.FollowBottom && _textAlign.ToString().Contains("Middle"))
                {
                    locY = (int)((ClientRectangle.Height + getSize[2]) / 2);
                    int tempY = ClientRectangle.Height - _Picon.Width - 5 - Padding.Right;
                    locY = locY > tempY ? tempY:locY;
                }
                else if (_iconPosition == Position.FollowBottom && _textAlign.ToString().Contains("Top"))
                {
                    locY = (int)(getSize[2] + 5);
                    int tempY = ClientRectangle.Height - _Picon.Width - 5 - Padding.Right;
                    locY = locY > tempY ? tempY : locY;
                }
                else if (_iconPosition.ToString().Contains("Left"))
                {
                    locX = 5 + Padding.Left;
                    if ((ClientRectangle.Width - getSize[1]) / 2 < _Picon.Width + 5 + Padding.Left)
                    {
                        rrRectangle.X = _Picon.Width + Padding.Left + 5 - selisihH;
                    }
                    if (_textAlign.ToString().Contains("Left"))
                    {
                        rrRectangle.X = _Picon.Width + Padding.Left + 5;
                    }
                }
                else if (_iconPosition.ToString().Contains("Right"))
                {
                    locX = ClientRectangle.Width - _Picon.Width - 5 - Padding.Right;
                    if ((ClientRectangle.Width - getSize[1]) / 2 < _Picon.Width + 5 + Padding.Right ||
                        _textAlign.ToString().Contains("Right"))
                    {
                        rrRectangle.X = -_Picon.Width - Padding.Right + 5;
                    }
                }
                else if (_iconPosition.ToString().Contains("Top"))
                {
                    locY = 5 + Padding.Top;
                    if (selisihV < _Picon.Height + 5 + Padding.Top)
                    {
                        rrRectangle.Y = _Picon.Height + Padding.Top - selisihV;
                    }
                    if (_textAlign.ToString().Contains("Top"))
                    {
                        rrRectangle.Y = _Picon.Height + 5 + Padding.Top;
                    }
                }
                else if (_iconPosition.ToString().Contains("Bottom"))
                {
                    locY = ClientRectangle.Height - _Picon.Width - 5 - Padding.Bottom;
                    if (selisihV < _Picon.Width + 5 + Padding.Right ||
                        _textAlign.ToString().Contains("Bottom"))
                    {
                        rrRectangle.Y = -_Picon.Width - Padding.Right + 5;
                    }
                }

                pbBox.Location              = new Point(locX, locY);
                pbBox.Size                  = new Size(_Picon.Width, _Picon.Height);
                pbBox.BackgroundImage       = _Picon;
                pbBox.BackgroundImageLayout = ImageLayout.Stretch;
                Controls.Add(pbBox);
                pbBox.BringToFront();
            }

            using (StringFormat sf = new StringFormat()
            {
                LineAlignment = verAlgnmt,
                Alignment = horAlgnmt
            })
                using (Brush brush = new SolidBrush(ForeColor))
                    e.Graphics.DrawString(Text, newFont, brush, rrRectangle, sf);
            base.OnPaint(e);
        }
        protected void CropAndDrawImageToTileSet(Bitmap image, ContentAlignment alignment = ContentAlignment.BottomCenter)
        {
            Bitmap rightSizeImage       = null;
            bool   rightSizeImageNeeded = false;

            try
            {
                if (image.Width > Program.MaxTileSize.Width || image.Height > Program.MaxTileSize.Height)
                {
                    int x = 0;
                    if (alignment == ContentAlignment.TopCenter || alignment == ContentAlignment.MiddleCenter || alignment == ContentAlignment.BottomCenter)
                    {
                        x = (image.Width - Program.MaxTileSize.Width) / 2; //Align Horizontally: Center
                    }
                    else if (alignment == ContentAlignment.TopLeft || alignment == ContentAlignment.MiddleLeft || alignment == ContentAlignment.BottomLeft)
                    {
                        x = 0; //Align Horizontally: Left
                    }
                    else if (alignment == ContentAlignment.TopRight || alignment == ContentAlignment.MiddleRight || alignment == ContentAlignment.BottomRight)
                    {
                        x = image.Width - Program.MaxTileSize.Width; //Align Horizontally: Right
                    }
                    else
                    {
                        throw new NotImplementedException(string.Format("Horizontal Alignment in '{0}' not implemented.", alignment.ToString()));
                    }

                    int y = 0;
                    if (alignment == ContentAlignment.BottomCenter || alignment == ContentAlignment.BottomLeft || alignment == ContentAlignment.BottomRight)
                    {
                        y = image.Height - Program.MaxTileSize.Height; //Align Vertically: Bottom
                    }
                    else if (alignment == ContentAlignment.TopCenter || alignment == ContentAlignment.TopLeft || alignment == ContentAlignment.TopRight)
                    {
                        y = 0; //Align Vertically: Top
                    }
                    else if (alignment == ContentAlignment.MiddleCenter || alignment == ContentAlignment.MiddleLeft || alignment == ContentAlignment.MiddleRight)
                    {
                        y = (image.Height - Program.MaxTileSize.Height) / 2; //Align Vertically: Middle
                    }
                    else
                    {
                        throw new NotImplementedException(string.Format("Vertical Alignment in '{0}' not implemented.", alignment.ToString()));
                    }

                    Rectangle rec = new Rectangle(new Point(x, y), Program.MaxTileSize);
                    rightSizeImage       = image.Clone(rec, image.PixelFormat);
                    rightSizeImageNeeded = true;
                }
                else
                {
                    rightSizeImage = image;
                }

                DrawImageToTileSet(rightSizeImage);
            }
            finally
            {
                if (rightSizeImageNeeded)
                {
                    rightSizeImage.Dispose();
                }
            }
        }
示例#18
0
 private static XmlNode createPageLabelNode(XmlDocument doc, Point location, System.Drawing.Size size, ContentAlignment align, string format, string text)
 {
     XmlNode source = doc.CreateElement("pagelabel");
     setLocationAttribute(source, location);
     setSizeAttribute(source, size);
     XmlFunc.setStringAttribute(source, "TextAlign", align.ToString());
     XmlFunc.setStringAttribute(source, "PageFormat", format);
     XmlFunc.setStringAttribute(source, "Text", text);
     return source;
 }
示例#19
0
 private XmlNode createLabelNode(XmlDocument doc, Point location, System.Drawing.Size size, ContentAlignment align, string text)
 {
     XmlNode source = doc.CreateElement("label");
     this.setLocationAttribute(source, location);
     this.setSizeAttribute(source, size);
     XmlFunc.setStringAttribute(source, "TextAlign", align.ToString());
     XmlFunc.setStringAttribute(source, "Text", text);
     XmlFunc.setStringAttribute(source, "Font", "Courier New, 9pt");
     return source;
 }
示例#20
0
		static internal void SaveXmlAlignment(XmlDocument doc, XmlElement newElement, ContentAlignment alignment)
		{
			newElement.SetAttribute("Value", alignment.ToString());
		}