Home > Net >  Custom pictureBox control problem
Custom pictureBox control problem

Time:04-30

From the Internet to find a custom pictureBox control code, the purpose of this code is to put the pictureBox control into a round shape, the code is on the net, inherited pictureBox class overrides the OnCreateControl method and the OnPaint, my understanding is to join in the engineering MyPictureBox class, call MyPictureBox OnPaint method of a class in the main form, refer to the code on the net, I use the computer to try, I use the computer code is as follows:

using System;
using System.Collections.Generic;
Using System. Linq;
using System.Text;
Using System. The Threading. The Tasks;
Using System. Drawing;
Using System. Drawing. Drawing2D;



The namespace WindowsFormsApp3
{
The class MyPictureBox: PictureBox
{
Protected override void OnCreateControl ()
{
A Rectangle rec=new Rectangle (0, 0, 72, 72);
GraphicsPath gp=new GraphicsPath ();
Gp. AddEllipse (rec);
//gp. AddEllipse (enclosing ClientRectangle);
Region Region=new Region (gp);
Enclosing Region=Region;
Gp. The Dispose ();
Region. The Dispose ();
Base. OnCreateControl ();
}
Protected override void OnPaint (PaintEventArgs PE)
{
Base. The OnPaint (PE);
A Rectangle rec=new Rectangle (0, 0, 72, 72);
Var g=PE. Graphics;
G.S moothingMode=SmoothingMode. AntiAlias;
G.I nterpolationMode=InterpolationMode. HighQualityBicubic;
G.Com positingQuality=CompositingQuality. HighQuality;
G.D rawEllipse (Pens. White, rec);
}
}

}

The compiled some exceptions:

Severity code shows the project file line prohibits display status
Error CS0246 failed to find the type or namespace name "PictureBox (whether the lack of a using directive or assembly reference?) WindowsFormsApp3 E: \ \ c # drawing round button \ WindowsFormsApp3 \ WindowsFormsApp3 \ MyPictureBox cs 13 activity

Severity code shows the project file line prohibits display status
Error CS0115 "MyPictureBox OnCreateControl () :" did not find the right way to rewrite WindowsFormsApp3 E: \ \ c # drawing round button \ WindowsFormsApp3 \ WindowsFormsApp3 \ MyPictureBox cs 15 activities of

Severity code shows the project file line prohibits display status
Error CS0115 "MyPictureBox OnPaint (PaintEventArgs)" : did not find the right way to rewrite WindowsFormsApp3 E: \ \ c # drawing round button \ WindowsFormsApp3 \ WindowsFormsApp3 \ MyPictureBox cs activity of 27


Severity code shows the project file line prohibits display status
Error CS0246 failed to find the type or namespace name "PaintEventArgs" (whether the lack of a using directive or assembly reference?) WindowsFormsApp3 E: \ \ c # drawing round button \ WindowsFormsApp3 \ WindowsFormsApp3 \ MyPictureBox cs activity of 27

Severity code shows the project file line prohibits display status
Error CS0201 only the assignment, the call, increment and decrement, await and new object expression can be used as a statement WindowsFormsApp3 E: \ \ c # drawing round button \ WindowsFormsApp3 \ WindowsFormsApp3 \ Form1 cs 22 activity

Severity code shows the project file line prohibits display status
Error CS0122 "MyPictureBox OnPaint (PaintEventArgs)" inaccessible, because it has a certain level of protection WindowsFormsApp3 E: \ \ c # drawing round button \ WindowsFormsApp3 \ WindowsFormsApp3 \ Form1 cs 22 activity

Severity code shows the project file line prohibits display status
Error CS1061 "MyPictureBox" does not contain the definition of "Region", and couldn't find an acceptable first "MyPictureBox" type parameters can be accessed extension method "Region" (whether the lack of a using directive or assembly reference?) WindowsFormsApp3 E: \ \ c # drawing round button \ WindowsFormsApp3 \ WindowsFormsApp3 \ MyPictureBox cs 22 activity

Can you tell me why?

CodePudding user response:

The east should be can't control it, it is finished, paint what panel, picbox, the button can be
 
Public static GraphicsPath DrawRoundRect (int x, int y, int width, int height, radius, int)
{
//edges rounded
GraphicsPath gp=new GraphicsPath ();
Gp. AddArc (x, y, the radius, the radius, 180, 90);
Gp. AddArc (width - the radius, y, the radius, the radius, 270, 90);
Gp. AddArc (width - the radius, height - the radius, the radius, the radius, 0, 90);
Gp. AddArc (x, height - the radius, the radius, the radius, 90, 90);
Gp. CloseAllFigures ();
Return gp;
}

//the panel paint
Private void panel1_Paint (object sender, PaintEventArgs e)
{
The Draw (e.c. with our fabrication: lipRectangle, um participant raphics, 18, true, Color. FromArgb (90, 143, 0), Color, FromArgb (41, 67, 0));
Base. The OnPaint (e);
Graphics g=um participant raphics;
G.D rawString (" I was in fact a Panel, "the new Font (" Microsoft elegant black," 9, FontStyle. Regular), new SolidBrush (Color. White), new PointF (10, 10));
}

CodePudding user response:

It should be no references or wrong version

CodePudding user response:

System. Windows Forms

CodePudding user response:

Demo:
 
Public void DrawRoundRect (Graphics g, Pen p, float X, float Y, float width, float height, radius, float)
{
//edges rounded
System. Drawing. Drawing2D. GraphicsPath gp=new System. Drawing. Drawing2D. GraphicsPath ();
Gp. AddLine (X + radius, Y, X + width - radius, (* 2), Y);
Gp. AddArc (X + width - radius, (* 2), Y, and the radius * 2, the radius * 2, 270, 90);
Gp. AddLine (X + width, Y + radius, X + width, Y + height - radius, (* 2));
Gp. AddArc (X + width - radius, (* 2), Y + height - radius, (* 2), the radius * 2, the radius * 2, 0, 90);
Gp. AddLine (X + width - radius, (* 2), Y + height, X + radius, Y + height);
Gp. AddArc (X, Y + height - radius, (* 2), the radius * 2, the radius * 2, 90, 90);
Gp. AddLine (X, Y + height - radius, (* 2), X, Y + radius);
Gp. AddArc (X, Y, the radius * 2, the radius * 2, 180, 90);
Gp. CloseFigure ();
G.D rawPath (p, gp);
Gp. The Dispose ();
}

Private void pictureBox1_Paint (object sender, PaintEventArgs e)
{
DrawRoundRect (um participant raphics, Pens. Black, 0, 0, pictureBox1. Width 1, pictureBox1. The Height of 1, 10);
}


nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#
  • Related