0

I am trying to create a new component. when I try to draw an edge around this component, there is a load overload. I would appreciate if you help.

FillBorderRentangle Extentions Code

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 Code:

        [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;
            }
        }

here are the codes for the component

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

as a result:

enter image description here

the resulting error:

MinaXTextBox.cs (158, 22): [CS0121] [Şu001] The call is ambiguous among the following methods or features: 'MinaX.Extensions.BorderHelper.FillBorder (System.Drawing.Graphics, System.Drawing.Color, int, System.Windows. Forms.BorderStyle) 'and' MinaX.Extensions.BorderHelper.FillBorder (System.Drawing.Graphics, System.Drawing.Color, int, System.Windows.Forms.BorderStyle) '

KdrGny
  • 140
  • 11
  • It's hard to understand the purpose of this code (and the objects it uses). Are you trying to draw a border around a TextBox? – Jimi Feb 29 '20 at 17:27
  • I am trying to draw a frame outside the text box. https://stackoverflow.com/questions/42077126/outer-glow-rounded-corners-textbox like here – KdrGny Feb 29 '20 at 17:39
  • Do you mean TextBox with a border thickness > 2, rounded corners and a glow effect? Or just a colored border of 1 and a half pixels? You can get near that with a UserControls that uses a TextBox as the editing component and draw a semi-transparent bitmap in the background. See this, for example: [Creating different brush patterns](https://stackoverflow.com/a/49298313/7444103). For the rounded corners you need to create a rounded Region that allows antialiasing. See [here](https://stackoverflow.com/a/54794097/7444103) for example. – Jimi Feb 29 '20 at 18:05
  • To draw the inner border, in WinForms it's common to override WndProc, trap WM_PAINT and use [ControlPaint.DrawBorder](https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.controlpaint.drawborder) to draw a border different than the standard in a TextBox. The outer border is trivial, also already included in the sample code related to the UserControl with rounded borders already linked. Btw, for the *glowing effect, you can also use something like this: [Snipping tool laggy highlighter](https://stackoverflow.com/a/48899431/7444103), choosing the right alpha for the color. – Jimi Feb 29 '20 at 18:08
  • The hard part is to correctly *blend* the TextBox inside the UserControl. You're better off with a RichTextBox, since you can more easily control the internal padding. You can also expand the default implementation, modifying the base RichEdit control's behavior. [This](https://stackoverflow.com/a/47470191/7444103), for example, is an *extended* RichTextBox control where the Block Align (full text justification) capability has been re-enabled. – Jimi Feb 29 '20 at 18:16
  • as a result it should be like the picture above when it is active. – KdrGny Feb 29 '20 at 18:29
  • You posted code, but you didn't tell us what is the issue you are having with the code. – LarsTech Feb 29 '20 at 18:48
  • MinaXTextBox.cs (158, 22): [CS0121] [Şu001] The call is ambiguous among the following methods or features: 'MinaX.Extensions.BorderHelper.FillBorder (System.Drawing.Graphics, System.Drawing.Color, int, System.Windows. Forms.BorderStyle) 'and' MinaX.Extensions.BorderHelper.FillBorder (System.Drawing.Graphics, System.Drawing.Color, int, System.Windows.Forms.BorderStyle) ' – KdrGny Feb 29 '20 at 18:58
  • You seem to have a FillBorder duplicate somewhere. Not sure how you did that. Do a search in your code for FillBorder. Your use of a temporary Panel control is unnecessary, and not very useful, and probably even problematic. You didn't document FillBorderRectangle. Avoid using CreateGraphics at all cost. – LarsTech Feb 29 '20 at 19:49
  • yes I had more than one FillBorder code. I removed the other code and deleted the CreateGraphics code, but the error continues. – KdrGny Feb 29 '20 at 20:05

0 Answers0