Перегрузка при добавлении границы в текстовое поле [CS0121] - PullRequest
0 голосов
/ 29 февраля 2020

Я пытаюсь создать новый компонент. когда я пытаюсь нарисовать край вокруг этого компонента, возникает перегрузка нагрузки. Буду признателен, если вы поможете.

Код расширения FillBorderRentangle

private static GraphicsPath GenerateRoundedRectangle(this Graphics graphics, RectangleF rectangle, float radius, RectangleEdgeFilter filter){
            float diameter;
            graphics.SmoothingMode = SmoothingMode.AntiAlias;
            GraphicsPath path = new GraphicsPath();
            if(radius <= 0.0F || filter == RectangleEdgeFilter.None) {
                path.AddRectangle(rectangle);
                path.CloseFigure();
                return path;
            } else {
                if(radius >= (Math.Min(rectangle.Width, rectangle.Height)) / 2.0)
                    return graphics.GenerateCapsule(rectangle);
                diameter = radius * 2.0F;
                SizeF sizeF = new SizeF(diameter, diameter);
                RectangleF arc = new RectangleF(rectangle.Location, sizeF);
                if((RectangleEdgeFilter.TopLeft & filter) == RectangleEdgeFilter.TopLeft)
                    path.AddArc(arc, 180, 90);
                else {
                    path.AddLine(arc.X, arc.Y + arc.Height, arc.X, arc.Y);
                    path.AddLine(arc.X, arc.Y, arc.X + arc.Width, arc.Y);
                }
                arc.X = rectangle.Right - diameter;
                if((RectangleEdgeFilter.TopRight & filter) == RectangleEdgeFilter.TopRight)
                    path.AddArc(arc, 270, 90);
                else {
                    path.AddLine(arc.X, arc.Y, arc.X + arc.Width, arc.Y);
                    path.AddLine(arc.X + arc.Width, arc.Y + arc.Height, arc.X + arc.Width, arc.Y);
                }
                arc.Y = rectangle.Bottom - diameter;
                if((RectangleEdgeFilter.BottomRight & filter) == RectangleEdgeFilter.BottomRight)
                    path.AddArc(arc, 0, 90);
                else {
                    path.AddLine(arc.X + arc.Width, arc.Y, arc.X + arc.Width, arc.Y + arc.Height);
                    path.AddLine(arc.X, arc.Y + arc.Height, arc.X + arc.Width, arc.Y + arc.Height);
                }
                arc.X = rectangle.Left;
                if((RectangleEdgeFilter.BottomLeft & filter) == RectangleEdgeFilter.BottomLeft)
                    path.AddArc(arc, 90, 90);
                else {
                    path.AddLine(arc.X + arc.Width, arc.Y + arc.Height, arc.X, arc.Y + arc.Height);
                    path.AddLine(arc.X, arc.Y + arc.Height, arc.X, arc.Y);
                }
                path.CloseFigure();
            }
            return path;
        }
 private static void FillRoundedRectangle(this Graphics graphics, Brush brush, float x, float y, float width, float height, float radius, RectangleEdgeFilter filter){
            RectangleF rectangle = new RectangleF(x, y, width, height);
            GraphicsPath path = graphics.GenerateRoundedRectangle(rectangle, radius, filter);
            SmoothingMode old = graphics.SmoothingMode;
            graphics.SmoothingMode = SmoothingMode.AntiAlias;
            graphics.FillPath(brush, path);
            graphics.SmoothingMode = old;
        }
 public static void FillRoundedRectangle(this Graphics graphics, Brush brush, Rectangle rectangle, int radius){
            graphics.FillRoundedRectangle(brush, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, radius, RectangleEdgeFilter.All);
        }

Код BorderHelper:

        [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Winapi)]
        private static extern IntPtr GetFocus();
        public static void FillBorder(this Graphics g, Color color, int borderSize, BorderStyle style){
            var pan = new Panel();
            g = pan.CreateGraphics();
            g.FillBorderRectangle(new SolidBrush(color), pan.Size, pan.Location, 5);
            pan.BorderStyle = style;
            pan.Size = new Size(GetControl.Width + borderSize * 2, GetControl.Height + borderSize * 2);
            pan.Location = new Point(GetControl.Left - borderSize, GetControl.Top - borderSize);
            pan.BackColor = color;
            pan.Parent = GetControl.Parent;
            GetControl.Parent = pan;
            GetControl.Location = new Point(borderSize, borderSize);
            pan.Dispose();
        }
        private static Control GetControl{
            get {
                Control focusControl = null;
                IntPtr focusHandle = GetFocus();
                if(focusHandle != IntPtr.Zero)
                    focusControl = Control.FromHandle(focusHandle);
                return focusControl;
            }
        }

Вот коды для компонента

public class MinaXTextBox : Control, IControl{
 protected override void OnPaint(PaintEventArgs e){
            var g = e.Graphics;
             if(_textActive) 
                    g.FillBorder(Color.Red,5,BorderStyle.None);
   }
}

в результате:

enter image description here

Полученная ошибка:

MinaXTextBox.cs (158, 22): [CS0121] [Şu001] Вызов неоднозначен среди следующих методов или функций: 'MinaX.Extensions.BorderHelper.FillBorder (System.Drawing.Graphics, System.Drawing.Color, int, System. Windows. Forms.BorderStyle) 'и' MinaX.Extensions.BorderHelper.FillBorder (System.Drawing.Graphics, System.Drawing.Color, int, System. Windows .Forms.BorderStyle) '

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...