Skip to content

Commit

Permalink
DNS Changer v1.0.0
Browse files Browse the repository at this point in the history
Committed project files.
  • Loading branch information
NobakhtNet committed Sep 4, 2023
1 parent f5f44a3 commit ee626e3
Show file tree
Hide file tree
Showing 34 changed files with 1,960 additions and 0 deletions.
21 changes: 21 additions & 0 deletions DNS Changer/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="DNS_Changer.Data" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
<userSettings>
<DNS_Changer.Data>
<setting name="IP1" serializeAs="String">
<value />
</setting>
<setting name="IP2" serializeAs="String">
<value />
</setting>
</DNS_Changer.Data>
</userSettings>
</configuration>
36 changes: 36 additions & 0 deletions DNS Changer/CustomPanel.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

149 changes: 149 additions & 0 deletions DNS Changer/CustomPanel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
using System.Drawing.Drawing2D;
using System.Drawing;
using System.Windows.Forms;

namespace DNS_Changer
{
public partial class CustomPanel : Panel
{
private Panel panel;

private Color borderColor = Color.MediumSlateBlue;
private Color borderFocusColor = Color.HotPink;
private int borderSize = 2;
private bool underlinedStyle = false;
private bool isFocused = false;

private int borderRadius = 0;


public Color BorderColor
{
get { return borderColor; }
set
{
borderColor = value;
this.Invalidate();
}
}

public Color BorderFocusColor
{
get { return borderFocusColor; }
set { borderFocusColor = value; }
}

public int BorderSize
{
get { return borderSize; }
set
{
if (value >= 1)
{
borderSize = value;
this.Invalidate();
}
}
}

public bool UnderlinedStyle
{
get { return underlinedStyle; }
set
{
underlinedStyle = value;
this.Invalidate();
}
}

public override Color ForeColor
{
get { return base.ForeColor; }
set
{
base.ForeColor = value;
panel.ForeColor = value;
}
}


public int BorderRadius
{
get { return borderRadius; }
set
{
if (value >= 0)
{
borderRadius = value;
this.Invalidate();//Redraw control
}
}
}

protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics graph = e.Graphics;

if (borderRadius > 1)//Rounded TextBox
{
//-Fields
var rectBorderSmooth = this.ClientRectangle;
var rectBorder = Rectangle.Inflate(rectBorderSmooth, -borderSize, -borderSize);
int smoothSize = borderSize > 0 ? borderSize : 1;

using (GraphicsPath pathBorderSmooth = GetFigurePath(rectBorderSmooth, borderRadius))
using (GraphicsPath pathBorder = GetFigurePath(rectBorder, borderRadius - borderSize))
using (Pen penBorderSmooth = new Pen(this.Parent.BackColor, smoothSize))
using (Pen penBorder = new Pen(borderColor, borderSize))
{
//-Drawing
this.Region = new Region(pathBorderSmooth);//Set the rounded region of UserControl
if (borderRadius > 15) SetTextBoxRoundedRegion();//Set the rounded region of TextBox component
graph.SmoothingMode = SmoothingMode.AntiAlias;
penBorder.Alignment = System.Drawing.Drawing2D.PenAlignment.Center;
if (isFocused) penBorder.Color = borderFocusColor;

if (underlinedStyle) //Line Style
{
//Draw border smoothing
graph.DrawPath(penBorderSmooth, pathBorderSmooth);
//Draw border
graph.SmoothingMode = SmoothingMode.None;
graph.DrawLine(penBorder, 0, this.Height - 1, this.Width, this.Height - 1);
}
else //Normal Style
{
//Draw border smoothing
graph.DrawPath(penBorderSmooth, pathBorderSmooth);
//Draw border
graph.DrawPath(penBorder, pathBorder);
}
}
}
}
private void SetTextBoxRoundedRegion()
{
GraphicsPath pathTxt;


pathTxt = GetFigurePath(panel.ClientRectangle, borderSize * 2);
panel.Region = new Region(pathTxt);

pathTxt.Dispose();
}
private GraphicsPath GetFigurePath(Rectangle rect, int radius)
{
GraphicsPath path = new GraphicsPath();
float curveSize = radius * 2F;

path.StartFigure();
path.AddArc(rect.X, rect.Y, curveSize, curveSize, 180, 90);
path.AddArc(rect.Right - curveSize, rect.Y, curveSize, curveSize, 270, 90);
path.AddArc(rect.Right - curveSize, rect.Bottom - curveSize, curveSize, curveSize, 0, 90);
path.AddArc(rect.X, rect.Bottom - curveSize, curveSize, curveSize, 90, 90);
path.CloseFigure();
return path;
}
}
}
Loading

0 comments on commit ee626e3

Please sign in to comment.