Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

Custom Circular Picture Box C# win Form app

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
namespace RashiUI
{
class RashiCircularPictureBox:PictureBox
{
private int border = 2;
private Color colorBorder = Color.RoyalBlue;
private Color colorBorder2 = Color.HotPink;
private DashStyle borderstyle = DashStyle.Solid;
private DashCap borderCap = DashCap.Flat;
private float gradiant = 50f;
public RashiCircularPictureBox()
{
this.Size = new Size(95, 95);
this.SizeMode = PictureBoxSizeMode.StretchImage;
}
public int Border
{
get
{
return border;
}
set
{
border = value;
this.Invalidate();
}
}
public Color ColorBorder
{
get
{
return colorBorder;
}
set
{
colorBorder = value;
this.Invalidate();
}
}
public Color ColorBorder2
{
get
{
return colorBorder2;
}
set
{
colorBorder2 = value;
this.Invalidate();
}
}
public DashStyle Borderstyle
{
get
{
return borderstyle;
}
set
{
borderstyle = value;
this.Invalidate();
}
}
public DashCap BorderCap
{
get
{
return borderCap;
}
set
{
borderCap = value;
this.Invalidate();
}
}
public float Gradiant
{
get
{
return gradiant;
}
set
{
gradiant = value;
this.Invalidate();
}
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
this.Size = new Size(this.Width, this.Width);
}
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
var graphic = pe.Graphics;
var rect = Rectangle.Inflate(this.ClientRectangle, -1, -1);
var rectborder = Rectangle.Inflate(rect, -border, -border);
var size = border > 0 ? border * 3 : 1;
using (var bordercolorG = new LinearGradientBrush(rectborder, colorBorder, colorBorder2, gradiant))
using (var path = new GraphicsPath())
using (var pen = new Pen(this.Parent.BackColor, border))
using (var penborder = new Pen(bordercolorG, size))
{
graphic.SmoothingMode = SmoothingMode.AntiAlias;
penborder.DashStyle = borderstyle;
penborder.DashCap = borderCap;
path.AddEllipse(rect);
this.Region = new Region(path);
graphic.DrawEllipse(pen, rect);
if (border>0)
{
graphic.DrawEllipse(penborder, rectborder);
}
}
}
 
}
}Copy
Comment

PREVIOUS NEXT
Code Example
Csharp :: lambda not null c# 
Csharp :: c# use meditor from service 
Csharp :: wpf clock conrt 
Csharp :: c# check if pdf is protected without password 
Csharp :: c# check if file is zero bytes 
Csharp :: c# how to return 2 strings 
Csharp :: Untiy particle system play 
Csharp :: unity eventtrigger blocks scrollview 
Csharp :: "??" in C# 
Csharp :: CS0234 compile error c# unity fix scene managment 
Csharp :: Display the elements in an array one at a time using getkeydown in unity 
Csharp :: Focus on last entry in listbox 
Csharp :: get path revit link unloaded 
Csharp :: shell32.dll c# example 
Csharp :: vb.net substring after character 
Csharp :: The anti-forgery cookie token and form field token do not match. 
Csharp :: AR light estimation Unity 
Csharp :: unity download image from online 
Csharp :: c# cosmos db add items into container 
Csharp :: C# if with obj params 
Csharp :: using selected item in listbox c# to fill texbox 
Csharp :: stack in c# 
Csharp :: c# replace characters in string that are invalid using regex 
Csharp :: get centerpoint of points transforms 
Csharp :: ArgumentOutOfRangeException when sorting a DataGridView using a custom IComparer 
Csharp :: ismirrored c# 
Csharp :: vb.net ionic zip examples 
Csharp :: how to input data several times in c# 
Csharp :: C# Blocks without statements 
Csharp :: c# convert string to datetime any format 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =