Added from Code Project
BIN
.vs/ToggleSwitch/v16/.suo
Normal file
BIN
Image70.png
Normal file
After Width: | Height: | Size: 322 B |
BIN
Images/060511_Switches.jpg
Normal file
After Width: | Height: | Size: 19 KiB |
BIN
Images/060511_Switches.psd
Normal file
BIN
Images/checkbox.psd
Normal file
BIN
Images/checkbox2.psd
Normal file
BIN
Images/checkbox3.psd
Normal file
BIN
Images/checkbox3b.psd
Normal file
BIN
Images/checkbox_off.png
Normal file
After Width: | Height: | Size: 9.6 KiB |
BIN
Images/checkbox_off3.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
Images/checkbox_on.png
Normal file
After Width: | Height: | Size: 9.6 KiB |
BIN
Images/checkbox_on2.png
Normal file
After Width: | Height: | Size: 7.0 KiB |
BIN
Images/checkbox_on3.png
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
ToggleSwitch.bmp
Normal file
After Width: | Height: | Size: 822 B |
BIN
ToggleSwitch.png
Normal file
After Width: | Height: | Size: 396 B |
28
ToggleSwitch.sln
Normal file
|
@ -0,0 +1,28 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2013
|
||||
VisualStudioVersion = 12.0.40629.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ToggleSwitch", "ToggleSwitch\ToggleSwitch.csproj", "{49B88FFA-F02C-4709-BA65-9F8996444ECD}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ToggleSwitchDemo", "ToggleSwitchDemo\ToggleSwitchDemo.csproj", "{2F7ADBD8-EC70-4407-8B09-474E8F2043AC}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{49B88FFA-F02C-4709-BA65-9F8996444ECD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{49B88FFA-F02C-4709-BA65-9F8996444ECD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{49B88FFA-F02C-4709-BA65-9F8996444ECD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{49B88FFA-F02C-4709-BA65-9F8996444ECD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{2F7ADBD8-EC70-4407-8B09-474E8F2043AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2F7ADBD8-EC70-4407-8B09-474E8F2043AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2F7ADBD8-EC70-4407-8B09-474E8F2043AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{2F7ADBD8-EC70-4407-8B09-474E8F2043AC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
16
ToggleSwitch/GraphicsExtensionMethods.cs
Normal file
|
@ -0,0 +1,16 @@
|
|||
using System.Drawing;
|
||||
|
||||
namespace JCS
|
||||
{
|
||||
public static class GraphicsExtensionMethods
|
||||
{
|
||||
public static Color ToGrayScale(this Color originalColor)
|
||||
{
|
||||
if (originalColor.Equals(Color.Transparent))
|
||||
return originalColor;
|
||||
|
||||
int grayScale = (int)((originalColor.R * .299) + (originalColor.G * .587) + (originalColor.B * .114));
|
||||
return Color.FromArgb(grayScale, grayScale, grayScale);
|
||||
}
|
||||
}
|
||||
}
|
52
ToggleSwitch/ImageHelper.cs
Normal file
|
@ -0,0 +1,52 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
|
||||
namespace ToggleSwitch
|
||||
{
|
||||
public static class ImageHelper
|
||||
{
|
||||
private static float[][] _colorMatrixElements = {
|
||||
new float[] {(float)0.299, (float)0.299, (float)0.299, 0, 0},
|
||||
new float[] {(float)0.587, (float)0.587, (float)0.587, 0, 0},
|
||||
new float[] {(float)0.114, (float)0.114, (float)0.114, 0, 0},
|
||||
new float[] {0, 0, 0, 1, 0},
|
||||
new float[] {0, 0, 0, 0, 1}
|
||||
};
|
||||
|
||||
private static ColorMatrix _grayscaleColorMatrix = new ColorMatrix(_colorMatrixElements);
|
||||
|
||||
public static ImageAttributes GetGrayscaleAttributes()
|
||||
{
|
||||
ImageAttributes attr = new ImageAttributes();
|
||||
attr.SetColorMatrix(_grayscaleColorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
|
||||
return attr;
|
||||
}
|
||||
|
||||
public static Size RescaleImageToFit(Size imageSize, Size canvasSize)
|
||||
{
|
||||
//Code "borrowed" from http://stackoverflow.com/questions/1940581/c-sharp-image-resizing-to-different-size-while-preserving-aspect-ratio
|
||||
// and the Math.Min improvement from http://stackoverflow.com/questions/6501797/resize-image-proportionally-with-maxheight-and-maxwidth-constraints
|
||||
|
||||
// Figure out the ratio
|
||||
double ratioX = (double)canvasSize.Width / (double)imageSize.Width;
|
||||
double ratioY = (double)canvasSize.Height / (double)imageSize.Height;
|
||||
|
||||
// use whichever multiplier is smaller
|
||||
double ratio = Math.Min(ratioX, ratioY);
|
||||
|
||||
// now we can get the new height and width
|
||||
int newHeight = Convert.ToInt32(imageSize.Height * ratio);
|
||||
int newWidth = Convert.ToInt32(imageSize.Width * ratio);
|
||||
|
||||
Size resizedSize = new Size(newWidth, newHeight);
|
||||
|
||||
if (resizedSize.Width > canvasSize.Width || resizedSize.Height > canvasSize.Height)
|
||||
{
|
||||
throw new Exception("ImageHelper.RescaleImageToFit - Resize failed!");
|
||||
}
|
||||
|
||||
return resizedSize;
|
||||
}
|
||||
}
|
||||
}
|
36
ToggleSwitch/Properties/AssemblyInfo.cs
Normal file
|
@ -0,0 +1,36 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("ToggleSwitch")]
|
||||
[assembly: AssemblyDescription("JCS ToggleSwitch Control Library")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("JC Software Solutions")]
|
||||
[assembly: AssemblyProduct("JCS ToggleSwitch")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2015")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("f1b1489e-7d6c-47ae-b71c-bb97ba895d96")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.1.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.1.0.0")]
|
14
ToggleSwitch/RendererChangedEventArgs.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
using JCS;
|
||||
|
||||
namespace ToggleSwitch
|
||||
{
|
||||
public class BeforeRenderingEventArgs
|
||||
{
|
||||
public ToggleSwitchRendererBase Renderer { get; set; }
|
||||
|
||||
public BeforeRenderingEventArgs(ToggleSwitchRendererBase renderer)
|
||||
{
|
||||
Renderer = renderer;
|
||||
}
|
||||
}
|
||||
}
|
295
ToggleSwitch/Renderers/ToggleSwitchAndroidRenderer.cs
Normal file
|
@ -0,0 +1,295 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using ToggleSwitch;
|
||||
|
||||
namespace JCS
|
||||
{
|
||||
public class ToggleSwitchAndroidRenderer : ToggleSwitchRendererBase
|
||||
{
|
||||
#region Constructor
|
||||
|
||||
public ToggleSwitchAndroidRenderer()
|
||||
{
|
||||
BorderColor = Color.FromArgb(255, 166, 166, 166);
|
||||
BackColor = Color.FromArgb(255, 32, 32, 32);
|
||||
LeftSideColor = Color.FromArgb(255, 32, 32, 32);
|
||||
RightSideColor = Color.FromArgb(255, 32, 32, 32);
|
||||
OffButtonColor = Color.FromArgb(255, 70, 70, 70);
|
||||
OnButtonColor = Color.FromArgb(255, 27, 161, 226);
|
||||
OffButtonBorderColor = Color.FromArgb(255, 70, 70, 70);
|
||||
OnButtonBorderColor = Color.FromArgb(255, 27, 161, 226);
|
||||
SlantAngle = 8;
|
||||
}
|
||||
|
||||
#endregion Constructor
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public Color BorderColor { get; set; }
|
||||
public Color BackColor { get; set; }
|
||||
public Color LeftSideColor { get; set; }
|
||||
public Color RightSideColor { get; set; }
|
||||
public Color OffButtonColor { get; set; }
|
||||
public Color OnButtonColor { get; set; }
|
||||
public Color OffButtonBorderColor { get; set; }
|
||||
public Color OnButtonBorderColor { get; set; }
|
||||
public int SlantAngle { get; set; }
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Render Method Implementations
|
||||
|
||||
public override void RenderBorder(Graphics g, Rectangle borderRectangle)
|
||||
{
|
||||
Color borderColor = !ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled ? BorderColor.ToGrayScale() : BorderColor;
|
||||
|
||||
g.SetClip(borderRectangle);
|
||||
|
||||
using (Pen borderPen = new Pen(borderColor))
|
||||
{
|
||||
g.DrawRectangle(borderPen, borderRectangle.X, borderRectangle.Y, borderRectangle.Width - 1, borderRectangle.Height - 1);
|
||||
}
|
||||
}
|
||||
|
||||
public override void RenderLeftToggleField(Graphics g, Rectangle leftRectangle, int totalToggleFieldWidth)
|
||||
{
|
||||
Color leftColor = LeftSideColor;
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
leftColor = leftColor.ToGrayScale();
|
||||
|
||||
Rectangle controlRectangle = GetInnerControlRectangle();
|
||||
|
||||
g.SetClip(controlRectangle);
|
||||
|
||||
int halfCathetusLength = GetHalfCathetusLengthBasedOnAngle();
|
||||
|
||||
Rectangle adjustedLeftRect = new Rectangle(leftRectangle.X, leftRectangle.Y, leftRectangle.Width + halfCathetusLength, leftRectangle.Height);
|
||||
|
||||
g.IntersectClip(adjustedLeftRect);
|
||||
|
||||
using (Brush leftBrush = new SolidBrush(leftColor))
|
||||
{
|
||||
g.FillRectangle(leftBrush, adjustedLeftRect);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
|
||||
public override void RenderRightToggleField(Graphics g, Rectangle rightRectangle, int totalToggleFieldWidth)
|
||||
{
|
||||
Color rightColor = RightSideColor;
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
rightColor = rightColor.ToGrayScale();
|
||||
|
||||
Rectangle controlRectangle = GetInnerControlRectangle();
|
||||
|
||||
g.SetClip(controlRectangle);
|
||||
|
||||
int halfCathetusLength = GetHalfCathetusLengthBasedOnAngle();
|
||||
|
||||
Rectangle adjustedRightRect = new Rectangle(rightRectangle.X - halfCathetusLength, rightRectangle.Y, rightRectangle.Width + halfCathetusLength, rightRectangle.Height);
|
||||
|
||||
g.IntersectClip(adjustedRightRect);
|
||||
|
||||
using (Brush rightBrush = new SolidBrush(rightColor))
|
||||
{
|
||||
g.FillRectangle(rightBrush, adjustedRightRect);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
|
||||
public override void RenderButton(Graphics g, Rectangle buttonRectangle)
|
||||
{
|
||||
Rectangle controlRectangle = GetInnerControlRectangle();
|
||||
|
||||
g.SetClip(controlRectangle);
|
||||
|
||||
int fullCathetusLength = GetCathetusLengthBasedOnAngle();
|
||||
int dblFullCathetusLength = 2*fullCathetusLength;
|
||||
|
||||
Point[] polygonPoints = new Point[4];
|
||||
|
||||
Rectangle adjustedButtonRect = new Rectangle(buttonRectangle.X - fullCathetusLength, controlRectangle.Y, buttonRectangle.Width + dblFullCathetusLength, controlRectangle.Height);
|
||||
|
||||
if (SlantAngle > 0)
|
||||
{
|
||||
polygonPoints[0] = new Point(adjustedButtonRect.X + fullCathetusLength, adjustedButtonRect.Y);
|
||||
polygonPoints[1] = new Point(adjustedButtonRect.X + adjustedButtonRect.Width - 1, adjustedButtonRect.Y);
|
||||
polygonPoints[2] = new Point(adjustedButtonRect.X + adjustedButtonRect.Width - fullCathetusLength - 1, adjustedButtonRect.Y + adjustedButtonRect.Height - 1);
|
||||
polygonPoints[3] = new Point(adjustedButtonRect.X, adjustedButtonRect.Y + adjustedButtonRect.Height - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
polygonPoints[0] = new Point(adjustedButtonRect.X, adjustedButtonRect.Y);
|
||||
polygonPoints[1] = new Point(adjustedButtonRect.X + adjustedButtonRect.Width - fullCathetusLength - 1, adjustedButtonRect.Y);
|
||||
polygonPoints[2] = new Point(adjustedButtonRect.X + adjustedButtonRect.Width - 1, adjustedButtonRect.Y + adjustedButtonRect.Height - 1);
|
||||
polygonPoints[3] = new Point(adjustedButtonRect.X + fullCathetusLength, adjustedButtonRect.Y + adjustedButtonRect.Height - 1);
|
||||
}
|
||||
|
||||
g.IntersectClip(adjustedButtonRect);
|
||||
|
||||
Color buttonColor = ToggleSwitch.Checked ? OnButtonColor : OffButtonColor;
|
||||
Color buttonBorderColor = ToggleSwitch.Checked ? OnButtonBorderColor : OffButtonBorderColor;
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
{
|
||||
buttonColor = buttonColor.ToGrayScale();
|
||||
buttonBorderColor = buttonBorderColor.ToGrayScale();
|
||||
}
|
||||
|
||||
using (Pen buttonPen = new Pen(buttonBorderColor))
|
||||
{
|
||||
g.DrawPolygon(buttonPen, polygonPoints);
|
||||
}
|
||||
|
||||
using (Brush buttonBrush = new SolidBrush(buttonColor))
|
||||
{
|
||||
g.FillPolygon(buttonBrush, polygonPoints);
|
||||
}
|
||||
|
||||
Image buttonImage = ToggleSwitch.ButtonImage ?? (ToggleSwitch.Checked ? ToggleSwitch.OnButtonImage : ToggleSwitch.OffButtonImage);
|
||||
string buttonText = ToggleSwitch.Checked ? ToggleSwitch.OnText : ToggleSwitch.OffText;
|
||||
|
||||
if (buttonImage != null || !string.IsNullOrEmpty(buttonText))
|
||||
{
|
||||
ToggleSwitch.ToggleSwitchButtonAlignment alignment = ToggleSwitch.ButtonImage != null ? ToggleSwitch.ButtonAlignment : (ToggleSwitch.Checked ? ToggleSwitch.OnButtonAlignment : ToggleSwitch.OffButtonAlignment);
|
||||
|
||||
if (buttonImage != null)
|
||||
{
|
||||
Size imageSize = buttonImage.Size;
|
||||
Rectangle imageRectangle;
|
||||
|
||||
int imageXPos = (int)adjustedButtonRect.X;
|
||||
|
||||
bool scaleImage = ToggleSwitch.ButtonImage != null ? ToggleSwitch.ButtonScaleImageToFit : (ToggleSwitch.Checked ? ToggleSwitch.OnButtonScaleImageToFit : ToggleSwitch.OffButtonScaleImageToFit);
|
||||
|
||||
if (scaleImage)
|
||||
{
|
||||
Size canvasSize = adjustedButtonRect.Size;
|
||||
Size resizedImageSize = ImageHelper.RescaleImageToFit(imageSize, canvasSize);
|
||||
|
||||
if (alignment == ToggleSwitch.ToggleSwitchButtonAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)adjustedButtonRect.X + (((float)adjustedButtonRect.Width - (float)resizedImageSize.Width) / 2));
|
||||
}
|
||||
else if (alignment == ToggleSwitch.ToggleSwitchButtonAlignment.Right)
|
||||
{
|
||||
imageXPos = (int)((float)adjustedButtonRect.X + (float)adjustedButtonRect.Width - (float)resizedImageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)adjustedButtonRect.Y + (((float)adjustedButtonRect.Height - (float)resizedImageSize.Height) / 2)), resizedImageSize.Width, resizedImageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(buttonImage, imageRectangle, 0, 0, buttonImage.Width, buttonImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImage(buttonImage, imageRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (alignment == ToggleSwitch.ToggleSwitchButtonAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)adjustedButtonRect.X + (((float)adjustedButtonRect.Width - (float)imageSize.Width) / 2));
|
||||
}
|
||||
else if (alignment == ToggleSwitch.ToggleSwitchButtonAlignment.Right)
|
||||
{
|
||||
imageXPos = (int)((float)adjustedButtonRect.X + (float)adjustedButtonRect.Width - (float)imageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)adjustedButtonRect.Y + (((float)adjustedButtonRect.Height - (float)imageSize.Height) / 2)), imageSize.Width, imageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(buttonImage, imageRectangle, 0, 0, buttonImage.Width, buttonImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImageUnscaled(buttonImage, imageRectangle);
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(buttonText))
|
||||
{
|
||||
Font buttonFont = ToggleSwitch.Checked ? ToggleSwitch.OnFont : ToggleSwitch.OffFont;
|
||||
Color buttonForeColor = ToggleSwitch.Checked ? ToggleSwitch.OnForeColor : ToggleSwitch.OffForeColor;
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
buttonForeColor = buttonForeColor.ToGrayScale();
|
||||
|
||||
SizeF textSize = g.MeasureString(buttonText, buttonFont);
|
||||
|
||||
float textXPos = adjustedButtonRect.X;
|
||||
|
||||
if (alignment == ToggleSwitch.ToggleSwitchButtonAlignment.Center)
|
||||
{
|
||||
textXPos = (float)adjustedButtonRect.X + (((float)adjustedButtonRect.Width - (float)textSize.Width) / 2);
|
||||
}
|
||||
else if (alignment == ToggleSwitch.ToggleSwitchButtonAlignment.Right)
|
||||
{
|
||||
textXPos = (float)adjustedButtonRect.X + (float)adjustedButtonRect.Width - (float)textSize.Width;
|
||||
}
|
||||
|
||||
RectangleF textRectangle = new RectangleF(textXPos, (float)adjustedButtonRect.Y + (((float)adjustedButtonRect.Height - (float)textSize.Height) / 2), textSize.Width, textSize.Height);
|
||||
|
||||
using (Brush textBrush = new SolidBrush(buttonForeColor))
|
||||
{
|
||||
g.DrawString(buttonText, buttonFont, textBrush, textRectangle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
|
||||
#endregion Render Method Implementations
|
||||
|
||||
#region Helper Method Implementations
|
||||
|
||||
public Rectangle GetInnerControlRectangle()
|
||||
{
|
||||
return new Rectangle(1, 1, ToggleSwitch.Width - 2, ToggleSwitch.Height - 2);
|
||||
}
|
||||
|
||||
public int GetCathetusLengthBasedOnAngle()
|
||||
{
|
||||
if (SlantAngle == 0)
|
||||
return 0;
|
||||
|
||||
double degrees = Math.Abs(SlantAngle);
|
||||
double radians = degrees * (Math.PI / 180);
|
||||
double length = Math.Tan(radians)*ToggleSwitch.Height;
|
||||
|
||||
return (int)length;
|
||||
}
|
||||
|
||||
public int GetHalfCathetusLengthBasedOnAngle()
|
||||
{
|
||||
if (SlantAngle == 0)
|
||||
return 0;
|
||||
|
||||
double degrees = Math.Abs(SlantAngle);
|
||||
double radians = degrees * (Math.PI / 180);
|
||||
double length = (Math.Tan(radians) * ToggleSwitch.Height) / 2;
|
||||
|
||||
return (int)length;
|
||||
}
|
||||
|
||||
public override int GetButtonWidth()
|
||||
{
|
||||
double buttonWidth = (double)ToggleSwitch.Width / 2;
|
||||
return (int) buttonWidth;
|
||||
}
|
||||
|
||||
public override Rectangle GetButtonRectangle()
|
||||
{
|
||||
int buttonWidth = GetButtonWidth();
|
||||
return GetButtonRectangle(buttonWidth);
|
||||
}
|
||||
|
||||
public override Rectangle GetButtonRectangle(int buttonWidth)
|
||||
{
|
||||
Rectangle buttonRect = new Rectangle(ToggleSwitch.ButtonValue, 0, buttonWidth, ToggleSwitch.Height);
|
||||
return buttonRect;
|
||||
}
|
||||
|
||||
#endregion Helper Method Implementations
|
||||
}
|
||||
}
|
483
ToggleSwitch/Renderers/ToggleSwitchBrushedMetalRenderer.cs
Normal file
|
@ -0,0 +1,483 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using ToggleSwitch;
|
||||
|
||||
namespace JCS
|
||||
{
|
||||
public class ToggleSwitchBrushedMetalRenderer : ToggleSwitchRendererBase
|
||||
{
|
||||
#region Constructor
|
||||
|
||||
public ToggleSwitchBrushedMetalRenderer()
|
||||
{
|
||||
BorderColor1 = Color.FromArgb(255, 145, 146, 149);
|
||||
BorderColor2 = Color.FromArgb(255, 227, 229, 232);
|
||||
BackColor1 = Color.FromArgb(255, 125, 126, 128);
|
||||
BackColor2 = Color.FromArgb(255, 224, 226, 228);
|
||||
UpperShadowColor1 = Color.FromArgb(150, 0, 0, 0);
|
||||
UpperShadowColor2 = Color.FromArgb(5, 0, 0, 0);
|
||||
ButtonNormalBorderColor = Color.FromArgb(255, 144, 144, 145);
|
||||
ButtonNormalSurfaceColor = Color.FromArgb(255, 251, 251, 251);
|
||||
ButtonHoverBorderColor = Color.FromArgb(255, 166, 167, 168);
|
||||
ButtonHoverSurfaceColor = Color.FromArgb(255, 238, 238, 238);
|
||||
ButtonPressedBorderColor = Color.FromArgb(255, 123, 123, 123);
|
||||
ButtonPressedSurfaceColor = Color.FromArgb(255, 184, 184, 184);
|
||||
|
||||
UpperShadowHeight = 8;
|
||||
}
|
||||
|
||||
#endregion Constructor
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public Color BorderColor1 { get; set; }
|
||||
public Color BorderColor2 { get; set; }
|
||||
public Color BackColor1 { get; set; }
|
||||
public Color BackColor2 { get; set; }
|
||||
public Color UpperShadowColor1 { get; set; }
|
||||
public Color UpperShadowColor2 { get; set; }
|
||||
public Color ButtonNormalBorderColor { get; set; }
|
||||
public Color ButtonNormalSurfaceColor { get; set; }
|
||||
public Color ButtonHoverBorderColor { get; set; }
|
||||
public Color ButtonHoverSurfaceColor { get; set; }
|
||||
public Color ButtonPressedBorderColor { get; set; }
|
||||
public Color ButtonPressedSurfaceColor { get; set; }
|
||||
|
||||
public int UpperShadowHeight { get; set; }
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Render Method Implementations
|
||||
|
||||
public override void RenderBorder(Graphics g, Rectangle borderRectangle)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
|
||||
|
||||
//Draw outer border
|
||||
using (GraphicsPath outerControlPath = GetRectangleClipPath(borderRectangle))
|
||||
{
|
||||
g.SetClip(outerControlPath);
|
||||
|
||||
Color borderColor1 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? BorderColor1.ToGrayScale() : BorderColor1;
|
||||
Color borderColor2 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? BorderColor2.ToGrayScale() : BorderColor2;
|
||||
|
||||
using (Brush borderBrush = new LinearGradientBrush(borderRectangle, borderColor1, borderColor2, LinearGradientMode.Vertical))
|
||||
{
|
||||
g.FillPath(borderBrush, outerControlPath);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
|
||||
//Draw inner background
|
||||
Rectangle innercontrolRectangle = new Rectangle(borderRectangle.X + 1, borderRectangle.Y + 1, borderRectangle.Width - 1, borderRectangle.Height - 2);
|
||||
|
||||
using (GraphicsPath innerControlPath = GetRectangleClipPath(innercontrolRectangle))
|
||||
{
|
||||
g.SetClip(innerControlPath);
|
||||
|
||||
Color backColor1 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? BackColor1.ToGrayScale() : BackColor1;
|
||||
Color backColor2 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? BackColor2.ToGrayScale() : BackColor2;
|
||||
|
||||
using (Brush backgroundBrush = new LinearGradientBrush(borderRectangle, backColor1, backColor2, LinearGradientMode.Horizontal))
|
||||
{
|
||||
g.FillPath(backgroundBrush, innerControlPath);
|
||||
}
|
||||
|
||||
//Draw inner top shadow
|
||||
Rectangle upperShadowRectangle = new Rectangle(innercontrolRectangle.X, innercontrolRectangle.Y, innercontrolRectangle.Width, UpperShadowHeight);
|
||||
|
||||
g.IntersectClip(upperShadowRectangle);
|
||||
|
||||
using (Brush shadowBrush = new LinearGradientBrush(upperShadowRectangle, UpperShadowColor1, UpperShadowColor2, LinearGradientMode.Vertical))
|
||||
{
|
||||
g.FillRectangle(shadowBrush, upperShadowRectangle);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
}
|
||||
|
||||
public override void RenderLeftToggleField(Graphics g, Rectangle leftRectangle, int totalToggleFieldWidth)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
|
||||
|
||||
Rectangle innercontrolRectangle = new Rectangle(1, 1, ToggleSwitch.Width - 1, ToggleSwitch.Height - 2);
|
||||
|
||||
using (GraphicsPath innerControlPath = GetRectangleClipPath(innercontrolRectangle))
|
||||
{
|
||||
g.SetClip(innerControlPath);
|
||||
|
||||
//Draw image or text
|
||||
if (ToggleSwitch.OnSideImage != null || !string.IsNullOrEmpty(ToggleSwitch.OnText))
|
||||
{
|
||||
RectangleF fullRectangle = new RectangleF(leftRectangle.X + 2 - (totalToggleFieldWidth - leftRectangle.Width), 2, totalToggleFieldWidth - 2, ToggleSwitch.Height - 4);
|
||||
|
||||
g.IntersectClip(fullRectangle);
|
||||
|
||||
if (ToggleSwitch.OnSideImage != null)
|
||||
{
|
||||
Size imageSize = ToggleSwitch.OnSideImage.Size;
|
||||
Rectangle imageRectangle;
|
||||
|
||||
int imageXPos = (int)fullRectangle.X;
|
||||
|
||||
if (ToggleSwitch.OnSideScaleImageToFit)
|
||||
{
|
||||
Size canvasSize = new Size((int)fullRectangle.Width, (int)fullRectangle.Height);
|
||||
Size resizedImageSize = ImageHelper.RescaleImageToFit(imageSize, canvasSize);
|
||||
|
||||
if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)resizedImageSize.Width) / 2));
|
||||
}
|
||||
else if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Near)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)resizedImageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)resizedImageSize.Height) / 2)), resizedImageSize.Width, resizedImageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)imageSize.Width) / 2));
|
||||
}
|
||||
else if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Near)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)imageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)imageSize.Height) / 2)), imageSize.Width, imageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImageUnscaled(ToggleSwitch.OnSideImage, imageRectangle);
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(ToggleSwitch.OnText))
|
||||
{
|
||||
SizeF textSize = g.MeasureString(ToggleSwitch.OnText, ToggleSwitch.OnFont);
|
||||
|
||||
float textXPos = fullRectangle.X;
|
||||
|
||||
if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
textXPos = (float)fullRectangle.X + (((float)fullRectangle.Width - (float)textSize.Width) / 2);
|
||||
}
|
||||
else if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Near)
|
||||
{
|
||||
textXPos = (float)fullRectangle.X + (float)fullRectangle.Width - (float)textSize.Width;
|
||||
}
|
||||
|
||||
RectangleF textRectangle = new RectangleF(textXPos, (float)fullRectangle.Y + (((float)fullRectangle.Height - (float)textSize.Height) / 2), textSize.Width, textSize.Height);
|
||||
|
||||
Color textForeColor = ToggleSwitch.OnForeColor;
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
textForeColor = textForeColor.ToGrayScale();
|
||||
|
||||
using (Brush textBrush = new SolidBrush(textForeColor))
|
||||
{
|
||||
g.DrawString(ToggleSwitch.OnText, ToggleSwitch.OnFont, textBrush, textRectangle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
}
|
||||
|
||||
public override void RenderRightToggleField(Graphics g, Rectangle rightRectangle, int totalToggleFieldWidth)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
|
||||
|
||||
Rectangle innercontrolRectangle = new Rectangle(1, 1, ToggleSwitch.Width - 1, ToggleSwitch.Height - 2);
|
||||
|
||||
using (GraphicsPath innerControlPath = GetRectangleClipPath(innercontrolRectangle))
|
||||
{
|
||||
g.SetClip(innerControlPath);
|
||||
|
||||
//Draw image or text
|
||||
if (ToggleSwitch.OffSideImage != null || !string.IsNullOrEmpty(ToggleSwitch.OffText))
|
||||
{
|
||||
RectangleF fullRectangle = new RectangleF(rightRectangle.X, 2, totalToggleFieldWidth - 2, ToggleSwitch.Height - 4);
|
||||
|
||||
g.IntersectClip(fullRectangle);
|
||||
|
||||
if (ToggleSwitch.OffSideImage != null)
|
||||
{
|
||||
Size imageSize = ToggleSwitch.OffSideImage.Size;
|
||||
Rectangle imageRectangle;
|
||||
|
||||
int imageXPos = (int)fullRectangle.X;
|
||||
|
||||
if (ToggleSwitch.OffSideScaleImageToFit)
|
||||
{
|
||||
Size canvasSize = new Size((int)fullRectangle.Width, (int)fullRectangle.Height);
|
||||
Size resizedImageSize = ImageHelper.RescaleImageToFit(imageSize, canvasSize);
|
||||
|
||||
if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)resizedImageSize.Width) / 2));
|
||||
}
|
||||
else if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Far)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)resizedImageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)resizedImageSize.Height) / 2)), resizedImageSize.Width, resizedImageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)imageSize.Width) / 2));
|
||||
}
|
||||
else if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Far)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)imageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)imageSize.Height) / 2)), imageSize.Width, imageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImageUnscaled(ToggleSwitch.OffSideImage, imageRectangle);
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(ToggleSwitch.OffText))
|
||||
{
|
||||
SizeF textSize = g.MeasureString(ToggleSwitch.OffText, ToggleSwitch.OffFont);
|
||||
|
||||
float textXPos = fullRectangle.X;
|
||||
|
||||
if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
textXPos = (float)fullRectangle.X + (((float)fullRectangle.Width - (float)textSize.Width) / 2);
|
||||
}
|
||||
else if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Far)
|
||||
{
|
||||
textXPos = (float)fullRectangle.X + (float)fullRectangle.Width - (float)textSize.Width;
|
||||
}
|
||||
|
||||
RectangleF textRectangle = new RectangleF(textXPos, (float)fullRectangle.Y + (((float)fullRectangle.Height - (float)textSize.Height) / 2), textSize.Width, textSize.Height);
|
||||
|
||||
Color textForeColor = ToggleSwitch.OffForeColor;
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
textForeColor = textForeColor.ToGrayScale();
|
||||
|
||||
using (Brush textBrush = new SolidBrush(textForeColor))
|
||||
{
|
||||
g.DrawString(ToggleSwitch.OffText, ToggleSwitch.OffFont, textBrush, textRectangle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
}
|
||||
|
||||
public override void RenderButton(Graphics g, Rectangle buttonRectangle)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
|
||||
|
||||
g.SetClip(buttonRectangle);
|
||||
|
||||
//Draw button surface
|
||||
Color buttonSurfaceColor = ButtonNormalSurfaceColor;
|
||||
|
||||
if (ToggleSwitch.IsButtonPressed)
|
||||
buttonSurfaceColor = ButtonPressedSurfaceColor;
|
||||
else if (ToggleSwitch.IsButtonHovered)
|
||||
buttonSurfaceColor = ButtonHoverSurfaceColor;
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
buttonSurfaceColor = buttonSurfaceColor.ToGrayScale();
|
||||
|
||||
using (Brush buttonSurfaceBrush = new SolidBrush(buttonSurfaceColor))
|
||||
{
|
||||
g.FillEllipse(buttonSurfaceBrush, buttonRectangle);
|
||||
}
|
||||
|
||||
//Draw "metal" surface
|
||||
PointF centerPoint1 = new PointF(buttonRectangle.X + (buttonRectangle.Width / 2f), buttonRectangle.Y + 1.2f*(buttonRectangle.Height / 2f));
|
||||
|
||||
using (PathGradientBrush firstMetalBrush = GetBrush(new Color[]
|
||||
{
|
||||
Color.Transparent, Color.Transparent, Color.Transparent, Color.Transparent, Color.Transparent, Color.Transparent,
|
||||
Color.Transparent, Color.Transparent, Color.Transparent, Color.FromArgb(255, 110, 110, 110), Color.Transparent, Color.Transparent,
|
||||
Color.Transparent
|
||||
}, buttonRectangle, centerPoint1))
|
||||
{
|
||||
g.FillEllipse(firstMetalBrush, buttonRectangle);
|
||||
}
|
||||
|
||||
PointF centerPoint2 = new PointF(buttonRectangle.X + 0.8f*(buttonRectangle.Width / 2f), buttonRectangle.Y + (buttonRectangle.Height / 2f));
|
||||
|
||||
using (PathGradientBrush secondMetalBrush = GetBrush(new Color[]
|
||||
{
|
||||
Color.FromArgb(255, 110, 110, 110), Color.Transparent, Color.Transparent, Color.Transparent,
|
||||
Color.Transparent, Color.Transparent, Color.Transparent, Color.Transparent,
|
||||
Color.FromArgb(255, 110, 110, 110)
|
||||
}, buttonRectangle, centerPoint2))
|
||||
{
|
||||
g.FillEllipse(secondMetalBrush, buttonRectangle);
|
||||
}
|
||||
|
||||
PointF centerPoint3 = new PointF(buttonRectangle.X + 1.2f*(buttonRectangle.Width / 2f), buttonRectangle.Y + (buttonRectangle.Height / 2f));
|
||||
|
||||
using (PathGradientBrush thirdMetalBrush = GetBrush(new Color[]
|
||||
{
|
||||
Color.Transparent, Color.Transparent, Color.Transparent, Color.Transparent,
|
||||
Color.FromArgb(255, 98, 98, 98), Color.Transparent, Color.Transparent, Color.Transparent,
|
||||
Color.Transparent
|
||||
}, buttonRectangle, centerPoint3))
|
||||
{
|
||||
g.FillEllipse(thirdMetalBrush, buttonRectangle);
|
||||
}
|
||||
|
||||
PointF centerPoint4 = new PointF(buttonRectangle.X + 0.9f*(buttonRectangle.Width / 2f), buttonRectangle.Y + 0.9f*(buttonRectangle.Height / 2f));
|
||||
|
||||
using (PathGradientBrush fourthMetalBrush = GetBrush(new Color[]
|
||||
{
|
||||
Color.Transparent, Color.FromArgb(255, 188, 188, 188), Color.FromArgb(255, 110, 110, 110), Color.Transparent, Color.Transparent, Color.Transparent,
|
||||
Color.Transparent, Color.Transparent, Color.Transparent, Color.Transparent, Color.Transparent, Color.Transparent,
|
||||
Color.Transparent
|
||||
}, buttonRectangle, centerPoint4))
|
||||
{
|
||||
g.FillEllipse(fourthMetalBrush, buttonRectangle);
|
||||
}
|
||||
|
||||
//Draw button border
|
||||
Color buttonBorderColor = ButtonNormalBorderColor;
|
||||
|
||||
if (ToggleSwitch.IsButtonPressed)
|
||||
buttonBorderColor = ButtonPressedBorderColor;
|
||||
else if (ToggleSwitch.IsButtonHovered)
|
||||
buttonBorderColor = ButtonHoverBorderColor;
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
buttonBorderColor = buttonBorderColor.ToGrayScale();
|
||||
|
||||
using (Pen buttonBorderPen = new Pen(buttonBorderColor))
|
||||
{
|
||||
g.DrawEllipse(buttonBorderPen, buttonRectangle);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
|
||||
#endregion Render Method Implementations
|
||||
|
||||
#region Helper Method Implementations
|
||||
|
||||
public GraphicsPath GetRectangleClipPath(Rectangle rect)
|
||||
{
|
||||
GraphicsPath borderPath = new GraphicsPath();
|
||||
borderPath.AddArc(rect.X, rect.Y, rect.Height, rect.Height, 90, 180);
|
||||
borderPath.AddArc(rect.Width - rect.Height, rect.Y, rect.Height, rect.Height, 270, 180);
|
||||
borderPath.CloseFigure();
|
||||
|
||||
return borderPath;
|
||||
}
|
||||
|
||||
public GraphicsPath GetButtonClipPath()
|
||||
{
|
||||
Rectangle buttonRectangle = GetButtonRectangle();
|
||||
|
||||
GraphicsPath buttonPath = new GraphicsPath();
|
||||
|
||||
buttonPath.AddArc(buttonRectangle.X, buttonRectangle.Y, buttonRectangle.Height, buttonRectangle.Height, 0, 360);
|
||||
|
||||
return buttonPath;
|
||||
}
|
||||
|
||||
public override int GetButtonWidth()
|
||||
{
|
||||
return ToggleSwitch.Height - 2;
|
||||
}
|
||||
|
||||
public override Rectangle GetButtonRectangle()
|
||||
{
|
||||
int buttonWidth = GetButtonWidth();
|
||||
return GetButtonRectangle(buttonWidth);
|
||||
}
|
||||
|
||||
public override Rectangle GetButtonRectangle(int buttonWidth)
|
||||
{
|
||||
Rectangle buttonRect = new Rectangle(ToggleSwitch.ButtonValue, 1, buttonWidth, buttonWidth);
|
||||
return buttonRect;
|
||||
}
|
||||
|
||||
private PathGradientBrush GetBrush(Color[] Colors, RectangleF r, PointF centerPoint)
|
||||
{
|
||||
int i = Colors.Length - 1;
|
||||
PointF[] points = new PointF[i + 1];
|
||||
|
||||
float a = 0f;
|
||||
int n = 0;
|
||||
float cx = r.Width / 2f;
|
||||
float cy = r.Height / 2f;
|
||||
|
||||
int w = (int)(Math.Floor((180.0 * (i - 2.0) / i) / 2.0));
|
||||
double wi = w * Math.PI / 180.0;
|
||||
double faktor = 1.0 / Math.Sin(wi);
|
||||
|
||||
float radx = (float)(cx * faktor);
|
||||
float rady = (float)(cy * faktor);
|
||||
|
||||
while (a <= Math.PI * 2)
|
||||
{
|
||||
points[n] = new PointF((float)((cx + (Math.Cos(a) * radx))) + r.Left, (float)((cy + (Math.Sin(a) * rady))) + r.Top);
|
||||
n += 1;
|
||||
a += (float)(Math.PI * 2 / i);
|
||||
}
|
||||
|
||||
points[i] = points[0];
|
||||
GraphicsPath graphicsPath = new GraphicsPath();
|
||||
graphicsPath.AddLines(points);
|
||||
|
||||
PathGradientBrush fBrush = new PathGradientBrush(graphicsPath);
|
||||
fBrush.CenterPoint = centerPoint;
|
||||
fBrush.CenterColor = Color.Transparent;
|
||||
fBrush.SurroundColors = new Color[] { Color.White };
|
||||
|
||||
try
|
||||
{
|
||||
fBrush.SurroundColors = Colors;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception("Too may colors!", ex);
|
||||
}
|
||||
|
||||
return fBrush;
|
||||
}
|
||||
|
||||
#endregion Helper Method Implementations
|
||||
}
|
||||
}
|
597
ToggleSwitch/Renderers/ToggleSwitchCarbonRenderer.cs
Normal file
|
@ -0,0 +1,597 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using ToggleSwitch;
|
||||
|
||||
namespace JCS
|
||||
{
|
||||
public class ToggleSwitchCarbonRenderer : ToggleSwitchRendererBase, IDisposable
|
||||
{
|
||||
#region Constructor
|
||||
|
||||
private GraphicsPath _innerControlPath = null;
|
||||
|
||||
public ToggleSwitchCarbonRenderer()
|
||||
{
|
||||
OuterBorderColor = Color.FromArgb(255, 106, 106, 106);
|
||||
InnerBorderColor1 = Color.FromArgb(255, 141, 151, 158);
|
||||
InnerBorderColor2 = Color.FromArgb(255, 138, 139, 140);
|
||||
LeftSideBackColor1 = Color.FromArgb(255, 61, 99, 119);
|
||||
LeftSideBackColor2 = Color.FromArgb(255, 108, 148, 179);
|
||||
RightSideBackColor1 = Color.FromArgb(255, 72, 72, 72);
|
||||
RightSideBackColor2 = Color.FromArgb(255, 85, 85, 85);
|
||||
ButtonNormalBorderColor1 = Color.FromArgb(255, 165, 167, 169);
|
||||
ButtonNormalBorderColor2 = Color.FromArgb(255, 106, 106, 106);
|
||||
ButtonNormalSurfaceColor1 = Color.FromArgb(255, 235, 235, 235);
|
||||
ButtonNormalSurfaceColor2 = Color.FromArgb(255, 178, 180, 182);
|
||||
ButtonHoverBorderColor1 = Color.FromArgb(255, 166, 168, 169);
|
||||
ButtonHoverBorderColor2 = Color.FromArgb(255, 169, 171, 173);
|
||||
ButtonHoverSurfaceColor1 = Color.FromArgb(255, 223, 224, 224);
|
||||
ButtonHoverSurfaceColor2 = Color.FromArgb(255, 169, 171, 173);
|
||||
ButtonPressedBorderColor1 = Color.FromArgb(255, 159, 159, 162);
|
||||
ButtonPressedBorderColor2 = Color.FromArgb(255, 106, 106, 106);
|
||||
ButtonPressedSurfaceColor1 = Color.FromArgb(255, 176, 177, 177);
|
||||
ButtonPressedSurfaceColor2 = Color.FromArgb(255, 133, 135, 136);
|
||||
ButtonShadowColor1 = Color.FromArgb(50, 0, 0, 0);
|
||||
ButtonShadowColor2 = Color.FromArgb(0, 0, 0, 0);
|
||||
|
||||
ButtonShadowWidth = 7;
|
||||
CornerRadius = 6;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_innerControlPath != null)
|
||||
_innerControlPath.Dispose();
|
||||
}
|
||||
|
||||
#endregion Constructor
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public Color OuterBorderColor { get; set; }
|
||||
public Color InnerBorderColor1 { get; set; }
|
||||
public Color InnerBorderColor2 { get; set; }
|
||||
public Color LeftSideBackColor1 { get; set; }
|
||||
public Color LeftSideBackColor2 { get; set; }
|
||||
public Color RightSideBackColor1 { get; set; }
|
||||
public Color RightSideBackColor2 { get; set; }
|
||||
public Color ButtonNormalBorderColor1 { get; set; }
|
||||
public Color ButtonNormalBorderColor2 { get; set; }
|
||||
public Color ButtonNormalSurfaceColor1 { get; set; }
|
||||
public Color ButtonNormalSurfaceColor2 { get; set; }
|
||||
public Color ButtonHoverBorderColor1 { get; set; }
|
||||
public Color ButtonHoverBorderColor2 { get; set; }
|
||||
public Color ButtonHoverSurfaceColor1 { get; set; }
|
||||
public Color ButtonHoverSurfaceColor2 { get; set; }
|
||||
public Color ButtonPressedBorderColor1 { get; set; }
|
||||
public Color ButtonPressedBorderColor2 { get; set; }
|
||||
public Color ButtonPressedSurfaceColor1 { get; set; }
|
||||
public Color ButtonPressedSurfaceColor2 { get; set; }
|
||||
public Color ButtonShadowColor1 { get; set; }
|
||||
public Color ButtonShadowColor2 { get; set; }
|
||||
|
||||
public int ButtonShadowWidth { get; set; }
|
||||
public int CornerRadius { get; set; }
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Render Method Implementations
|
||||
|
||||
public override void RenderBorder(Graphics g, Rectangle borderRectangle)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
|
||||
|
||||
//Draw outer border
|
||||
using (GraphicsPath outerBorderPath = GetRoundedRectanglePath(borderRectangle, CornerRadius))
|
||||
{
|
||||
g.SetClip(outerBorderPath);
|
||||
|
||||
Color outerBorderColor = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? OuterBorderColor.ToGrayScale() : OuterBorderColor;
|
||||
|
||||
using (Brush outerBorderBrush = new SolidBrush(outerBorderColor))
|
||||
{
|
||||
g.FillPath(outerBorderBrush, outerBorderPath);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
|
||||
//Draw inner border
|
||||
Rectangle innerborderRectangle = new Rectangle(borderRectangle.X + 1, borderRectangle.Y + 1, borderRectangle.Width - 2, borderRectangle.Height - 2);
|
||||
|
||||
using (GraphicsPath innerBorderPath = GetRoundedRectanglePath(innerborderRectangle, CornerRadius))
|
||||
{
|
||||
g.SetClip(innerBorderPath);
|
||||
|
||||
Color borderColor1 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? InnerBorderColor1.ToGrayScale() : InnerBorderColor1;
|
||||
Color borderColor2 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? InnerBorderColor2.ToGrayScale() : InnerBorderColor2;
|
||||
|
||||
using (Brush borderBrush = new LinearGradientBrush(borderRectangle, borderColor1, borderColor2, LinearGradientMode.Vertical))
|
||||
{
|
||||
g.FillPath(borderBrush, innerBorderPath);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
|
||||
Rectangle backgroundRectangle = new Rectangle(borderRectangle.X + 2, borderRectangle.Y + 2, borderRectangle.Width - 4, borderRectangle.Height - 4);
|
||||
_innerControlPath = GetRoundedRectanglePath(backgroundRectangle, CornerRadius);
|
||||
}
|
||||
|
||||
public override void RenderLeftToggleField(Graphics g, Rectangle leftRectangle, int totalToggleFieldWidth)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
|
||||
|
||||
int buttonWidth = GetButtonWidth();
|
||||
|
||||
//Draw inner background
|
||||
int gradientRectWidth = leftRectangle.Width + buttonWidth / 2;
|
||||
Rectangle gradientRectangle = new Rectangle(leftRectangle.X, leftRectangle.Y, gradientRectWidth, leftRectangle.Height);
|
||||
|
||||
Color leftSideBackColor1 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? LeftSideBackColor1.ToGrayScale() : LeftSideBackColor1;
|
||||
Color leftSideBackColor2 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? LeftSideBackColor2.ToGrayScale() : LeftSideBackColor2;
|
||||
|
||||
if (_innerControlPath != null)
|
||||
{
|
||||
g.SetClip(_innerControlPath);
|
||||
g.IntersectClip(gradientRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.SetClip(gradientRectangle);
|
||||
}
|
||||
|
||||
using (Brush backgroundBrush = new LinearGradientBrush(gradientRectangle, leftSideBackColor1, leftSideBackColor2, LinearGradientMode.Vertical))
|
||||
{
|
||||
g.FillRectangle(backgroundBrush, gradientRectangle);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
|
||||
Rectangle leftShadowRectangle = new Rectangle();
|
||||
leftShadowRectangle.X = leftRectangle.X + leftRectangle.Width - ButtonShadowWidth;
|
||||
leftShadowRectangle.Y = leftRectangle.Y;
|
||||
leftShadowRectangle.Width = ButtonShadowWidth + CornerRadius;
|
||||
leftShadowRectangle.Height = leftRectangle.Height;
|
||||
|
||||
if (_innerControlPath != null)
|
||||
{
|
||||
g.SetClip(_innerControlPath);
|
||||
g.IntersectClip(leftShadowRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.SetClip(leftShadowRectangle);
|
||||
}
|
||||
|
||||
using (Brush buttonShadowBrush = new LinearGradientBrush(leftShadowRectangle, ButtonShadowColor2, ButtonShadowColor1, LinearGradientMode.Horizontal))
|
||||
{
|
||||
g.FillRectangle(buttonShadowBrush, leftShadowRectangle);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
|
||||
//Draw image or text
|
||||
if (ToggleSwitch.OnSideImage != null || !string.IsNullOrEmpty(ToggleSwitch.OnText))
|
||||
{
|
||||
RectangleF fullRectangle = new RectangleF(leftRectangle.X + 1 - (totalToggleFieldWidth - leftRectangle.Width), 1, totalToggleFieldWidth - 1, ToggleSwitch.Height - 2);
|
||||
|
||||
if (_innerControlPath != null)
|
||||
{
|
||||
g.SetClip(_innerControlPath);
|
||||
g.IntersectClip(fullRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.SetClip(fullRectangle);
|
||||
}
|
||||
|
||||
if (ToggleSwitch.OnSideImage != null)
|
||||
{
|
||||
Size imageSize = ToggleSwitch.OnSideImage.Size;
|
||||
Rectangle imageRectangle;
|
||||
|
||||
int imageXPos = (int)fullRectangle.X;
|
||||
|
||||
if (ToggleSwitch.OnSideScaleImageToFit)
|
||||
{
|
||||
Size canvasSize = new Size((int)fullRectangle.Width, (int)fullRectangle.Height);
|
||||
Size resizedImageSize = ImageHelper.RescaleImageToFit(imageSize, canvasSize);
|
||||
|
||||
if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)resizedImageSize.Width) / 2));
|
||||
}
|
||||
else if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Near)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)resizedImageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)resizedImageSize.Height) / 2)), resizedImageSize.Width, resizedImageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)imageSize.Width) / 2));
|
||||
}
|
||||
else if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Near)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)imageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)imageSize.Height) / 2)), imageSize.Width, imageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImageUnscaled(ToggleSwitch.OnSideImage, imageRectangle);
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(ToggleSwitch.OnText))
|
||||
{
|
||||
SizeF textSize = g.MeasureString(ToggleSwitch.OnText, ToggleSwitch.OnFont);
|
||||
|
||||
float textXPos = fullRectangle.X;
|
||||
|
||||
if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
textXPos = (float)fullRectangle.X + (((float)fullRectangle.Width - (float)textSize.Width) / 2);
|
||||
}
|
||||
else if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Near)
|
||||
{
|
||||
textXPos = (float)fullRectangle.X + (float)fullRectangle.Width - (float)textSize.Width;
|
||||
}
|
||||
|
||||
RectangleF textRectangle = new RectangleF(textXPos, (float)fullRectangle.Y + (((float)fullRectangle.Height - (float)textSize.Height) / 2), textSize.Width, textSize.Height);
|
||||
|
||||
Color textForeColor = ToggleSwitch.OnForeColor;
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
textForeColor = textForeColor.ToGrayScale();
|
||||
|
||||
using (Brush textBrush = new SolidBrush(textForeColor))
|
||||
{
|
||||
g.DrawString(ToggleSwitch.OnText, ToggleSwitch.OnFont, textBrush, textRectangle);
|
||||
}
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
}
|
||||
|
||||
public override void RenderRightToggleField(Graphics g, Rectangle rightRectangle, int totalToggleFieldWidth)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
|
||||
|
||||
int buttonWidth = GetButtonWidth();
|
||||
|
||||
//Draw inner background
|
||||
int gradientRectWidth = rightRectangle.Width + buttonWidth / 2;
|
||||
Rectangle gradientRectangle = new Rectangle(rightRectangle.X - buttonWidth / 2, rightRectangle.Y, gradientRectWidth, rightRectangle.Height);
|
||||
|
||||
Color rightSideBackColor1 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? RightSideBackColor1.ToGrayScale() : RightSideBackColor1;
|
||||
Color rightSideBackColor2 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? RightSideBackColor2.ToGrayScale() : RightSideBackColor2;
|
||||
|
||||
if (_innerControlPath != null)
|
||||
{
|
||||
g.SetClip(_innerControlPath);
|
||||
g.IntersectClip(gradientRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.SetClip(gradientRectangle);
|
||||
}
|
||||
|
||||
using (Brush backgroundBrush = new LinearGradientBrush(gradientRectangle, rightSideBackColor1, rightSideBackColor2, LinearGradientMode.Vertical))
|
||||
{
|
||||
g.FillRectangle(backgroundBrush, gradientRectangle);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
|
||||
Rectangle rightShadowRectangle = new Rectangle();
|
||||
rightShadowRectangle.X = rightRectangle.X - CornerRadius;
|
||||
rightShadowRectangle.Y = rightRectangle.Y;
|
||||
rightShadowRectangle.Width = ButtonShadowWidth + CornerRadius;
|
||||
rightShadowRectangle.Height = rightRectangle.Height;
|
||||
|
||||
if (_innerControlPath != null)
|
||||
{
|
||||
g.SetClip(_innerControlPath);
|
||||
g.IntersectClip(rightShadowRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.SetClip(rightShadowRectangle);
|
||||
}
|
||||
|
||||
using (Brush buttonShadowBrush = new LinearGradientBrush(rightShadowRectangle, ButtonShadowColor1, ButtonShadowColor2, LinearGradientMode.Horizontal))
|
||||
{
|
||||
g.FillRectangle(buttonShadowBrush, rightShadowRectangle);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
|
||||
//Draw image or text
|
||||
if (ToggleSwitch.OffSideImage != null || !string.IsNullOrEmpty(ToggleSwitch.OffText))
|
||||
{
|
||||
RectangleF fullRectangle = new RectangleF(rightRectangle.X, 1, totalToggleFieldWidth - 1, ToggleSwitch.Height - 2);
|
||||
|
||||
if (_innerControlPath != null)
|
||||
{
|
||||
g.SetClip(_innerControlPath);
|
||||
g.IntersectClip(fullRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.SetClip(fullRectangle);
|
||||
}
|
||||
|
||||
if (ToggleSwitch.OffSideImage != null)
|
||||
{
|
||||
Size imageSize = ToggleSwitch.OffSideImage.Size;
|
||||
Rectangle imageRectangle;
|
||||
|
||||
int imageXPos = (int)fullRectangle.X;
|
||||
|
||||
if (ToggleSwitch.OffSideScaleImageToFit)
|
||||
{
|
||||
Size canvasSize = new Size((int)fullRectangle.Width, (int)fullRectangle.Height);
|
||||
Size resizedImageSize = ImageHelper.RescaleImageToFit(imageSize, canvasSize);
|
||||
|
||||
if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)resizedImageSize.Width) / 2));
|
||||
}
|
||||
else if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Far)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)resizedImageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)resizedImageSize.Height) / 2)), resizedImageSize.Width, resizedImageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)imageSize.Width) / 2));
|
||||
}
|
||||
else if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Far)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)imageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)imageSize.Height) / 2)), imageSize.Width, imageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImageUnscaled(ToggleSwitch.OffSideImage, imageRectangle);
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(ToggleSwitch.OffText))
|
||||
{
|
||||
SizeF textSize = g.MeasureString(ToggleSwitch.OffText, ToggleSwitch.OffFont);
|
||||
|
||||
float textXPos = fullRectangle.X;
|
||||
|
||||
if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
textXPos = (float)fullRectangle.X + (((float)fullRectangle.Width - (float)textSize.Width) / 2);
|
||||
}
|
||||
else if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Far)
|
||||
{
|
||||
textXPos = (float)fullRectangle.X + (float)fullRectangle.Width - (float)textSize.Width;
|
||||
}
|
||||
|
||||
RectangleF textRectangle = new RectangleF(textXPos, (float)fullRectangle.Y + (((float)fullRectangle.Height - (float)textSize.Height) / 2), textSize.Width, textSize.Height);
|
||||
|
||||
Color textForeColor = ToggleSwitch.OffForeColor;
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
textForeColor = textForeColor.ToGrayScale();
|
||||
|
||||
using (Brush textBrush = new SolidBrush(textForeColor))
|
||||
{
|
||||
g.DrawString(ToggleSwitch.OffText, ToggleSwitch.OffFont, textBrush, textRectangle);
|
||||
}
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
}
|
||||
|
||||
public override void RenderButton(Graphics g, Rectangle buttonRectangle)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
|
||||
|
||||
buttonRectangle.Inflate(-1, -1);
|
||||
|
||||
using (GraphicsPath buttonPath = GetRoundedRectanglePath(buttonRectangle, CornerRadius))
|
||||
{
|
||||
g.SetClip(buttonPath);
|
||||
|
||||
//Draw button surface
|
||||
Color buttonSurfaceColor1 = ButtonNormalSurfaceColor1;
|
||||
Color buttonSurfaceColor2 = ButtonNormalSurfaceColor2;
|
||||
|
||||
if (ToggleSwitch.IsButtonPressed)
|
||||
{
|
||||
buttonSurfaceColor1 = ButtonPressedSurfaceColor1;
|
||||
buttonSurfaceColor2 = ButtonPressedSurfaceColor2;
|
||||
}
|
||||
else if (ToggleSwitch.IsButtonHovered)
|
||||
{
|
||||
buttonSurfaceColor1 = ButtonHoverSurfaceColor1;
|
||||
buttonSurfaceColor2 = ButtonHoverSurfaceColor2;
|
||||
}
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
{
|
||||
buttonSurfaceColor1 = buttonSurfaceColor1.ToGrayScale();
|
||||
buttonSurfaceColor2 = buttonSurfaceColor2.ToGrayScale();
|
||||
}
|
||||
|
||||
using (Brush buttonSurfaceBrush = new LinearGradientBrush(buttonRectangle, buttonSurfaceColor1, buttonSurfaceColor2, LinearGradientMode.Vertical))
|
||||
{
|
||||
g.FillPath(buttonSurfaceBrush, buttonPath);
|
||||
}
|
||||
|
||||
//Draw button border
|
||||
Color buttonBorderColor1 = ButtonNormalBorderColor1;
|
||||
Color buttonBorderColor2 = ButtonNormalBorderColor2;
|
||||
|
||||
if (ToggleSwitch.IsButtonPressed)
|
||||
{
|
||||
buttonBorderColor1 = ButtonPressedBorderColor1;
|
||||
buttonBorderColor2 = ButtonPressedBorderColor2;
|
||||
}
|
||||
else if (ToggleSwitch.IsButtonHovered)
|
||||
{
|
||||
buttonBorderColor1 = ButtonHoverBorderColor1;
|
||||
buttonBorderColor2 = ButtonHoverBorderColor2;
|
||||
}
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
{
|
||||
buttonBorderColor1 = buttonBorderColor1.ToGrayScale();
|
||||
buttonBorderColor2 = buttonBorderColor2.ToGrayScale();
|
||||
}
|
||||
|
||||
using (Brush buttonBorderBrush = new LinearGradientBrush(buttonRectangle, buttonBorderColor1, buttonBorderColor2, LinearGradientMode.Vertical))
|
||||
{
|
||||
using (Pen buttonBorderPen = new Pen(buttonBorderBrush))
|
||||
{
|
||||
g.DrawPath(buttonBorderPen, buttonPath);
|
||||
}
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
|
||||
//Draw button image
|
||||
Image buttonImage = ToggleSwitch.ButtonImage ?? (ToggleSwitch.Checked ? ToggleSwitch.OnButtonImage : ToggleSwitch.OffButtonImage);
|
||||
|
||||
if (buttonImage != null)
|
||||
{
|
||||
g.SetClip(buttonPath);
|
||||
|
||||
ToggleSwitch.ToggleSwitchButtonAlignment alignment = ToggleSwitch.ButtonImage != null ? ToggleSwitch.ButtonAlignment : (ToggleSwitch.Checked ? ToggleSwitch.OnButtonAlignment : ToggleSwitch.OffButtonAlignment);
|
||||
|
||||
Size imageSize = buttonImage.Size;
|
||||
|
||||
Rectangle imageRectangle;
|
||||
|
||||
int imageXPos = buttonRectangle.X;
|
||||
|
||||
bool scaleImage = ToggleSwitch.ButtonImage != null ? ToggleSwitch.ButtonScaleImageToFit : (ToggleSwitch.Checked ? ToggleSwitch.OnButtonScaleImageToFit : ToggleSwitch.OffButtonScaleImageToFit);
|
||||
|
||||
if (scaleImage)
|
||||
{
|
||||
Size canvasSize = buttonRectangle.Size;
|
||||
Size resizedImageSize = ImageHelper.RescaleImageToFit(imageSize, canvasSize);
|
||||
|
||||
if (alignment == ToggleSwitch.ToggleSwitchButtonAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)buttonRectangle.X + (((float)buttonRectangle.Width - (float)resizedImageSize.Width) / 2));
|
||||
}
|
||||
else if (alignment == ToggleSwitch.ToggleSwitchButtonAlignment.Right)
|
||||
{
|
||||
imageXPos = (int)((float)buttonRectangle.X + (float)buttonRectangle.Width - (float)resizedImageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)buttonRectangle.Y + (((float)buttonRectangle.Height - (float)resizedImageSize.Height) / 2)), resizedImageSize.Width, resizedImageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(buttonImage, imageRectangle, 0, 0, buttonImage.Width, buttonImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImage(buttonImage, imageRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (alignment == ToggleSwitch.ToggleSwitchButtonAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)buttonRectangle.X + (((float)buttonRectangle.Width - (float)imageSize.Width) / 2));
|
||||
}
|
||||
else if (alignment == ToggleSwitch.ToggleSwitchButtonAlignment.Right)
|
||||
{
|
||||
imageXPos = (int)((float)buttonRectangle.X + (float)buttonRectangle.Width - (float)imageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)buttonRectangle.Y + (((float)buttonRectangle.Height - (float)imageSize.Height) / 2)), imageSize.Width, imageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(buttonImage, imageRectangle, 0, 0, buttonImage.Width, buttonImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImageUnscaled(buttonImage, imageRectangle);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Render Method Implementations
|
||||
|
||||
#region Helper Method Implementations
|
||||
|
||||
public GraphicsPath GetRoundedRectanglePath(Rectangle rectangle, int radius)
|
||||
{
|
||||
GraphicsPath gp = new GraphicsPath();
|
||||
int diameter = 2*radius;
|
||||
|
||||
if (diameter > ToggleSwitch.Height)
|
||||
diameter = ToggleSwitch.Height;
|
||||
|
||||
if (diameter > ToggleSwitch.Width)
|
||||
diameter = ToggleSwitch.Width;
|
||||
|
||||
gp.AddArc(rectangle.X, rectangle.Y, diameter, diameter, 180, 90);
|
||||
gp.AddArc(rectangle.X + rectangle.Width - diameter, rectangle.Y, diameter, diameter, 270, 90);
|
||||
gp.AddArc(rectangle.X + rectangle.Width - diameter, rectangle.Y + rectangle.Height - diameter, diameter, diameter, 0, 90);
|
||||
gp.AddArc(rectangle.X, rectangle.Y + rectangle.Height - diameter, diameter, diameter, 90, 90);
|
||||
gp.CloseFigure();
|
||||
|
||||
return gp;
|
||||
}
|
||||
|
||||
public override int GetButtonWidth()
|
||||
{
|
||||
float buttonWidth = 1.61f*(ToggleSwitch.Height - 2);
|
||||
return (int) buttonWidth;
|
||||
}
|
||||
|
||||
public override Rectangle GetButtonRectangle()
|
||||
{
|
||||
int buttonWidth = GetButtonWidth();
|
||||
return GetButtonRectangle(buttonWidth);
|
||||
}
|
||||
|
||||
public override Rectangle GetButtonRectangle(int buttonWidth)
|
||||
{
|
||||
Rectangle buttonRect = new Rectangle(ToggleSwitch.ButtonValue, 0, buttonWidth, ToggleSwitch.Height);
|
||||
return buttonRect;
|
||||
}
|
||||
|
||||
#endregion Helper Method Implementations
|
||||
}
|
||||
}
|
642
ToggleSwitch/Renderers/ToggleSwitchFancyRenderer.cs
Normal file
|
@ -0,0 +1,642 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using ToggleSwitch;
|
||||
|
||||
namespace JCS
|
||||
{
|
||||
public class ToggleSwitchFancyRenderer : ToggleSwitchRendererBase, IDisposable
|
||||
{
|
||||
#region Constructor
|
||||
|
||||
private GraphicsPath _innerControlPath = null;
|
||||
|
||||
public ToggleSwitchFancyRenderer()
|
||||
{
|
||||
OuterBorderColor1 = Color.FromArgb(255, 197, 199, 201);
|
||||
OuterBorderColor2 = Color.FromArgb(255, 207, 209, 212);
|
||||
InnerBorderColor1 = Color.FromArgb(200, 205, 208, 207);
|
||||
InnerBorderColor2 = Color.FromArgb(255, 207, 209, 212);
|
||||
LeftSideBackColor1 = Color.FromArgb(255, 61, 110, 6);
|
||||
LeftSideBackColor2 = Color.FromArgb(255, 93, 170, 9);
|
||||
RightSideBackColor1 = Color.FromArgb(255, 149, 0, 0);
|
||||
RightSideBackColor2 = Color.FromArgb(255, 198, 0, 0);
|
||||
ButtonNormalBorderColor1 = Color.FromArgb(255, 212, 209, 211);
|
||||
ButtonNormalBorderColor2 = Color.FromArgb(255, 197, 199, 201);
|
||||
ButtonNormalUpperSurfaceColor1 = Color.FromArgb(255, 252, 251, 252);
|
||||
ButtonNormalUpperSurfaceColor2 = Color.FromArgb(255, 247, 247, 247);
|
||||
ButtonNormalLowerSurfaceColor1 = Color.FromArgb(255, 233, 233, 233);
|
||||
ButtonNormalLowerSurfaceColor2 = Color.FromArgb(255, 225, 225, 225);
|
||||
ButtonHoverBorderColor1 = Color.FromArgb(255, 212, 207, 209);
|
||||
ButtonHoverBorderColor2 = Color.FromArgb(255, 223, 223, 223);
|
||||
ButtonHoverUpperSurfaceColor1 = Color.FromArgb(255, 240, 239, 240);
|
||||
ButtonHoverUpperSurfaceColor2 = Color.FromArgb(255, 235, 235, 235);
|
||||
ButtonHoverLowerSurfaceColor1 = Color.FromArgb(255, 221, 221, 221);
|
||||
ButtonHoverLowerSurfaceColor2 = Color.FromArgb(255, 214, 214, 214);
|
||||
ButtonPressedBorderColor1 = Color.FromArgb(255, 176, 176, 176);
|
||||
ButtonPressedBorderColor2 = Color.FromArgb(255, 176, 176, 176);
|
||||
ButtonPressedUpperSurfaceColor1 = Color.FromArgb(255, 189, 188, 189);
|
||||
ButtonPressedUpperSurfaceColor2 = Color.FromArgb(255, 185, 185, 185);
|
||||
ButtonPressedLowerSurfaceColor1 = Color.FromArgb(255, 175, 175, 175);
|
||||
ButtonPressedLowerSurfaceColor2 = Color.FromArgb(255, 169, 169, 169);
|
||||
ButtonShadowColor1 = Color.FromArgb(50, 0, 0, 0);
|
||||
ButtonShadowColor2 = Color.FromArgb(0, 0, 0, 0);
|
||||
|
||||
ButtonShadowWidth = 7;
|
||||
CornerRadius = 6;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_innerControlPath != null)
|
||||
_innerControlPath.Dispose();
|
||||
}
|
||||
|
||||
#endregion Constructor
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public Color OuterBorderColor1 { get; set; }
|
||||
public Color OuterBorderColor2 { get; set; }
|
||||
public Color InnerBorderColor1 { get; set; }
|
||||
public Color InnerBorderColor2 { get; set; }
|
||||
public Color LeftSideBackColor1 { get; set; }
|
||||
public Color LeftSideBackColor2 { get; set; }
|
||||
public Color RightSideBackColor1 { get; set; }
|
||||
public Color RightSideBackColor2 { get; set; }
|
||||
public Color ButtonNormalBorderColor1 { get; set; }
|
||||
public Color ButtonNormalBorderColor2 { get; set; }
|
||||
public Color ButtonNormalUpperSurfaceColor1 { get; set; }
|
||||
public Color ButtonNormalUpperSurfaceColor2 { get; set; }
|
||||
public Color ButtonNormalLowerSurfaceColor1 { get; set; }
|
||||
public Color ButtonNormalLowerSurfaceColor2 { get; set; }
|
||||
public Color ButtonHoverBorderColor1 { get; set; }
|
||||
public Color ButtonHoverBorderColor2 { get; set; }
|
||||
public Color ButtonHoverUpperSurfaceColor1 { get; set; }
|
||||
public Color ButtonHoverUpperSurfaceColor2 { get; set; }
|
||||
public Color ButtonHoverLowerSurfaceColor1 { get; set; }
|
||||
public Color ButtonHoverLowerSurfaceColor2 { get; set; }
|
||||
public Color ButtonPressedBorderColor1 { get; set; }
|
||||
public Color ButtonPressedBorderColor2 { get; set; }
|
||||
public Color ButtonPressedUpperSurfaceColor1 { get; set; }
|
||||
public Color ButtonPressedUpperSurfaceColor2 { get; set; }
|
||||
public Color ButtonPressedLowerSurfaceColor1 { get; set; }
|
||||
public Color ButtonPressedLowerSurfaceColor2 { get; set; }
|
||||
public Color ButtonShadowColor1 { get; set; }
|
||||
public Color ButtonShadowColor2 { get; set; }
|
||||
|
||||
public int ButtonShadowWidth { get; set; }
|
||||
public int CornerRadius { get; set; }
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Render Method Implementations
|
||||
|
||||
public override void RenderBorder(Graphics g, Rectangle borderRectangle)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
|
||||
|
||||
//Draw outer border
|
||||
using (GraphicsPath outerBorderPath = GetRoundedRectanglePath(borderRectangle, CornerRadius))
|
||||
{
|
||||
g.SetClip(outerBorderPath);
|
||||
|
||||
Color outerBorderColor1 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? OuterBorderColor1.ToGrayScale() : OuterBorderColor1;
|
||||
Color outerBorderColor2 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? OuterBorderColor2.ToGrayScale() : OuterBorderColor2;
|
||||
|
||||
using (Brush outerBorderBrush = new LinearGradientBrush(borderRectangle, outerBorderColor1, outerBorderColor2, LinearGradientMode.Vertical))
|
||||
{
|
||||
g.FillPath(outerBorderBrush, outerBorderPath);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
|
||||
//Draw inner border
|
||||
Rectangle innerborderRectangle = new Rectangle(borderRectangle.X + 1, borderRectangle.Y + 1, borderRectangle.Width - 2, borderRectangle.Height - 2);
|
||||
|
||||
using (GraphicsPath innerBorderPath = GetRoundedRectanglePath(innerborderRectangle, CornerRadius))
|
||||
{
|
||||
g.SetClip(innerBorderPath);
|
||||
|
||||
Color innerBorderColor1 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? InnerBorderColor1.ToGrayScale() : InnerBorderColor1;
|
||||
Color innerBorderColor2 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? InnerBorderColor2.ToGrayScale() : InnerBorderColor2;
|
||||
|
||||
using (Brush borderBrush = new LinearGradientBrush(borderRectangle, innerBorderColor1, innerBorderColor2, LinearGradientMode.Vertical))
|
||||
{
|
||||
g.FillPath(borderBrush, innerBorderPath);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
|
||||
Rectangle backgroundRectangle = new Rectangle(borderRectangle.X + 2, borderRectangle.Y + 2, borderRectangle.Width - 4, borderRectangle.Height - 4);
|
||||
_innerControlPath = GetRoundedRectanglePath(backgroundRectangle, CornerRadius);
|
||||
}
|
||||
|
||||
public override void RenderLeftToggleField(Graphics g, Rectangle leftRectangle, int totalToggleFieldWidth)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
|
||||
|
||||
int buttonWidth = GetButtonWidth();
|
||||
|
||||
//Draw inner background
|
||||
int gradientRectWidth = leftRectangle.Width + buttonWidth / 2;
|
||||
Rectangle gradientRectangle = new Rectangle(leftRectangle.X, leftRectangle.Y, gradientRectWidth, leftRectangle.Height);
|
||||
|
||||
Color leftSideBackColor1 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? LeftSideBackColor1.ToGrayScale() : LeftSideBackColor1;
|
||||
Color leftSideBackColor2 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? LeftSideBackColor2.ToGrayScale() : LeftSideBackColor2;
|
||||
|
||||
if (_innerControlPath != null)
|
||||
{
|
||||
g.SetClip(_innerControlPath);
|
||||
g.IntersectClip(gradientRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.SetClip(gradientRectangle);
|
||||
}
|
||||
|
||||
using (Brush backgroundBrush = new LinearGradientBrush(gradientRectangle, leftSideBackColor1, leftSideBackColor2, LinearGradientMode.Vertical))
|
||||
{
|
||||
g.FillRectangle(backgroundBrush, gradientRectangle);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
|
||||
Rectangle leftShadowRectangle = new Rectangle();
|
||||
leftShadowRectangle.X = leftRectangle.X + leftRectangle.Width - ButtonShadowWidth;
|
||||
leftShadowRectangle.Y = leftRectangle.Y;
|
||||
leftShadowRectangle.Width = ButtonShadowWidth + CornerRadius;
|
||||
leftShadowRectangle.Height = leftRectangle.Height;
|
||||
|
||||
if (_innerControlPath != null)
|
||||
{
|
||||
g.SetClip(_innerControlPath);
|
||||
g.IntersectClip(leftShadowRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.SetClip(leftShadowRectangle);
|
||||
}
|
||||
|
||||
using (Brush buttonShadowBrush = new LinearGradientBrush(leftShadowRectangle, ButtonShadowColor2, ButtonShadowColor1, LinearGradientMode.Horizontal))
|
||||
{
|
||||
g.FillRectangle(buttonShadowBrush, leftShadowRectangle);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
|
||||
//Draw image or text
|
||||
if (ToggleSwitch.OnSideImage != null || !string.IsNullOrEmpty(ToggleSwitch.OnText))
|
||||
{
|
||||
RectangleF fullRectangle = new RectangleF(leftRectangle.X + 1 - (totalToggleFieldWidth - leftRectangle.Width), 1, totalToggleFieldWidth - 1, ToggleSwitch.Height - 2);
|
||||
|
||||
if (_innerControlPath != null)
|
||||
{
|
||||
g.SetClip(_innerControlPath);
|
||||
g.IntersectClip(fullRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.SetClip(fullRectangle);
|
||||
}
|
||||
|
||||
if (ToggleSwitch.OnSideImage != null)
|
||||
{
|
||||
Size imageSize = ToggleSwitch.OnSideImage.Size;
|
||||
Rectangle imageRectangle;
|
||||
|
||||
int imageXPos = (int)fullRectangle.X;
|
||||
|
||||
if (ToggleSwitch.OnSideScaleImageToFit)
|
||||
{
|
||||
Size canvasSize = new Size((int)fullRectangle.Width, (int)fullRectangle.Height);
|
||||
Size resizedImageSize = ImageHelper.RescaleImageToFit(imageSize, canvasSize);
|
||||
|
||||
if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)resizedImageSize.Width) / 2));
|
||||
}
|
||||
else if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Near)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)resizedImageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)resizedImageSize.Height) / 2)), resizedImageSize.Width, resizedImageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)imageSize.Width) / 2));
|
||||
}
|
||||
else if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Near)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)imageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)imageSize.Height) / 2)), imageSize.Width, imageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImageUnscaled(ToggleSwitch.OnSideImage, imageRectangle);
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(ToggleSwitch.OnText))
|
||||
{
|
||||
SizeF textSize = g.MeasureString(ToggleSwitch.OnText, ToggleSwitch.OnFont);
|
||||
|
||||
float textXPos = fullRectangle.X;
|
||||
|
||||
if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
textXPos = (float)fullRectangle.X + (((float)fullRectangle.Width - (float)textSize.Width) / 2);
|
||||
}
|
||||
else if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Near)
|
||||
{
|
||||
textXPos = (float)fullRectangle.X + (float)fullRectangle.Width - (float)textSize.Width;
|
||||
}
|
||||
|
||||
RectangleF textRectangle = new RectangleF(textXPos, (float)fullRectangle.Y + (((float)fullRectangle.Height - (float)textSize.Height) / 2), textSize.Width, textSize.Height);
|
||||
|
||||
Color textForeColor = ToggleSwitch.OnForeColor;
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
textForeColor = textForeColor.ToGrayScale();
|
||||
|
||||
using (Brush textBrush = new SolidBrush(textForeColor))
|
||||
{
|
||||
g.DrawString(ToggleSwitch.OnText, ToggleSwitch.OnFont, textBrush, textRectangle);
|
||||
}
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
}
|
||||
|
||||
public override void RenderRightToggleField(Graphics g, Rectangle rightRectangle, int totalToggleFieldWidth)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
|
||||
|
||||
int buttonWidth = GetButtonWidth();
|
||||
|
||||
//Draw inner background
|
||||
int gradientRectWidth = rightRectangle.Width + buttonWidth / 2;
|
||||
Rectangle gradientRectangle = new Rectangle(rightRectangle.X - buttonWidth / 2, rightRectangle.Y, gradientRectWidth, rightRectangle.Height);
|
||||
|
||||
Color rightSideBackColor1 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? RightSideBackColor1.ToGrayScale() : RightSideBackColor1;
|
||||
Color rightSideBackColor2 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? RightSideBackColor2.ToGrayScale() : RightSideBackColor2;
|
||||
|
||||
if (_innerControlPath != null)
|
||||
{
|
||||
g.SetClip(_innerControlPath);
|
||||
g.IntersectClip(gradientRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.SetClip(gradientRectangle);
|
||||
}
|
||||
|
||||
using (Brush backgroundBrush = new LinearGradientBrush(gradientRectangle, rightSideBackColor1, rightSideBackColor2, LinearGradientMode.Vertical))
|
||||
{
|
||||
g.FillRectangle(backgroundBrush, gradientRectangle);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
|
||||
Rectangle rightShadowRectangle = new Rectangle();
|
||||
rightShadowRectangle.X = rightRectangle.X - CornerRadius;
|
||||
rightShadowRectangle.Y = rightRectangle.Y;
|
||||
rightShadowRectangle.Width = ButtonShadowWidth + CornerRadius;
|
||||
rightShadowRectangle.Height = rightRectangle.Height;
|
||||
|
||||
if (_innerControlPath != null)
|
||||
{
|
||||
g.SetClip(_innerControlPath);
|
||||
g.IntersectClip(rightShadowRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.SetClip(rightShadowRectangle);
|
||||
}
|
||||
|
||||
using (Brush buttonShadowBrush = new LinearGradientBrush(rightShadowRectangle, ButtonShadowColor1, ButtonShadowColor2, LinearGradientMode.Horizontal))
|
||||
{
|
||||
g.FillRectangle(buttonShadowBrush, rightShadowRectangle);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
|
||||
//Draw image or text
|
||||
if (ToggleSwitch.OffSideImage != null || !string.IsNullOrEmpty(ToggleSwitch.OffText))
|
||||
{
|
||||
RectangleF fullRectangle = new RectangleF(rightRectangle.X, 1, totalToggleFieldWidth - 1, ToggleSwitch.Height - 2);
|
||||
|
||||
if (_innerControlPath != null)
|
||||
{
|
||||
g.SetClip(_innerControlPath);
|
||||
g.IntersectClip(fullRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.SetClip(fullRectangle);
|
||||
}
|
||||
|
||||
if (ToggleSwitch.OffSideImage != null)
|
||||
{
|
||||
Size imageSize = ToggleSwitch.OffSideImage.Size;
|
||||
Rectangle imageRectangle;
|
||||
|
||||
int imageXPos = (int)fullRectangle.X;
|
||||
|
||||
if (ToggleSwitch.OffSideScaleImageToFit)
|
||||
{
|
||||
Size canvasSize = new Size((int)fullRectangle.Width, (int)fullRectangle.Height);
|
||||
Size resizedImageSize = ImageHelper.RescaleImageToFit(imageSize, canvasSize);
|
||||
|
||||
if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)resizedImageSize.Width) / 2));
|
||||
}
|
||||
else if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Far)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)resizedImageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)resizedImageSize.Height) / 2)), resizedImageSize.Width, resizedImageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)imageSize.Width) / 2));
|
||||
}
|
||||
else if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Far)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)imageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)imageSize.Height) / 2)), imageSize.Width, imageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImageUnscaled(ToggleSwitch.OffSideImage, imageRectangle);
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(ToggleSwitch.OffText))
|
||||
{
|
||||
SizeF textSize = g.MeasureString(ToggleSwitch.OffText, ToggleSwitch.OffFont);
|
||||
|
||||
float textXPos = fullRectangle.X;
|
||||
|
||||
if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
textXPos = (float)fullRectangle.X + (((float)fullRectangle.Width - (float)textSize.Width) / 2);
|
||||
}
|
||||
else if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Far)
|
||||
{
|
||||
textXPos = (float)fullRectangle.X + (float)fullRectangle.Width - (float)textSize.Width;
|
||||
}
|
||||
|
||||
RectangleF textRectangle = new RectangleF(textXPos, (float)fullRectangle.Y + (((float)fullRectangle.Height - (float)textSize.Height) / 2), textSize.Width, textSize.Height);
|
||||
|
||||
Color textForeColor = ToggleSwitch.OffForeColor;
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
textForeColor = textForeColor.ToGrayScale();
|
||||
|
||||
using (Brush textBrush = new SolidBrush(textForeColor))
|
||||
{
|
||||
g.DrawString(ToggleSwitch.OffText, ToggleSwitch.OffFont, textBrush, textRectangle);
|
||||
}
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
}
|
||||
|
||||
public override void RenderButton(Graphics g, Rectangle buttonRectangle)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
|
||||
|
||||
//Draw button surface
|
||||
Color buttonUpperSurfaceColor1 = ButtonNormalUpperSurfaceColor1;
|
||||
Color buttonUpperSurfaceColor2 = ButtonNormalUpperSurfaceColor2;
|
||||
Color buttonLowerSurfaceColor1 = ButtonNormalLowerSurfaceColor1;
|
||||
Color buttonLowerSurfaceColor2 = ButtonNormalLowerSurfaceColor2;
|
||||
|
||||
if (ToggleSwitch.IsButtonPressed)
|
||||
{
|
||||
buttonUpperSurfaceColor1 = ButtonPressedUpperSurfaceColor1;
|
||||
buttonUpperSurfaceColor2 = ButtonPressedUpperSurfaceColor2;
|
||||
buttonLowerSurfaceColor1 = ButtonPressedLowerSurfaceColor1;
|
||||
buttonLowerSurfaceColor2 = ButtonPressedLowerSurfaceColor2;
|
||||
}
|
||||
else if (ToggleSwitch.IsButtonHovered)
|
||||
{
|
||||
buttonUpperSurfaceColor1 = ButtonHoverUpperSurfaceColor1;
|
||||
buttonUpperSurfaceColor2 = ButtonHoverUpperSurfaceColor2;
|
||||
buttonLowerSurfaceColor1 = ButtonHoverLowerSurfaceColor1;
|
||||
buttonLowerSurfaceColor2 = ButtonHoverLowerSurfaceColor2;
|
||||
}
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
{
|
||||
buttonUpperSurfaceColor1 = buttonUpperSurfaceColor1.ToGrayScale();
|
||||
buttonUpperSurfaceColor2 = buttonUpperSurfaceColor2.ToGrayScale();
|
||||
buttonLowerSurfaceColor1 = buttonLowerSurfaceColor1.ToGrayScale();
|
||||
buttonLowerSurfaceColor2 = buttonLowerSurfaceColor2.ToGrayScale();
|
||||
}
|
||||
|
||||
buttonRectangle.Inflate(-1, -1);
|
||||
|
||||
int upperHeight = buttonRectangle.Height/2;
|
||||
|
||||
Rectangle upperGradientRect = new Rectangle(buttonRectangle.X, buttonRectangle.Y, buttonRectangle.Width, upperHeight);
|
||||
Rectangle lowerGradientRect = new Rectangle(buttonRectangle.X, buttonRectangle.Y + upperHeight, buttonRectangle.Width, buttonRectangle.Height - upperHeight);
|
||||
|
||||
using (GraphicsPath buttonPath = GetRoundedRectanglePath(buttonRectangle, CornerRadius))
|
||||
{
|
||||
g.SetClip(buttonPath);
|
||||
g.IntersectClip(upperGradientRect);
|
||||
|
||||
//Draw upper button surface gradient
|
||||
using (Brush buttonUpperSurfaceBrush = new LinearGradientBrush(buttonRectangle, buttonUpperSurfaceColor1, buttonUpperSurfaceColor2, LinearGradientMode.Vertical))
|
||||
{
|
||||
g.FillPath(buttonUpperSurfaceBrush, buttonPath);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
|
||||
g.SetClip(buttonPath);
|
||||
g.IntersectClip(lowerGradientRect);
|
||||
|
||||
//Draw lower button surface gradient
|
||||
using (Brush buttonLowerSurfaceBrush = new LinearGradientBrush(buttonRectangle, buttonLowerSurfaceColor1, buttonLowerSurfaceColor2, LinearGradientMode.Vertical))
|
||||
{
|
||||
g.FillPath(buttonLowerSurfaceBrush, buttonPath);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
|
||||
g.SetClip(buttonPath);
|
||||
|
||||
//Draw button border
|
||||
Color buttonBorderColor1 = ButtonNormalBorderColor1;
|
||||
Color buttonBorderColor2 = ButtonNormalBorderColor2;
|
||||
|
||||
if (ToggleSwitch.IsButtonPressed)
|
||||
{
|
||||
buttonBorderColor1 = ButtonPressedBorderColor1;
|
||||
buttonBorderColor2 = ButtonPressedBorderColor2;
|
||||
}
|
||||
else if (ToggleSwitch.IsButtonHovered)
|
||||
{
|
||||
buttonBorderColor1 = ButtonHoverBorderColor1;
|
||||
buttonBorderColor2 = ButtonHoverBorderColor2;
|
||||
}
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
{
|
||||
buttonBorderColor1 = buttonBorderColor1.ToGrayScale();
|
||||
buttonBorderColor2 = buttonBorderColor2.ToGrayScale();
|
||||
}
|
||||
|
||||
using (Brush buttonBorderBrush = new LinearGradientBrush(buttonRectangle, buttonBorderColor1, buttonBorderColor2, LinearGradientMode.Vertical))
|
||||
{
|
||||
using (Pen buttonBorderPen = new Pen(buttonBorderBrush))
|
||||
{
|
||||
g.DrawPath(buttonBorderPen, buttonPath);
|
||||
}
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
|
||||
//Draw button image
|
||||
Image buttonImage = ToggleSwitch.ButtonImage ?? (ToggleSwitch.Checked ? ToggleSwitch.OnButtonImage : ToggleSwitch.OffButtonImage);
|
||||
|
||||
if (buttonImage != null)
|
||||
{
|
||||
g.SetClip(buttonPath);
|
||||
|
||||
ToggleSwitch.ToggleSwitchButtonAlignment alignment = ToggleSwitch.ButtonImage != null ? ToggleSwitch.ButtonAlignment : (ToggleSwitch.Checked ? ToggleSwitch.OnButtonAlignment : ToggleSwitch.OffButtonAlignment);
|
||||
|
||||
Size imageSize = buttonImage.Size;
|
||||
|
||||
Rectangle imageRectangle;
|
||||
|
||||
int imageXPos = buttonRectangle.X;
|
||||
|
||||
bool scaleImage = ToggleSwitch.ButtonImage != null ? ToggleSwitch.ButtonScaleImageToFit : (ToggleSwitch.Checked ? ToggleSwitch.OnButtonScaleImageToFit : ToggleSwitch.OffButtonScaleImageToFit);
|
||||
|
||||
if (scaleImage)
|
||||
{
|
||||
Size canvasSize = buttonRectangle.Size;
|
||||
Size resizedImageSize = ImageHelper.RescaleImageToFit(imageSize, canvasSize);
|
||||
|
||||
if (alignment == ToggleSwitch.ToggleSwitchButtonAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)buttonRectangle.X + (((float)buttonRectangle.Width - (float)resizedImageSize.Width) / 2));
|
||||
}
|
||||
else if (alignment == ToggleSwitch.ToggleSwitchButtonAlignment.Right)
|
||||
{
|
||||
imageXPos = (int)((float)buttonRectangle.X + (float)buttonRectangle.Width - (float)resizedImageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)buttonRectangle.Y + (((float)buttonRectangle.Height - (float)resizedImageSize.Height) / 2)), resizedImageSize.Width, resizedImageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(buttonImage, imageRectangle, 0, 0, buttonImage.Width, buttonImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImage(buttonImage, imageRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (alignment == ToggleSwitch.ToggleSwitchButtonAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)buttonRectangle.X + (((float)buttonRectangle.Width - (float)imageSize.Width) / 2));
|
||||
}
|
||||
else if (alignment == ToggleSwitch.ToggleSwitchButtonAlignment.Right)
|
||||
{
|
||||
imageXPos = (int)((float)buttonRectangle.X + (float)buttonRectangle.Width - (float)imageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)buttonRectangle.Y + (((float)buttonRectangle.Height - (float)imageSize.Height) / 2)), imageSize.Width, imageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(buttonImage, imageRectangle, 0, 0, buttonImage.Width, buttonImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImageUnscaled(buttonImage, imageRectangle);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Render Method Implementations
|
||||
|
||||
#region Helper Method Implementations
|
||||
|
||||
public GraphicsPath GetRoundedRectanglePath(Rectangle rectangle, int radius)
|
||||
{
|
||||
GraphicsPath gp = new GraphicsPath();
|
||||
int diameter = 2*radius;
|
||||
|
||||
if (diameter > ToggleSwitch.Height)
|
||||
diameter = ToggleSwitch.Height;
|
||||
|
||||
if (diameter > ToggleSwitch.Width)
|
||||
diameter = ToggleSwitch.Width;
|
||||
|
||||
gp.AddArc(rectangle.X, rectangle.Y, diameter, diameter, 180, 90);
|
||||
gp.AddArc(rectangle.X + rectangle.Width - diameter, rectangle.Y, diameter, diameter, 270, 90);
|
||||
gp.AddArc(rectangle.X + rectangle.Width - diameter, rectangle.Y + rectangle.Height - diameter, diameter, diameter, 0, 90);
|
||||
gp.AddArc(rectangle.X, rectangle.Y + rectangle.Height - diameter, diameter, diameter, 90, 90);
|
||||
gp.CloseFigure();
|
||||
|
||||
return gp;
|
||||
}
|
||||
|
||||
public override int GetButtonWidth()
|
||||
{
|
||||
float buttonWidth = 1.61f*ToggleSwitch.Height;
|
||||
return (int) buttonWidth;
|
||||
}
|
||||
|
||||
public override Rectangle GetButtonRectangle()
|
||||
{
|
||||
int buttonWidth = GetButtonWidth();
|
||||
return GetButtonRectangle(buttonWidth);
|
||||
}
|
||||
|
||||
public override Rectangle GetButtonRectangle(int buttonWidth)
|
||||
{
|
||||
Rectangle buttonRect = new Rectangle(ToggleSwitch.ButtonValue, 0, buttonWidth, ToggleSwitch.Height);
|
||||
return buttonRect;
|
||||
}
|
||||
|
||||
#endregion Helper Method Implementations
|
||||
}
|
||||
}
|
660
ToggleSwitch/Renderers/ToggleSwitchIOS5Renderer.cs
Normal file
|
@ -0,0 +1,660 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using ToggleSwitch;
|
||||
|
||||
namespace JCS
|
||||
{
|
||||
public class ToggleSwitchIOS5Renderer : ToggleSwitchRendererBase
|
||||
{
|
||||
#region Constructor
|
||||
|
||||
public ToggleSwitchIOS5Renderer()
|
||||
{
|
||||
BorderColor = Color.FromArgb(255, 202, 202, 202);
|
||||
LeftSideUpperColor1 = Color.FromArgb(255, 48, 115, 189);
|
||||
LeftSideUpperColor2 = Color.FromArgb(255, 17, 123, 220);
|
||||
LeftSideLowerColor1 = Color.FromArgb(255, 65, 143, 218);
|
||||
LeftSideLowerColor2 = Color.FromArgb(255, 130, 190, 243);
|
||||
LeftSideUpperBorderColor = Color.FromArgb(150, 123, 157, 196);
|
||||
LeftSideLowerBorderColor = Color.FromArgb(150, 174, 208, 241);
|
||||
RightSideUpperColor1 = Color.FromArgb(255, 191, 191, 191);
|
||||
RightSideUpperColor2 = Color.FromArgb(255, 229, 229, 229);
|
||||
RightSideLowerColor1 = Color.FromArgb(255, 232, 232, 232);
|
||||
RightSideLowerColor2 = Color.FromArgb(255, 251, 251, 251);
|
||||
RightSideUpperBorderColor = Color.FromArgb(150, 175, 175, 175);
|
||||
RightSideLowerBorderColor = Color.FromArgb(150, 229, 230, 233);
|
||||
ButtonShadowColor = Color.Transparent;
|
||||
ButtonNormalOuterBorderColor = Color.FromArgb(255, 149, 172, 194);
|
||||
ButtonNormalInnerBorderColor = Color.FromArgb(255, 235, 235, 235);
|
||||
ButtonNormalSurfaceColor1 = Color.FromArgb(255, 216, 215, 216);
|
||||
ButtonNormalSurfaceColor2 = Color.FromArgb(255, 251, 250, 251);
|
||||
ButtonHoverOuterBorderColor = Color.FromArgb(255, 141, 163, 184);
|
||||
ButtonHoverInnerBorderColor = Color.FromArgb(255, 223, 223, 223);
|
||||
ButtonHoverSurfaceColor1 = Color.FromArgb(255, 205, 204, 205);
|
||||
ButtonHoverSurfaceColor2 = Color.FromArgb(255, 239, 238, 239);
|
||||
ButtonPressedOuterBorderColor = Color.FromArgb(255, 111, 128, 145);
|
||||
ButtonPressedInnerBorderColor = Color.FromArgb(255, 176, 176, 176);
|
||||
ButtonPressedSurfaceColor1 = Color.FromArgb(255, 162, 161, 162);
|
||||
ButtonPressedSurfaceColor2 = Color.FromArgb(255, 187, 187, 187);
|
||||
}
|
||||
|
||||
#endregion Constructor
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public Color BorderColor { get; set; }
|
||||
public Color LeftSideUpperColor1 { get; set; }
|
||||
public Color LeftSideUpperColor2 { get; set; }
|
||||
public Color LeftSideLowerColor1 { get; set; }
|
||||
public Color LeftSideLowerColor2 { get; set; }
|
||||
public Color LeftSideUpperBorderColor { get; set; }
|
||||
public Color LeftSideLowerBorderColor { get; set; }
|
||||
public Color RightSideUpperColor1 { get; set; }
|
||||
public Color RightSideUpperColor2 { get; set; }
|
||||
public Color RightSideLowerColor1 { get; set; }
|
||||
public Color RightSideLowerColor2 { get; set; }
|
||||
public Color RightSideUpperBorderColor { get; set; }
|
||||
public Color RightSideLowerBorderColor { get; set; }
|
||||
public Color ButtonShadowColor { get; set; }
|
||||
public Color ButtonNormalOuterBorderColor { get; set; }
|
||||
public Color ButtonNormalInnerBorderColor { get; set; }
|
||||
public Color ButtonNormalSurfaceColor1 { get; set; }
|
||||
public Color ButtonNormalSurfaceColor2 { get; set; }
|
||||
public Color ButtonHoverOuterBorderColor { get; set; }
|
||||
public Color ButtonHoverInnerBorderColor { get; set; }
|
||||
public Color ButtonHoverSurfaceColor1 { get; set; }
|
||||
public Color ButtonHoverSurfaceColor2 { get; set; }
|
||||
public Color ButtonPressedOuterBorderColor { get; set; }
|
||||
public Color ButtonPressedInnerBorderColor { get; set; }
|
||||
public Color ButtonPressedSurfaceColor1 { get; set; }
|
||||
public Color ButtonPressedSurfaceColor2 { get; set; }
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Render Method Implementations
|
||||
|
||||
public override void RenderBorder(Graphics g, Rectangle borderRectangle)
|
||||
{
|
||||
//Draw this one AFTER the button is drawn in the RenderButton method
|
||||
}
|
||||
|
||||
public override void RenderLeftToggleField(Graphics g, Rectangle leftRectangle, int totalToggleFieldWidth)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
|
||||
int buttonWidth = GetButtonWidth();
|
||||
|
||||
//Draw upper gradient field
|
||||
int gradientRectWidth = leftRectangle.Width + buttonWidth / 2;
|
||||
int upperGradientRectHeight = (int)((double)0.8*(double)(leftRectangle.Height - 2));
|
||||
|
||||
Rectangle controlRectangle = new Rectangle(0, 0, ToggleSwitch.Width, ToggleSwitch.Height);
|
||||
GraphicsPath controlClipPath = GetControlClipPath(controlRectangle);
|
||||
|
||||
Rectangle upperGradientRectangle = new Rectangle(leftRectangle.X, leftRectangle.Y + 1, gradientRectWidth, upperGradientRectHeight - 1);
|
||||
|
||||
g.SetClip(controlClipPath);
|
||||
g.IntersectClip(upperGradientRectangle);
|
||||
|
||||
using (GraphicsPath upperGradientPath = new GraphicsPath())
|
||||
{
|
||||
upperGradientPath.AddArc(upperGradientRectangle.X, upperGradientRectangle.Y, ToggleSwitch.Height, ToggleSwitch.Height, 135, 135);
|
||||
upperGradientPath.AddLine(upperGradientRectangle.X, upperGradientRectangle.Y, upperGradientRectangle.X + upperGradientRectangle.Width, upperGradientRectangle.Y);
|
||||
upperGradientPath.AddLine(upperGradientRectangle.X + upperGradientRectangle.Width, upperGradientRectangle.Y, upperGradientRectangle.X + upperGradientRectangle.Width, upperGradientRectangle.Y + upperGradientRectangle.Height);
|
||||
upperGradientPath.AddLine(upperGradientRectangle.X, upperGradientRectangle.Y + upperGradientRectangle.Height, upperGradientRectangle.X + upperGradientRectangle.Width, upperGradientRectangle.Y + upperGradientRectangle.Height);
|
||||
|
||||
Color upperColor1 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? LeftSideUpperColor1.ToGrayScale() : LeftSideUpperColor1;
|
||||
Color upperColor2 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? LeftSideUpperColor2.ToGrayScale() : LeftSideUpperColor2;
|
||||
|
||||
using (Brush upperGradientBrush = new LinearGradientBrush(upperGradientRectangle, upperColor1, upperColor2, LinearGradientMode.Vertical))
|
||||
{
|
||||
g.FillPath(upperGradientBrush, upperGradientPath);
|
||||
}
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
|
||||
//Draw lower gradient field
|
||||
int lowerGradientRectHeight = (int)Math.Ceiling((double)0.5 * (double)(leftRectangle.Height - 2));
|
||||
|
||||
Rectangle lowerGradientRectangle = new Rectangle(leftRectangle.X, leftRectangle.Y + (leftRectangle.Height / 2), gradientRectWidth, lowerGradientRectHeight);
|
||||
|
||||
g.SetClip(controlClipPath);
|
||||
g.IntersectClip(lowerGradientRectangle);
|
||||
|
||||
using (GraphicsPath lowerGradientPath = new GraphicsPath())
|
||||
{
|
||||
lowerGradientPath.AddArc(1, lowerGradientRectangle.Y, (int) (0.75*(ToggleSwitch.Height - 1)), ToggleSwitch.Height - 1, 215, 45); //Arc from side to top
|
||||
lowerGradientPath.AddLine(lowerGradientRectangle.X + buttonWidth/2, lowerGradientRectangle.Y, lowerGradientRectangle.X + lowerGradientRectangle.Width, lowerGradientRectangle.Y);
|
||||
lowerGradientPath.AddLine(lowerGradientRectangle.X + lowerGradientRectangle.Width, lowerGradientRectangle.Y, lowerGradientRectangle.X + lowerGradientRectangle.Width, lowerGradientRectangle.Y + lowerGradientRectangle.Height);
|
||||
lowerGradientPath.AddLine(lowerGradientRectangle.X + buttonWidth/4, lowerGradientRectangle.Y + lowerGradientRectangle.Height, lowerGradientRectangle.X + lowerGradientRectangle.Width, lowerGradientRectangle.Y + lowerGradientRectangle.Height);
|
||||
lowerGradientPath.AddArc(1, 1, ToggleSwitch.Height - 1, ToggleSwitch.Height - 1, 90, 70); //Arc from side to bottom
|
||||
|
||||
Color lowerColor1 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? LeftSideLowerColor1.ToGrayScale() : LeftSideLowerColor1;
|
||||
Color lowerColor2 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? LeftSideLowerColor2.ToGrayScale() : LeftSideLowerColor2;
|
||||
|
||||
using (Brush lowerGradientBrush = new LinearGradientBrush(lowerGradientRectangle, lowerColor1, lowerColor2, LinearGradientMode.Vertical))
|
||||
{
|
||||
g.FillPath(lowerGradientBrush, lowerGradientPath);
|
||||
}
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
|
||||
controlRectangle = new Rectangle(0, 0, ToggleSwitch.Width, ToggleSwitch.Height);
|
||||
controlClipPath = GetControlClipPath(controlRectangle);
|
||||
|
||||
g.SetClip(controlClipPath);
|
||||
|
||||
//Draw upper inside border
|
||||
Color upperBordercolor = LeftSideUpperBorderColor;
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
upperBordercolor = upperBordercolor.ToGrayScale();
|
||||
|
||||
using (Pen upperBorderPen = new Pen(upperBordercolor))
|
||||
{
|
||||
g.DrawLine(upperBorderPen, leftRectangle.X, leftRectangle.Y + 1, leftRectangle.X + leftRectangle.Width + (buttonWidth / 2), leftRectangle.Y + 1);
|
||||
}
|
||||
|
||||
//Draw lower inside border
|
||||
Color lowerBordercolor = LeftSideLowerBorderColor;
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
lowerBordercolor = lowerBordercolor.ToGrayScale();
|
||||
|
||||
using (Pen lowerBorderPen = new Pen(lowerBordercolor))
|
||||
{
|
||||
g.DrawLine(lowerBorderPen, leftRectangle.X, leftRectangle.Y + leftRectangle.Height - 1, leftRectangle.X + leftRectangle.Width + (buttonWidth / 2), leftRectangle.Y + leftRectangle.Height - 1);
|
||||
}
|
||||
|
||||
//Draw image or text
|
||||
if (ToggleSwitch.OnSideImage != null || !string.IsNullOrEmpty(ToggleSwitch.OnText))
|
||||
{
|
||||
RectangleF fullRectangle = new RectangleF(leftRectangle.X + 2 - (totalToggleFieldWidth - leftRectangle.Width), 2, totalToggleFieldWidth - 2, ToggleSwitch.Height - 4);
|
||||
|
||||
g.IntersectClip(fullRectangle);
|
||||
|
||||
if (ToggleSwitch.OnSideImage != null)
|
||||
{
|
||||
Size imageSize = ToggleSwitch.OnSideImage.Size;
|
||||
Rectangle imageRectangle;
|
||||
|
||||
int imageXPos = (int)fullRectangle.X;
|
||||
|
||||
if (ToggleSwitch.OnSideScaleImageToFit)
|
||||
{
|
||||
Size canvasSize = new Size((int)fullRectangle.Width, (int)fullRectangle.Height);
|
||||
Size resizedImageSize = ImageHelper.RescaleImageToFit(imageSize, canvasSize);
|
||||
|
||||
if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)resizedImageSize.Width) / 2));
|
||||
}
|
||||
else if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Near)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)resizedImageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)resizedImageSize.Height) / 2)), resizedImageSize.Width, resizedImageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)imageSize.Width) / 2));
|
||||
}
|
||||
else if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Near)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)imageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)imageSize.Height) / 2)), imageSize.Width, imageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImageUnscaled(ToggleSwitch.OnSideImage, imageRectangle);
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(ToggleSwitch.OnText))
|
||||
{
|
||||
SizeF textSize = g.MeasureString(ToggleSwitch.OnText, ToggleSwitch.OnFont);
|
||||
|
||||
float textXPos = fullRectangle.X;
|
||||
|
||||
if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
textXPos = (float)fullRectangle.X + (((float)fullRectangle.Width - (float)textSize.Width) / 2);
|
||||
}
|
||||
else if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Near)
|
||||
{
|
||||
textXPos = (float)fullRectangle.X + (float)fullRectangle.Width - (float)textSize.Width;
|
||||
}
|
||||
|
||||
RectangleF textRectangle = new RectangleF(textXPos, (float)fullRectangle.Y + (((float)fullRectangle.Height - (float)textSize.Height) / 2), textSize.Width, textSize.Height);
|
||||
|
||||
Color textForeColor = ToggleSwitch.OnForeColor;
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
textForeColor = textForeColor.ToGrayScale();
|
||||
|
||||
using (Brush textBrush = new SolidBrush(textForeColor))
|
||||
{
|
||||
g.DrawString(ToggleSwitch.OnText, ToggleSwitch.OnFont, textBrush, textRectangle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
|
||||
public override void RenderRightToggleField(Graphics g, Rectangle rightRectangle, int totalToggleFieldWidth)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
|
||||
Rectangle buttonRectangle = GetButtonRectangle();
|
||||
|
||||
Rectangle controlRectangle = new Rectangle(0, 0, ToggleSwitch.Width, ToggleSwitch.Height);
|
||||
GraphicsPath controlClipPath = GetControlClipPath(controlRectangle);
|
||||
|
||||
//Draw upper gradient field
|
||||
int gradientRectWidth = rightRectangle.Width + buttonRectangle.Width / 2;
|
||||
int upperGradientRectHeight = (int)((double)0.8 * (double)(rightRectangle.Height - 2));
|
||||
|
||||
Rectangle upperGradientRectangle = new Rectangle(rightRectangle.X - buttonRectangle.Width / 2, rightRectangle.Y + 1, gradientRectWidth - 1, upperGradientRectHeight - 1);
|
||||
|
||||
g.SetClip(controlClipPath);
|
||||
g.IntersectClip(upperGradientRectangle);
|
||||
|
||||
using (GraphicsPath upperGradientPath = new GraphicsPath())
|
||||
{
|
||||
upperGradientPath.AddLine(upperGradientRectangle.X, upperGradientRectangle.Y, upperGradientRectangle.X + upperGradientRectangle.Width, upperGradientRectangle.Y);
|
||||
upperGradientPath.AddArc(upperGradientRectangle.X + upperGradientRectangle.Width - ToggleSwitch.Height + 1, upperGradientRectangle.Y - 1, ToggleSwitch.Height, ToggleSwitch.Height, 270, 115);
|
||||
upperGradientPath.AddLine(upperGradientRectangle.X + upperGradientRectangle.Width, upperGradientRectangle.Y + upperGradientRectangle.Height, upperGradientRectangle.X, upperGradientRectangle.Y + upperGradientRectangle.Height);
|
||||
upperGradientPath.AddLine(upperGradientRectangle.X, upperGradientRectangle.Y + upperGradientRectangle.Height, upperGradientRectangle.X, upperGradientRectangle.Y);
|
||||
|
||||
Color upperColor1 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? RightSideUpperColor1.ToGrayScale() : RightSideUpperColor1;
|
||||
Color upperColor2 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? RightSideUpperColor2.ToGrayScale() : RightSideUpperColor2;
|
||||
|
||||
using (Brush upperGradientBrush = new LinearGradientBrush(upperGradientRectangle, upperColor1, upperColor2, LinearGradientMode.Vertical))
|
||||
{
|
||||
g.FillPath(upperGradientBrush, upperGradientPath);
|
||||
}
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
|
||||
//Draw lower gradient field
|
||||
int lowerGradientRectHeight = (int)Math.Ceiling((double)0.5 * (double)(rightRectangle.Height - 2));
|
||||
|
||||
Rectangle lowerGradientRectangle = new Rectangle(rightRectangle.X - buttonRectangle.Width / 2, rightRectangle.Y + (rightRectangle.Height / 2), gradientRectWidth - 1, lowerGradientRectHeight);
|
||||
|
||||
g.SetClip(controlClipPath);
|
||||
g.IntersectClip(lowerGradientRectangle);
|
||||
|
||||
using (GraphicsPath lowerGradientPath = new GraphicsPath())
|
||||
{
|
||||
lowerGradientPath.AddLine(lowerGradientRectangle.X, lowerGradientRectangle.Y, lowerGradientRectangle.X + lowerGradientRectangle.Width, lowerGradientRectangle.Y);
|
||||
lowerGradientPath.AddArc(lowerGradientRectangle.X + lowerGradientRectangle.Width - (int)(0.75 * (ToggleSwitch.Height - 1)), lowerGradientRectangle.Y, (int)(0.75 * (ToggleSwitch.Height - 1)), ToggleSwitch.Height - 1, 270, 45); //Arc from top to side
|
||||
lowerGradientPath.AddArc(ToggleSwitch.Width - ToggleSwitch.Height, 0, ToggleSwitch.Height, ToggleSwitch.Height, 20, 70); //Arc from side to bottom
|
||||
lowerGradientPath.AddLine(lowerGradientRectangle.X + lowerGradientRectangle.Width, lowerGradientRectangle.Y + lowerGradientRectangle.Height, lowerGradientRectangle.X, lowerGradientRectangle.Y + lowerGradientRectangle.Height);
|
||||
lowerGradientPath.AddLine(lowerGradientRectangle.X, lowerGradientRectangle.Y + lowerGradientRectangle.Height, lowerGradientRectangle.X, lowerGradientRectangle.Y);
|
||||
|
||||
Color lowerColor1 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? RightSideLowerColor1.ToGrayScale() : RightSideLowerColor1;
|
||||
Color lowerColor2 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? RightSideLowerColor2.ToGrayScale() : RightSideLowerColor2;
|
||||
|
||||
using (Brush lowerGradientBrush = new LinearGradientBrush(lowerGradientRectangle, lowerColor1, lowerColor2, LinearGradientMode.Vertical))
|
||||
{
|
||||
g.FillPath(lowerGradientBrush, lowerGradientPath);
|
||||
}
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
|
||||
controlRectangle = new Rectangle(0, 0, ToggleSwitch.Width, ToggleSwitch.Height);
|
||||
controlClipPath = GetControlClipPath(controlRectangle);
|
||||
|
||||
g.SetClip(controlClipPath);
|
||||
|
||||
//Draw upper inside border
|
||||
Color upperBordercolor = RightSideUpperBorderColor;
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
upperBordercolor = upperBordercolor.ToGrayScale();
|
||||
|
||||
using (Pen upperBorderPen = new Pen(upperBordercolor))
|
||||
{
|
||||
g.DrawLine(upperBorderPen, rightRectangle.X - (buttonRectangle.Width / 2), rightRectangle.Y + 1, rightRectangle.X + rightRectangle.Width, rightRectangle.Y + 1);
|
||||
}
|
||||
|
||||
//Draw lower inside border
|
||||
Color lowerBordercolor = RightSideLowerBorderColor;
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
lowerBordercolor = lowerBordercolor.ToGrayScale();
|
||||
|
||||
using (Pen lowerBorderPen = new Pen(lowerBordercolor))
|
||||
{
|
||||
g.DrawLine(lowerBorderPen, rightRectangle.X - (buttonRectangle.Width / 2), rightRectangle.Y + rightRectangle.Height - 1, rightRectangle.X + rightRectangle.Width, rightRectangle.Y + rightRectangle.Height - 1);
|
||||
}
|
||||
|
||||
//Draw image or text
|
||||
if (ToggleSwitch.OffSideImage != null || !string.IsNullOrEmpty(ToggleSwitch.OffText))
|
||||
{
|
||||
RectangleF fullRectangle = new RectangleF(rightRectangle.X, 2, totalToggleFieldWidth - 2, ToggleSwitch.Height - 4);
|
||||
|
||||
g.IntersectClip(fullRectangle);
|
||||
|
||||
if (ToggleSwitch.OffSideImage != null)
|
||||
{
|
||||
Size imageSize = ToggleSwitch.OffSideImage.Size;
|
||||
Rectangle imageRectangle;
|
||||
|
||||
int imageXPos = (int)fullRectangle.X;
|
||||
|
||||
if (ToggleSwitch.OffSideScaleImageToFit)
|
||||
{
|
||||
Size canvasSize = new Size((int)fullRectangle.Width, (int)fullRectangle.Height);
|
||||
Size resizedImageSize = ImageHelper.RescaleImageToFit(imageSize, canvasSize);
|
||||
|
||||
if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)resizedImageSize.Width) / 2));
|
||||
}
|
||||
else if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Far)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)resizedImageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)resizedImageSize.Height) / 2)), resizedImageSize.Width, resizedImageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)imageSize.Width) / 2));
|
||||
}
|
||||
else if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Far)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)imageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)imageSize.Height) / 2)), imageSize.Width, imageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImageUnscaled(ToggleSwitch.OffSideImage, imageRectangle);
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(ToggleSwitch.OffText))
|
||||
{
|
||||
SizeF textSize = g.MeasureString(ToggleSwitch.OffText, ToggleSwitch.OffFont);
|
||||
|
||||
float textXPos = fullRectangle.X;
|
||||
|
||||
if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
textXPos = (float)fullRectangle.X + (((float)fullRectangle.Width - (float)textSize.Width) / 2);
|
||||
}
|
||||
else if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Far)
|
||||
{
|
||||
textXPos = (float)fullRectangle.X + (float)fullRectangle.Width - (float)textSize.Width;
|
||||
}
|
||||
|
||||
RectangleF textRectangle = new RectangleF(textXPos, (float)fullRectangle.Y + (((float)fullRectangle.Height - (float)textSize.Height) / 2), textSize.Width, textSize.Height);
|
||||
|
||||
Color textForeColor = ToggleSwitch.OffForeColor;
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
textForeColor = textForeColor.ToGrayScale();
|
||||
|
||||
using (Brush textBrush = new SolidBrush(textForeColor))
|
||||
{
|
||||
g.DrawString(ToggleSwitch.OffText, ToggleSwitch.OffFont, textBrush, textRectangle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
|
||||
public override void RenderButton(Graphics g, Rectangle buttonRectangle)
|
||||
{
|
||||
if (ToggleSwitch.IsButtonOnLeftSide)
|
||||
buttonRectangle.X += 1;
|
||||
else if (ToggleSwitch.IsButtonOnRightSide)
|
||||
buttonRectangle.X -= 1;
|
||||
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
|
||||
//Draw button shadow
|
||||
buttonRectangle.Inflate(1, 1);
|
||||
|
||||
Rectangle shadowClipRectangle = new Rectangle(buttonRectangle.Location, buttonRectangle.Size);
|
||||
shadowClipRectangle.Inflate(0, -1);
|
||||
|
||||
if (ToggleSwitch.IsButtonOnLeftSide)
|
||||
{
|
||||
shadowClipRectangle.X += shadowClipRectangle.Width / 2;
|
||||
shadowClipRectangle.Width = shadowClipRectangle.Width / 2;
|
||||
}
|
||||
else if (ToggleSwitch.IsButtonOnRightSide)
|
||||
{
|
||||
shadowClipRectangle.Width = shadowClipRectangle.Width / 2;
|
||||
}
|
||||
|
||||
g.SetClip(shadowClipRectangle);
|
||||
|
||||
Color buttonShadowColor = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? ButtonShadowColor.ToGrayScale() : ButtonShadowColor;
|
||||
|
||||
using (Pen buttonShadowPen = new Pen(buttonShadowColor))
|
||||
{
|
||||
g.DrawEllipse(buttonShadowPen, buttonRectangle);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
|
||||
buttonRectangle.Inflate(-1, -1);
|
||||
|
||||
//Draw outer button border
|
||||
Color buttonOuterBorderColor = ButtonNormalOuterBorderColor;
|
||||
|
||||
if (ToggleSwitch.IsButtonPressed)
|
||||
buttonOuterBorderColor = ButtonPressedOuterBorderColor;
|
||||
else if (ToggleSwitch.IsButtonHovered)
|
||||
buttonOuterBorderColor = ButtonHoverOuterBorderColor;
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
buttonOuterBorderColor = buttonOuterBorderColor.ToGrayScale();
|
||||
|
||||
using (Brush outerBorderBrush = new SolidBrush(buttonOuterBorderColor))
|
||||
{
|
||||
g.FillEllipse(outerBorderBrush, buttonRectangle);
|
||||
}
|
||||
|
||||
//Draw inner button border
|
||||
buttonRectangle.Inflate(-1, -1);
|
||||
|
||||
Color buttonInnerBorderColor = ButtonNormalInnerBorderColor;
|
||||
|
||||
if (ToggleSwitch.IsButtonPressed)
|
||||
buttonInnerBorderColor = ButtonPressedInnerBorderColor;
|
||||
else if (ToggleSwitch.IsButtonHovered)
|
||||
buttonInnerBorderColor = ButtonHoverInnerBorderColor;
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
buttonInnerBorderColor = buttonInnerBorderColor.ToGrayScale();
|
||||
|
||||
using (Brush innerBorderBrush = new SolidBrush(buttonInnerBorderColor))
|
||||
{
|
||||
g.FillEllipse(innerBorderBrush, buttonRectangle);
|
||||
}
|
||||
|
||||
//Draw button surface
|
||||
buttonRectangle.Inflate(-1, -1);
|
||||
|
||||
Color buttonUpperSurfaceColor = ButtonNormalSurfaceColor1;
|
||||
|
||||
if (ToggleSwitch.IsButtonPressed)
|
||||
buttonUpperSurfaceColor = ButtonPressedSurfaceColor1;
|
||||
else if (ToggleSwitch.IsButtonHovered)
|
||||
buttonUpperSurfaceColor = ButtonHoverSurfaceColor1;
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
buttonUpperSurfaceColor = buttonUpperSurfaceColor.ToGrayScale();
|
||||
|
||||
Color buttonLowerSurfaceColor = ButtonNormalSurfaceColor2;
|
||||
|
||||
if (ToggleSwitch.IsButtonPressed)
|
||||
buttonLowerSurfaceColor = ButtonPressedSurfaceColor2;
|
||||
else if (ToggleSwitch.IsButtonHovered)
|
||||
buttonLowerSurfaceColor = ButtonHoverSurfaceColor2;
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
buttonLowerSurfaceColor = buttonLowerSurfaceColor.ToGrayScale();
|
||||
|
||||
using (Brush buttonSurfaceBrush = new LinearGradientBrush(buttonRectangle, buttonUpperSurfaceColor, buttonLowerSurfaceColor, LinearGradientMode.Vertical))
|
||||
{
|
||||
g.FillEllipse(buttonSurfaceBrush, buttonRectangle);
|
||||
}
|
||||
|
||||
g.CompositingMode = CompositingMode.SourceOver;
|
||||
g.CompositingQuality = CompositingQuality.HighQuality;
|
||||
|
||||
//Draw outer control border
|
||||
Rectangle controlRectangle = new Rectangle(0, 0, ToggleSwitch.Width, ToggleSwitch.Height);
|
||||
|
||||
using (GraphicsPath borderPath = GetControlClipPath(controlRectangle))
|
||||
{
|
||||
Color controlBorderColor = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? BorderColor.ToGrayScale() : BorderColor;
|
||||
|
||||
using (Pen borderPen = new Pen(controlBorderColor))
|
||||
{
|
||||
g.DrawPath(borderPen, borderPath);
|
||||
}
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
|
||||
//Draw button image
|
||||
Image buttonImage = ToggleSwitch.ButtonImage ?? (ToggleSwitch.Checked ? ToggleSwitch.OnButtonImage : ToggleSwitch.OffButtonImage);
|
||||
|
||||
if (buttonImage != null)
|
||||
{
|
||||
g.SetClip(GetButtonClipPath());
|
||||
|
||||
ToggleSwitch.ToggleSwitchButtonAlignment alignment = ToggleSwitch.ButtonImage != null ? ToggleSwitch.ButtonAlignment : (ToggleSwitch.Checked ? ToggleSwitch.OnButtonAlignment : ToggleSwitch.OffButtonAlignment);
|
||||
|
||||
Size imageSize = buttonImage.Size;
|
||||
|
||||
Rectangle imageRectangle;
|
||||
|
||||
int imageXPos = buttonRectangle.X;
|
||||
|
||||
bool scaleImage = ToggleSwitch.ButtonImage != null ? ToggleSwitch.ButtonScaleImageToFit : (ToggleSwitch.Checked ? ToggleSwitch.OnButtonScaleImageToFit : ToggleSwitch.OffButtonScaleImageToFit);
|
||||
|
||||
if (scaleImage)
|
||||
{
|
||||
Size canvasSize = buttonRectangle.Size;
|
||||
Size resizedImageSize = ImageHelper.RescaleImageToFit(imageSize, canvasSize);
|
||||
|
||||
if (alignment == ToggleSwitch.ToggleSwitchButtonAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)buttonRectangle.X + (((float)buttonRectangle.Width - (float)resizedImageSize.Width) / 2));
|
||||
}
|
||||
else if (alignment == ToggleSwitch.ToggleSwitchButtonAlignment.Right)
|
||||
{
|
||||
imageXPos = (int)((float)buttonRectangle.X + (float)buttonRectangle.Width - (float)resizedImageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)buttonRectangle.Y + (((float)buttonRectangle.Height - (float)resizedImageSize.Height) / 2)), resizedImageSize.Width, resizedImageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(buttonImage, imageRectangle, 0,0, buttonImage.Width, buttonImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImage(buttonImage, imageRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (alignment == ToggleSwitch.ToggleSwitchButtonAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)buttonRectangle.X + (((float)buttonRectangle.Width - (float)imageSize.Width) / 2));
|
||||
}
|
||||
else if (alignment == ToggleSwitch.ToggleSwitchButtonAlignment.Right)
|
||||
{
|
||||
imageXPos = (int)((float)buttonRectangle.X + (float)buttonRectangle.Width - (float)imageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)buttonRectangle.Y + (((float)buttonRectangle.Height - (float)imageSize.Height) / 2)), imageSize.Width, imageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(buttonImage, imageRectangle, 0, 0, buttonImage.Width, buttonImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImageUnscaled(buttonImage, imageRectangle);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Render Method Implementations
|
||||
|
||||
#region Helper Method Implementations
|
||||
|
||||
public GraphicsPath GetControlClipPath(Rectangle controlRectangle)
|
||||
{
|
||||
GraphicsPath borderPath = new GraphicsPath();
|
||||
borderPath.AddArc(controlRectangle.X, controlRectangle.Y, controlRectangle.Height, controlRectangle.Height, 90, 180);
|
||||
borderPath.AddArc(controlRectangle.X + controlRectangle.Width - controlRectangle.Height, controlRectangle.Y, controlRectangle.Height, controlRectangle.Height, 270, 180);
|
||||
borderPath.CloseFigure();
|
||||
|
||||
return borderPath;
|
||||
}
|
||||
|
||||
public GraphicsPath GetButtonClipPath()
|
||||
{
|
||||
Rectangle buttonRectangle = GetButtonRectangle();
|
||||
|
||||
GraphicsPath buttonPath = new GraphicsPath();
|
||||
|
||||
buttonPath.AddArc(buttonRectangle.X, buttonRectangle.Y, buttonRectangle.Height, buttonRectangle.Height, 0, 360);
|
||||
|
||||
return buttonPath;
|
||||
}
|
||||
|
||||
public override int GetButtonWidth()
|
||||
{
|
||||
return ToggleSwitch.Height - 2;
|
||||
}
|
||||
|
||||
public override Rectangle GetButtonRectangle()
|
||||
{
|
||||
int buttonWidth = GetButtonWidth();
|
||||
return GetButtonRectangle(buttonWidth);
|
||||
}
|
||||
|
||||
public override Rectangle GetButtonRectangle(int buttonWidth)
|
||||
{
|
||||
Rectangle buttonRect = new Rectangle(ToggleSwitch.ButtonValue, 1, buttonWidth, buttonWidth);
|
||||
return buttonRect;
|
||||
}
|
||||
|
||||
#endregion Helper Method Implementations
|
||||
}
|
||||
}
|
605
ToggleSwitch/Renderers/ToggleSwitchIphoneRenderer.cs
Normal file
|
@ -0,0 +1,605 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using ToggleSwitch;
|
||||
|
||||
namespace JCS
|
||||
{
|
||||
public class ToggleSwitchIphoneRenderer : ToggleSwitchRendererBase, IDisposable
|
||||
{
|
||||
#region Constructor
|
||||
|
||||
private GraphicsPath _innerControlPath = null;
|
||||
|
||||
public ToggleSwitchIphoneRenderer()
|
||||
{
|
||||
OuterBorderColor = Color.FromArgb(255, 205, 205, 207);
|
||||
InnerBorderColor1 = Color.FromArgb(200, 205, 205, 207);
|
||||
InnerBorderColor2 = Color.FromArgb(200, 205, 205, 207);
|
||||
LeftSideBackColor1 = Color.FromArgb(255, 50, 101, 161);
|
||||
LeftSideBackColor2 = Color.FromArgb(255, 123, 174, 229);
|
||||
RightSideBackColor1 = Color.FromArgb(255, 161, 161, 161);
|
||||
RightSideBackColor2 = Color.FromArgb(255, 250, 250, 250);
|
||||
ButtonNormalBorderColor1 = Color.FromArgb(255, 172, 172, 172);
|
||||
ButtonNormalBorderColor2 = Color.FromArgb(255, 196, 196, 196);
|
||||
ButtonNormalSurfaceColor1 = Color.FromArgb(255, 216, 215, 216);
|
||||
ButtonNormalSurfaceColor2 = Color.FromArgb(255, 251, 250, 251);
|
||||
ButtonHoverBorderColor1 = Color.FromArgb(255, 163, 163, 163);
|
||||
ButtonHoverBorderColor2 = Color.FromArgb(255, 185, 185, 185);
|
||||
ButtonHoverSurfaceColor1 = Color.FromArgb(255, 205, 204, 205);
|
||||
ButtonHoverSurfaceColor2 = Color.FromArgb(255, 239, 238, 239);
|
||||
ButtonPressedBorderColor1 = Color.FromArgb(255, 129, 129, 129);
|
||||
ButtonPressedBorderColor2 = Color.FromArgb(255, 146, 146, 146);
|
||||
ButtonPressedSurfaceColor1 = Color.FromArgb(255, 162, 161, 162);
|
||||
ButtonPressedSurfaceColor2 = Color.FromArgb(255, 188, 187, 188);
|
||||
ButtonShadowColor1 = Color.FromArgb(50, 0, 0, 0);
|
||||
ButtonShadowColor2 = Color.FromArgb(0, 0, 0, 0);
|
||||
|
||||
ButtonShadowWidth = 7;
|
||||
CornerRadius = 6;
|
||||
ButtonCornerRadius = 9;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_innerControlPath != null)
|
||||
_innerControlPath.Dispose();
|
||||
}
|
||||
|
||||
#endregion Constructor
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public Color OuterBorderColor { get; set; }
|
||||
public Color InnerBorderColor1 { get; set; }
|
||||
public Color InnerBorderColor2 { get; set; }
|
||||
public Color LeftSideBackColor1 { get; set; }
|
||||
public Color LeftSideBackColor2 { get; set; }
|
||||
public Color RightSideBackColor1 { get; set; }
|
||||
public Color RightSideBackColor2 { get; set; }
|
||||
public Color ButtonNormalBorderColor1 { get; set; }
|
||||
public Color ButtonNormalBorderColor2 { get; set; }
|
||||
public Color ButtonNormalSurfaceColor1 { get; set; }
|
||||
public Color ButtonNormalSurfaceColor2 { get; set; }
|
||||
public Color ButtonHoverBorderColor1 { get; set; }
|
||||
public Color ButtonHoverBorderColor2 { get; set; }
|
||||
public Color ButtonHoverSurfaceColor1 { get; set; }
|
||||
public Color ButtonHoverSurfaceColor2 { get; set; }
|
||||
public Color ButtonPressedBorderColor1 { get; set; }
|
||||
public Color ButtonPressedBorderColor2 { get; set; }
|
||||
public Color ButtonPressedSurfaceColor1 { get; set; }
|
||||
public Color ButtonPressedSurfaceColor2 { get; set; }
|
||||
public Color ButtonShadowColor1 { get; set; }
|
||||
public Color ButtonShadowColor2 { get; set; }
|
||||
|
||||
public int ButtonShadowWidth { get; set; }
|
||||
public int CornerRadius { get; set; }
|
||||
public int ButtonCornerRadius { get; set; }
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Render Method Implementations
|
||||
|
||||
public override void RenderBorder(Graphics g, Rectangle borderRectangle)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
|
||||
|
||||
//Draw outer border
|
||||
using (GraphicsPath outerBorderPath = GetRoundedRectanglePath(borderRectangle, CornerRadius))
|
||||
{
|
||||
g.SetClip(outerBorderPath);
|
||||
|
||||
Color outerBorderColor = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? OuterBorderColor.ToGrayScale() : OuterBorderColor;
|
||||
|
||||
using (Brush outerBorderBrush = new SolidBrush(outerBorderColor))
|
||||
{
|
||||
g.FillPath(outerBorderBrush, outerBorderPath);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
|
||||
//Draw inner border
|
||||
Rectangle innerborderRectangle = new Rectangle(borderRectangle.X + 1, borderRectangle.Y + 1, borderRectangle.Width - 2, borderRectangle.Height - 2);
|
||||
|
||||
using (GraphicsPath innerBorderPath = GetRoundedRectanglePath(innerborderRectangle, CornerRadius))
|
||||
{
|
||||
g.SetClip(innerBorderPath);
|
||||
|
||||
Color borderColor1 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? InnerBorderColor1.ToGrayScale() : InnerBorderColor1;
|
||||
Color borderColor2 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? InnerBorderColor2.ToGrayScale() : InnerBorderColor2;
|
||||
|
||||
using (Brush borderBrush = new LinearGradientBrush(borderRectangle, borderColor1, borderColor2, LinearGradientMode.Vertical))
|
||||
{
|
||||
g.FillPath(borderBrush, innerBorderPath);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
|
||||
Rectangle backgroundRectangle = new Rectangle(borderRectangle.X + 2, borderRectangle.Y + 2, borderRectangle.Width - 4, borderRectangle.Height - 4);
|
||||
_innerControlPath = GetRoundedRectanglePath(backgroundRectangle, CornerRadius);
|
||||
}
|
||||
|
||||
public override void RenderLeftToggleField(Graphics g, Rectangle leftRectangle, int totalToggleFieldWidth)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
|
||||
|
||||
int buttonWidth = GetButtonWidth();
|
||||
|
||||
//Draw inner background
|
||||
int gradientRectWidth = leftRectangle.Width + buttonWidth / 2;
|
||||
Rectangle gradientRectangle = new Rectangle(leftRectangle.X, leftRectangle.Y, gradientRectWidth, leftRectangle.Height);
|
||||
|
||||
Color leftSideBackColor1 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? LeftSideBackColor1.ToGrayScale() : LeftSideBackColor1;
|
||||
Color leftSideBackColor2 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? LeftSideBackColor2.ToGrayScale() : LeftSideBackColor2;
|
||||
|
||||
if (_innerControlPath != null)
|
||||
{
|
||||
g.SetClip(_innerControlPath);
|
||||
g.IntersectClip(gradientRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.SetClip(gradientRectangle);
|
||||
}
|
||||
|
||||
using (Brush backgroundBrush = new LinearGradientBrush(gradientRectangle, leftSideBackColor1, leftSideBackColor2, LinearGradientMode.Vertical))
|
||||
{
|
||||
g.FillRectangle(backgroundBrush, gradientRectangle);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
|
||||
Rectangle leftShadowRectangle = new Rectangle();
|
||||
leftShadowRectangle.X = leftRectangle.X + leftRectangle.Width - ButtonShadowWidth;
|
||||
leftShadowRectangle.Y = leftRectangle.Y;
|
||||
leftShadowRectangle.Width = ButtonShadowWidth + CornerRadius;
|
||||
leftShadowRectangle.Height = leftRectangle.Height;
|
||||
|
||||
if (_innerControlPath != null)
|
||||
{
|
||||
g.SetClip(_innerControlPath);
|
||||
g.IntersectClip(leftShadowRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.SetClip(leftShadowRectangle);
|
||||
}
|
||||
|
||||
using (Brush buttonShadowBrush = new LinearGradientBrush(leftShadowRectangle, ButtonShadowColor2, ButtonShadowColor1, LinearGradientMode.Horizontal))
|
||||
{
|
||||
g.FillRectangle(buttonShadowBrush, leftShadowRectangle);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
|
||||
//Draw image or text
|
||||
if (ToggleSwitch.OnSideImage != null || !string.IsNullOrEmpty(ToggleSwitch.OnText))
|
||||
{
|
||||
RectangleF fullRectangle = new RectangleF(leftRectangle.X + 1 - (totalToggleFieldWidth - leftRectangle.Width), 1, totalToggleFieldWidth - 1, ToggleSwitch.Height - 2);
|
||||
|
||||
if (_innerControlPath != null)
|
||||
{
|
||||
g.SetClip(_innerControlPath);
|
||||
g.IntersectClip(fullRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.SetClip(fullRectangle);
|
||||
}
|
||||
|
||||
if (ToggleSwitch.OnSideImage != null)
|
||||
{
|
||||
Size imageSize = ToggleSwitch.OnSideImage.Size;
|
||||
Rectangle imageRectangle;
|
||||
|
||||
int imageXPos = (int)fullRectangle.X;
|
||||
|
||||
if (ToggleSwitch.OnSideScaleImageToFit)
|
||||
{
|
||||
Size canvasSize = new Size((int)fullRectangle.Width, (int)fullRectangle.Height);
|
||||
Size resizedImageSize = ImageHelper.RescaleImageToFit(imageSize, canvasSize);
|
||||
|
||||
if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)resizedImageSize.Width) / 2));
|
||||
}
|
||||
else if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Near)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)resizedImageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)resizedImageSize.Height) / 2)), resizedImageSize.Width, resizedImageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)imageSize.Width) / 2));
|
||||
}
|
||||
else if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Near)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)imageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)imageSize.Height) / 2)), imageSize.Width, imageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImageUnscaled(ToggleSwitch.OnSideImage, imageRectangle);
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(ToggleSwitch.OnText))
|
||||
{
|
||||
SizeF textSize = g.MeasureString(ToggleSwitch.OnText, ToggleSwitch.OnFont);
|
||||
|
||||
float textXPos = fullRectangle.X;
|
||||
|
||||
if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
textXPos = (float)fullRectangle.X + (((float)fullRectangle.Width - (float)textSize.Width) / 2);
|
||||
}
|
||||
else if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Near)
|
||||
{
|
||||
textXPos = (float)fullRectangle.X + (float)fullRectangle.Width - (float)textSize.Width;
|
||||
}
|
||||
|
||||
RectangleF textRectangle = new RectangleF(textXPos, (float)fullRectangle.Y + (((float)fullRectangle.Height - (float)textSize.Height) / 2), textSize.Width, textSize.Height);
|
||||
|
||||
Color textForeColor = ToggleSwitch.OnForeColor;
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
textForeColor = textForeColor.ToGrayScale();
|
||||
|
||||
using (Brush textBrush = new SolidBrush(textForeColor))
|
||||
{
|
||||
g.DrawString(ToggleSwitch.OnText, ToggleSwitch.OnFont, textBrush, textRectangle);
|
||||
}
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
}
|
||||
|
||||
public override void RenderRightToggleField(Graphics g, Rectangle rightRectangle, int totalToggleFieldWidth)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
|
||||
|
||||
int buttonWidth = GetButtonWidth();
|
||||
|
||||
//Draw inner background
|
||||
int gradientRectWidth = rightRectangle.Width + buttonWidth / 2;
|
||||
Rectangle gradientRectangle = new Rectangle(rightRectangle.X - buttonWidth / 2, rightRectangle.Y, gradientRectWidth, rightRectangle.Height);
|
||||
|
||||
Color rightSideBackColor1 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? RightSideBackColor1.ToGrayScale() : RightSideBackColor1;
|
||||
Color rightSideBackColor2 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? RightSideBackColor2.ToGrayScale() : RightSideBackColor2;
|
||||
|
||||
if (_innerControlPath != null)
|
||||
{
|
||||
g.SetClip(_innerControlPath);
|
||||
g.IntersectClip(gradientRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.SetClip(gradientRectangle);
|
||||
}
|
||||
|
||||
using (Brush backgroundBrush = new LinearGradientBrush(gradientRectangle, rightSideBackColor1, rightSideBackColor2, LinearGradientMode.Vertical))
|
||||
{
|
||||
g.FillRectangle(backgroundBrush, gradientRectangle);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
|
||||
Rectangle rightShadowRectangle = new Rectangle();
|
||||
rightShadowRectangle.X = rightRectangle.X - CornerRadius;
|
||||
rightShadowRectangle.Y = rightRectangle.Y;
|
||||
rightShadowRectangle.Width = ButtonShadowWidth + CornerRadius;
|
||||
rightShadowRectangle.Height = rightRectangle.Height;
|
||||
|
||||
if (_innerControlPath != null)
|
||||
{
|
||||
g.SetClip(_innerControlPath);
|
||||
g.IntersectClip(rightShadowRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.SetClip(rightShadowRectangle);
|
||||
}
|
||||
|
||||
using (Brush buttonShadowBrush = new LinearGradientBrush(rightShadowRectangle, ButtonShadowColor1, ButtonShadowColor2, LinearGradientMode.Horizontal))
|
||||
{
|
||||
g.FillRectangle(buttonShadowBrush, rightShadowRectangle);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
|
||||
//Draw image or text
|
||||
if (ToggleSwitch.OffSideImage != null || !string.IsNullOrEmpty(ToggleSwitch.OffText))
|
||||
{
|
||||
RectangleF fullRectangle = new RectangleF(rightRectangle.X, 1, totalToggleFieldWidth - 1, ToggleSwitch.Height - 2);
|
||||
|
||||
if (_innerControlPath != null)
|
||||
{
|
||||
g.SetClip(_innerControlPath);
|
||||
g.IntersectClip(fullRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.SetClip(fullRectangle);
|
||||
}
|
||||
|
||||
if (ToggleSwitch.OffSideImage != null)
|
||||
{
|
||||
Size imageSize = ToggleSwitch.OffSideImage.Size;
|
||||
Rectangle imageRectangle;
|
||||
|
||||
int imageXPos = (int)fullRectangle.X;
|
||||
|
||||
if (ToggleSwitch.OffSideScaleImageToFit)
|
||||
{
|
||||
Size canvasSize = new Size((int)fullRectangle.Width, (int)fullRectangle.Height);
|
||||
Size resizedImageSize = ImageHelper.RescaleImageToFit(imageSize, canvasSize);
|
||||
|
||||
if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)resizedImageSize.Width) / 2));
|
||||
}
|
||||
else if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Far)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)resizedImageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)resizedImageSize.Height) / 2)), resizedImageSize.Width, resizedImageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)imageSize.Width) / 2));
|
||||
}
|
||||
else if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Far)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)imageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)imageSize.Height) / 2)), imageSize.Width, imageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImageUnscaled(ToggleSwitch.OffSideImage, imageRectangle);
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(ToggleSwitch.OffText))
|
||||
{
|
||||
SizeF textSize = g.MeasureString(ToggleSwitch.OffText, ToggleSwitch.OffFont);
|
||||
|
||||
float textXPos = fullRectangle.X;
|
||||
|
||||
if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
textXPos = (float)fullRectangle.X + (((float)fullRectangle.Width - (float)textSize.Width) / 2);
|
||||
}
|
||||
else if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Far)
|
||||
{
|
||||
textXPos = (float)fullRectangle.X + (float)fullRectangle.Width - (float)textSize.Width;
|
||||
}
|
||||
|
||||
RectangleF textRectangle = new RectangleF(textXPos, (float)fullRectangle.Y + (((float)fullRectangle.Height - (float)textSize.Height) / 2), textSize.Width, textSize.Height);
|
||||
|
||||
Color textForeColor = ToggleSwitch.OffForeColor;
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
textForeColor = textForeColor.ToGrayScale();
|
||||
|
||||
using (Brush textBrush = new SolidBrush(textForeColor))
|
||||
{
|
||||
g.DrawString(ToggleSwitch.OffText, ToggleSwitch.OffFont, textBrush, textRectangle);
|
||||
}
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
}
|
||||
|
||||
public override void RenderButton(Graphics g, Rectangle buttonRectangle)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
|
||||
|
||||
using (GraphicsPath buttonPath = GetRoundedRectanglePath(buttonRectangle, ButtonCornerRadius))
|
||||
{
|
||||
if (_innerControlPath != null)
|
||||
{
|
||||
g.SetClip(_innerControlPath);
|
||||
g.IntersectClip(buttonRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.SetClip(buttonRectangle);
|
||||
}
|
||||
|
||||
//Draw button surface
|
||||
Color buttonSurfaceColor1 = ButtonNormalSurfaceColor1;
|
||||
Color buttonSurfaceColor2 = ButtonNormalSurfaceColor2;
|
||||
|
||||
if (ToggleSwitch.IsButtonPressed)
|
||||
{
|
||||
buttonSurfaceColor1 = ButtonPressedSurfaceColor1;
|
||||
buttonSurfaceColor2 = ButtonPressedSurfaceColor2;
|
||||
}
|
||||
else if (ToggleSwitch.IsButtonHovered)
|
||||
{
|
||||
buttonSurfaceColor1 = ButtonHoverSurfaceColor1;
|
||||
buttonSurfaceColor2 = ButtonHoverSurfaceColor2;
|
||||
}
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
{
|
||||
buttonSurfaceColor1 = buttonSurfaceColor1.ToGrayScale();
|
||||
buttonSurfaceColor2 = buttonSurfaceColor2.ToGrayScale();
|
||||
}
|
||||
|
||||
using (Brush buttonSurfaceBrush = new LinearGradientBrush(buttonRectangle, buttonSurfaceColor1, buttonSurfaceColor2, LinearGradientMode.Vertical))
|
||||
{
|
||||
g.FillPath(buttonSurfaceBrush, buttonPath);
|
||||
}
|
||||
|
||||
//Draw button border
|
||||
Color buttonBorderColor1 = ButtonNormalBorderColor1;
|
||||
Color buttonBorderColor2 = ButtonNormalBorderColor2;
|
||||
|
||||
if (ToggleSwitch.IsButtonPressed)
|
||||
{
|
||||
buttonBorderColor1 = ButtonPressedBorderColor1;
|
||||
buttonBorderColor2 = ButtonPressedBorderColor2;
|
||||
}
|
||||
else if (ToggleSwitch.IsButtonHovered)
|
||||
{
|
||||
buttonBorderColor1 = ButtonHoverBorderColor1;
|
||||
buttonBorderColor2 = ButtonHoverBorderColor2;
|
||||
}
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
{
|
||||
buttonBorderColor1 = buttonBorderColor1.ToGrayScale();
|
||||
buttonBorderColor2 = buttonBorderColor2.ToGrayScale();
|
||||
}
|
||||
|
||||
using (Brush buttonBorderBrush = new LinearGradientBrush(buttonRectangle, buttonBorderColor1, buttonBorderColor2, LinearGradientMode.Vertical))
|
||||
{
|
||||
using (Pen buttonBorderPen = new Pen(buttonBorderBrush))
|
||||
{
|
||||
g.DrawPath(buttonBorderPen, buttonPath);
|
||||
}
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
|
||||
//Draw button image
|
||||
Image buttonImage = ToggleSwitch.ButtonImage ?? (ToggleSwitch.Checked ? ToggleSwitch.OnButtonImage : ToggleSwitch.OffButtonImage);
|
||||
|
||||
if (buttonImage != null)
|
||||
{
|
||||
g.SetClip(buttonPath);
|
||||
|
||||
ToggleSwitch.ToggleSwitchButtonAlignment alignment = ToggleSwitch.ButtonImage != null ? ToggleSwitch.ButtonAlignment : (ToggleSwitch.Checked ? ToggleSwitch.OnButtonAlignment : ToggleSwitch.OffButtonAlignment);
|
||||
|
||||
Size imageSize = buttonImage.Size;
|
||||
|
||||
Rectangle imageRectangle;
|
||||
|
||||
int imageXPos = buttonRectangle.X;
|
||||
|
||||
bool scaleImage = ToggleSwitch.ButtonImage != null ? ToggleSwitch.ButtonScaleImageToFit : (ToggleSwitch.Checked ? ToggleSwitch.OnButtonScaleImageToFit : ToggleSwitch.OffButtonScaleImageToFit);
|
||||
|
||||
if (scaleImage)
|
||||
{
|
||||
Size canvasSize = buttonRectangle.Size;
|
||||
Size resizedImageSize = ImageHelper.RescaleImageToFit(imageSize, canvasSize);
|
||||
|
||||
if (alignment == ToggleSwitch.ToggleSwitchButtonAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)buttonRectangle.X + (((float)buttonRectangle.Width - (float)resizedImageSize.Width) / 2));
|
||||
}
|
||||
else if (alignment == ToggleSwitch.ToggleSwitchButtonAlignment.Right)
|
||||
{
|
||||
imageXPos = (int)((float)buttonRectangle.X + (float)buttonRectangle.Width - (float)resizedImageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)buttonRectangle.Y + (((float)buttonRectangle.Height - (float)resizedImageSize.Height) / 2)), resizedImageSize.Width, resizedImageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(buttonImage, imageRectangle, 0, 0, buttonImage.Width, buttonImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImage(buttonImage, imageRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (alignment == ToggleSwitch.ToggleSwitchButtonAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)buttonRectangle.X + (((float)buttonRectangle.Width - (float)imageSize.Width) / 2));
|
||||
}
|
||||
else if (alignment == ToggleSwitch.ToggleSwitchButtonAlignment.Right)
|
||||
{
|
||||
imageXPos = (int)((float)buttonRectangle.X + (float)buttonRectangle.Width - (float)imageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)buttonRectangle.Y + (((float)buttonRectangle.Height - (float)imageSize.Height) / 2)), imageSize.Width, imageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(buttonImage, imageRectangle, 0, 0, buttonImage.Width, buttonImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImageUnscaled(buttonImage, imageRectangle);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Render Method Implementations
|
||||
|
||||
#region Helper Method Implementations
|
||||
|
||||
public GraphicsPath GetRoundedRectanglePath(Rectangle rectangle, int radius)
|
||||
{
|
||||
GraphicsPath gp = new GraphicsPath();
|
||||
int diameter = 2*radius;
|
||||
|
||||
if (diameter > ToggleSwitch.Height)
|
||||
diameter = ToggleSwitch.Height;
|
||||
|
||||
if (diameter > ToggleSwitch.Width)
|
||||
diameter = ToggleSwitch.Width;
|
||||
|
||||
gp.AddArc(rectangle.X, rectangle.Y, diameter, diameter, 180, 90);
|
||||
gp.AddArc(rectangle.X + rectangle.Width - diameter, rectangle.Y, diameter, diameter, 270, 90);
|
||||
gp.AddArc(rectangle.X + rectangle.Width - diameter, rectangle.Y + rectangle.Height - diameter, diameter, diameter, 0, 90);
|
||||
gp.AddArc(rectangle.X, rectangle.Y + rectangle.Height - diameter, diameter, diameter, 90, 90);
|
||||
gp.CloseFigure();
|
||||
|
||||
return gp;
|
||||
}
|
||||
|
||||
public override int GetButtonWidth()
|
||||
{
|
||||
float buttonWidth = 1.57f*ToggleSwitch.Height;
|
||||
return (int) buttonWidth;
|
||||
}
|
||||
|
||||
public override Rectangle GetButtonRectangle()
|
||||
{
|
||||
int buttonWidth = GetButtonWidth();
|
||||
return GetButtonRectangle(buttonWidth);
|
||||
}
|
||||
|
||||
public override Rectangle GetButtonRectangle(int buttonWidth)
|
||||
{
|
||||
Rectangle buttonRect = new Rectangle(ToggleSwitch.ButtonValue, 0, buttonWidth, ToggleSwitch.Height);
|
||||
return buttonRect;
|
||||
}
|
||||
|
||||
#endregion Helper Method Implementations
|
||||
}
|
||||
}
|
324
ToggleSwitch/Renderers/ToggleSwitchMetroRenderer.cs
Normal file
|
@ -0,0 +1,324 @@
|
|||
using System.Drawing;
|
||||
using ToggleSwitch;
|
||||
|
||||
namespace JCS
|
||||
{
|
||||
public class ToggleSwitchMetroRenderer : ToggleSwitchRendererBase
|
||||
{
|
||||
#region Constructor
|
||||
|
||||
public ToggleSwitchMetroRenderer()
|
||||
{
|
||||
BackColor = Color.White;
|
||||
LeftSideColor = Color.FromArgb(255, 23, 153, 0);
|
||||
LeftSideColorHovered = Color.FromArgb(255, 36, 182, 9);
|
||||
LeftSideColorPressed = Color.FromArgb(255, 121, 245, 100);
|
||||
RightSideColor = Color.FromArgb(255, 166, 166, 166);
|
||||
RightSideColorHovered = Color.FromArgb(255, 181, 181, 181);
|
||||
RightSideColorPressed = Color.FromArgb(255, 189, 189, 189);
|
||||
BorderColor = Color.FromArgb(255, 166, 166, 166);
|
||||
ButtonColor = Color.Black;
|
||||
ButtonColorHovered = Color.Black;
|
||||
ButtonColorPressed = Color.Black;
|
||||
}
|
||||
|
||||
#endregion Constructor
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public Color BackColor { get; set; }
|
||||
public Color LeftSideColor { get; set; }
|
||||
public Color LeftSideColorHovered { get; set; }
|
||||
public Color LeftSideColorPressed { get; set; }
|
||||
public Color RightSideColor { get; set; }
|
||||
public Color RightSideColorHovered { get; set; }
|
||||
public Color RightSideColorPressed { get; set; }
|
||||
public Color BorderColor { get; set; }
|
||||
public Color ButtonColor { get; set; }
|
||||
public Color ButtonColorHovered { get; set; }
|
||||
public Color ButtonColorPressed { get; set; }
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Render Method Implementations
|
||||
|
||||
public override void RenderBorder(Graphics g, Rectangle borderRectangle)
|
||||
{
|
||||
Color borderColor = !ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled ? BorderColor.ToGrayScale() : BorderColor;
|
||||
|
||||
g.SetClip(borderRectangle);
|
||||
|
||||
using (Pen borderPen = new Pen(borderColor))
|
||||
{
|
||||
g.DrawRectangle(borderPen, borderRectangle.X, borderRectangle.Y, borderRectangle.Width - 1, borderRectangle.Height - 1);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
|
||||
public override void RenderLeftToggleField(Graphics g, Rectangle leftRectangle, int totalToggleFieldWidth)
|
||||
{
|
||||
Rectangle adjustedLeftRect = new Rectangle(leftRectangle.X + 2, 2, leftRectangle.Width - 2, leftRectangle.Height - 4);
|
||||
|
||||
if (adjustedLeftRect.Width > 0)
|
||||
{
|
||||
Color leftColor = LeftSideColor;
|
||||
|
||||
if (ToggleSwitch.IsLeftSidePressed)
|
||||
leftColor = LeftSideColorPressed;
|
||||
else if (ToggleSwitch.IsLeftSideHovered)
|
||||
leftColor = LeftSideColorHovered;
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
leftColor = leftColor.ToGrayScale();
|
||||
|
||||
g.SetClip(adjustedLeftRect);
|
||||
|
||||
using (Brush leftBrush = new SolidBrush(leftColor))
|
||||
{
|
||||
g.FillRectangle(leftBrush, adjustedLeftRect);
|
||||
}
|
||||
|
||||
if (ToggleSwitch.OnSideImage != null || !string.IsNullOrEmpty(ToggleSwitch.OnText))
|
||||
{
|
||||
RectangleF fullRectangle = new RectangleF(leftRectangle.X + 2 - (totalToggleFieldWidth - leftRectangle.Width), 2, totalToggleFieldWidth - 2, ToggleSwitch.Height - 4);
|
||||
|
||||
g.IntersectClip(fullRectangle);
|
||||
|
||||
if (ToggleSwitch.OnSideImage != null)
|
||||
{
|
||||
Size imageSize = ToggleSwitch.OnSideImage.Size;
|
||||
Rectangle imageRectangle;
|
||||
|
||||
int imageXPos = (int)fullRectangle.X;
|
||||
|
||||
if (ToggleSwitch.OnSideScaleImageToFit)
|
||||
{
|
||||
Size canvasSize = new Size((int)fullRectangle.Width, (int)fullRectangle.Height);
|
||||
Size resizedImageSize = ImageHelper.RescaleImageToFit(imageSize, canvasSize);
|
||||
|
||||
if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)resizedImageSize.Width) / 2));
|
||||
}
|
||||
else if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Near)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)resizedImageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)resizedImageSize.Height) / 2)), resizedImageSize.Width, resizedImageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)imageSize.Width) / 2));
|
||||
}
|
||||
else if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Near)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)imageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)imageSize.Height) / 2)), imageSize.Width, imageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImageUnscaled(ToggleSwitch.OnSideImage, imageRectangle);
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(ToggleSwitch.OnText))
|
||||
{
|
||||
SizeF textSize = g.MeasureString(ToggleSwitch.OnText, ToggleSwitch.OnFont);
|
||||
|
||||
float textXPos = fullRectangle.X;
|
||||
|
||||
if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
textXPos = (float) fullRectangle.X + (((float) fullRectangle.Width - (float) textSize.Width)/2);
|
||||
}
|
||||
else if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Near)
|
||||
{
|
||||
textXPos = (float) fullRectangle.X + (float)fullRectangle.Width - (float) textSize.Width;
|
||||
}
|
||||
|
||||
RectangleF textRectangle = new RectangleF(textXPos, (float)fullRectangle.Y + (((float)fullRectangle.Height - (float)textSize.Height) / 2), textSize.Width, textSize.Height);
|
||||
|
||||
Color textForeColor = ToggleSwitch.OnForeColor;
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
textForeColor = textForeColor.ToGrayScale();
|
||||
|
||||
using (Brush textBrush = new SolidBrush(textForeColor))
|
||||
{
|
||||
g.DrawString(ToggleSwitch.OnText, ToggleSwitch.OnFont, textBrush, textRectangle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
}
|
||||
|
||||
public override void RenderRightToggleField(Graphics g, Rectangle rightRectangle, int totalToggleFieldWidth)
|
||||
{
|
||||
Rectangle adjustedRightRect = new Rectangle(rightRectangle.X, 2, rightRectangle.Width - 2, rightRectangle.Height - 4);
|
||||
|
||||
if (adjustedRightRect.Width > 0)
|
||||
{
|
||||
Color rightColor = RightSideColor;
|
||||
|
||||
if (ToggleSwitch.IsRightSidePressed)
|
||||
rightColor = RightSideColorPressed;
|
||||
else if (ToggleSwitch.IsRightSideHovered)
|
||||
rightColor = RightSideColorHovered;
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
rightColor = rightColor.ToGrayScale();
|
||||
|
||||
g.SetClip(adjustedRightRect);
|
||||
|
||||
using (Brush rightBrush = new SolidBrush(rightColor))
|
||||
{
|
||||
g.FillRectangle(rightBrush, adjustedRightRect);
|
||||
}
|
||||
|
||||
if (ToggleSwitch.OffSideImage != null || !string.IsNullOrEmpty(ToggleSwitch.OffText))
|
||||
{
|
||||
RectangleF fullRectangle = new RectangleF(rightRectangle.X, 2, totalToggleFieldWidth - 2, ToggleSwitch.Height - 4);
|
||||
|
||||
g.IntersectClip(fullRectangle);
|
||||
|
||||
if (ToggleSwitch.OffSideImage != null)
|
||||
{
|
||||
Size imageSize = ToggleSwitch.OffSideImage.Size;
|
||||
Rectangle imageRectangle;
|
||||
|
||||
int imageXPos = (int)fullRectangle.X;
|
||||
|
||||
if (ToggleSwitch.OffSideScaleImageToFit)
|
||||
{
|
||||
Size canvasSize = new Size((int)fullRectangle.Width, (int)fullRectangle.Height);
|
||||
Size resizedImageSize = ImageHelper.RescaleImageToFit(imageSize, canvasSize);
|
||||
|
||||
if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)resizedImageSize.Width) / 2));
|
||||
}
|
||||
else if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Far)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)resizedImageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)resizedImageSize.Height) / 2)), resizedImageSize.Width, resizedImageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)imageSize.Width) / 2));
|
||||
}
|
||||
else if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Far)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)imageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)imageSize.Height) / 2)), imageSize.Width, imageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImageUnscaled(ToggleSwitch.OffSideImage, imageRectangle);
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(ToggleSwitch.OffText))
|
||||
{
|
||||
SizeF textSize = g.MeasureString(ToggleSwitch.OffText, ToggleSwitch.OffFont);
|
||||
|
||||
float textXPos = fullRectangle.X;
|
||||
|
||||
if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
textXPos = (float)fullRectangle.X + (((float)fullRectangle.Width - (float)textSize.Width) / 2);
|
||||
}
|
||||
else if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Far)
|
||||
{
|
||||
textXPos = (float)fullRectangle.X + (float)fullRectangle.Width - (float)textSize.Width;
|
||||
}
|
||||
|
||||
RectangleF textRectangle = new RectangleF(textXPos, (float)fullRectangle.Y + (((float)fullRectangle.Height - (float)textSize.Height) / 2), textSize.Width, textSize.Height);
|
||||
|
||||
Color textForeColor = ToggleSwitch.OffForeColor;
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
textForeColor = textForeColor.ToGrayScale();
|
||||
|
||||
using (Brush textBrush = new SolidBrush(textForeColor))
|
||||
{
|
||||
g.DrawString(ToggleSwitch.OffText, ToggleSwitch.OffFont, textBrush, textRectangle);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void RenderButton(Graphics g, Rectangle buttonRectangle)
|
||||
{
|
||||
Color buttonColor = ButtonColor;
|
||||
|
||||
if (ToggleSwitch.IsButtonPressed)
|
||||
{
|
||||
buttonColor = ButtonColorPressed;
|
||||
}
|
||||
else if (ToggleSwitch.IsButtonHovered)
|
||||
{
|
||||
buttonColor = ButtonColorHovered;
|
||||
}
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
buttonColor = buttonColor.ToGrayScale();
|
||||
|
||||
g.SetClip(buttonRectangle);
|
||||
|
||||
using (Brush backBrush = new SolidBrush(buttonColor))
|
||||
{
|
||||
g.FillRectangle(backBrush, buttonRectangle);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
|
||||
#endregion Render Method Implementations
|
||||
|
||||
#region Helper Method Implementations
|
||||
|
||||
public override int GetButtonWidth()
|
||||
{
|
||||
return (int)((double)ToggleSwitch.Height / 3 * 2);
|
||||
}
|
||||
|
||||
public override Rectangle GetButtonRectangle()
|
||||
{
|
||||
int buttonWidth = GetButtonWidth();
|
||||
return GetButtonRectangle(buttonWidth);
|
||||
}
|
||||
|
||||
public override Rectangle GetButtonRectangle(int buttonWidth)
|
||||
{
|
||||
Rectangle buttonRect = new Rectangle(ToggleSwitch.ButtonValue, 0, buttonWidth, ToggleSwitch.Height);
|
||||
return buttonRect;
|
||||
}
|
||||
|
||||
#endregion Helper Method Implementations
|
||||
}
|
||||
}
|
611
ToggleSwitch/Renderers/ToggleSwitchModernRenderer.cs
Normal file
|
@ -0,0 +1,611 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using ToggleSwitch;
|
||||
|
||||
namespace JCS
|
||||
{
|
||||
public class ToggleSwitchModernRenderer : ToggleSwitchRendererBase, IDisposable
|
||||
{
|
||||
#region Constructor
|
||||
|
||||
private GraphicsPath _innerControlPath = null;
|
||||
|
||||
public ToggleSwitchModernRenderer()
|
||||
{
|
||||
OuterBorderColor = Color.FromArgb(255, 31, 31, 31);
|
||||
InnerBorderColor1 = Color.FromArgb(255, 80, 80, 82);
|
||||
InnerBorderColor2 = Color.FromArgb(255, 109, 110, 112);
|
||||
LeftSideBackColor1 = Color.FromArgb(255, 57, 166, 222);
|
||||
LeftSideBackColor2 = Color.FromArgb(255, 53, 155, 229);
|
||||
RightSideBackColor1 = Color.FromArgb(255, 48, 49, 45);
|
||||
RightSideBackColor2 = Color.FromArgb(255, 51, 52, 48);
|
||||
ButtonNormalBorderColor1 = Color.FromArgb(255, 31, 31, 31);
|
||||
ButtonNormalBorderColor2 = Color.FromArgb(255, 31, 31, 31);
|
||||
ButtonNormalSurfaceColor1 = Color.FromArgb(255, 51, 52, 48);
|
||||
ButtonNormalSurfaceColor2 = Color.FromArgb(255, 51, 52, 48);
|
||||
ArrowNormalColor = Color.FromArgb(255, 53, 156, 230);
|
||||
ButtonHoverBorderColor1 = Color.FromArgb(255, 29, 29, 29);
|
||||
ButtonHoverBorderColor2 = Color.FromArgb(255, 29, 29, 29);
|
||||
ButtonHoverSurfaceColor1 = Color.FromArgb(255, 48, 49, 45);
|
||||
ButtonHoverSurfaceColor2 = Color.FromArgb(255, 48, 49, 45);
|
||||
ArrowHoverColor = Color.FromArgb(255, 50, 148, 219);
|
||||
ButtonPressedBorderColor1 = Color.FromArgb(255, 23, 23, 23);
|
||||
ButtonPressedBorderColor2 = Color.FromArgb(255, 23, 23, 23);
|
||||
ButtonPressedSurfaceColor1 = Color.FromArgb(255, 38, 39, 36);
|
||||
ButtonPressedSurfaceColor2 = Color.FromArgb(255, 38, 39, 36);
|
||||
ArrowPressedColor = Color.FromArgb(255, 39, 117, 172);
|
||||
ButtonShadowColor1 = Color.FromArgb(50, 0, 0, 0);
|
||||
ButtonShadowColor2 = Color.FromArgb(0, 0, 0, 0);
|
||||
|
||||
ButtonShadowWidth = 7;
|
||||
CornerRadius = 6;
|
||||
ButtonCornerRadius = 6;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_innerControlPath != null)
|
||||
_innerControlPath.Dispose();
|
||||
}
|
||||
|
||||
#endregion Constructor
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public Color OuterBorderColor { get; set; }
|
||||
public Color InnerBorderColor1 { get; set; }
|
||||
public Color InnerBorderColor2 { get; set; }
|
||||
public Color LeftSideBackColor1 { get; set; }
|
||||
public Color LeftSideBackColor2 { get; set; }
|
||||
public Color RightSideBackColor1 { get; set; }
|
||||
public Color RightSideBackColor2 { get; set; }
|
||||
public Color ButtonNormalBorderColor1 { get; set; }
|
||||
public Color ButtonNormalBorderColor2 { get; set; }
|
||||
public Color ButtonNormalSurfaceColor1 { get; set; }
|
||||
public Color ButtonNormalSurfaceColor2 { get; set; }
|
||||
public Color ArrowNormalColor { get; set; }
|
||||
public Color ButtonHoverBorderColor1 { get; set; }
|
||||
public Color ButtonHoverBorderColor2 { get; set; }
|
||||
public Color ButtonHoverSurfaceColor1 { get; set; }
|
||||
public Color ButtonHoverSurfaceColor2 { get; set; }
|
||||
public Color ArrowHoverColor { get; set; }
|
||||
public Color ButtonPressedBorderColor1 { get; set; }
|
||||
public Color ButtonPressedBorderColor2 { get; set; }
|
||||
public Color ButtonPressedSurfaceColor1 { get; set; }
|
||||
public Color ButtonPressedSurfaceColor2 { get; set; }
|
||||
public Color ArrowPressedColor { get; set; }
|
||||
public Color ButtonShadowColor1 { get; set; }
|
||||
public Color ButtonShadowColor2 { get; set; }
|
||||
|
||||
public int ButtonShadowWidth { get; set; }
|
||||
public int CornerRadius { get; set; }
|
||||
public int ButtonCornerRadius { get; set; }
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Render Method Implementations
|
||||
|
||||
public override void RenderBorder(Graphics g, Rectangle borderRectangle)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
|
||||
|
||||
//Draw outer border
|
||||
using (GraphicsPath outerBorderPath = GetRoundedRectanglePath(borderRectangle, CornerRadius))
|
||||
{
|
||||
g.SetClip(outerBorderPath);
|
||||
|
||||
Color outerBorderColor = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? OuterBorderColor.ToGrayScale() : OuterBorderColor;
|
||||
|
||||
using (Brush outerBorderBrush = new SolidBrush(outerBorderColor))
|
||||
{
|
||||
g.FillPath(outerBorderBrush, outerBorderPath);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
|
||||
//Draw inner border
|
||||
Rectangle innerborderRectangle = new Rectangle(borderRectangle.X + 1, borderRectangle.Y + 1, borderRectangle.Width - 2, borderRectangle.Height - 2);
|
||||
|
||||
using (GraphicsPath innerBorderPath = GetRoundedRectanglePath(innerborderRectangle, CornerRadius))
|
||||
{
|
||||
g.SetClip(innerBorderPath);
|
||||
|
||||
Color borderColor1 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? InnerBorderColor1.ToGrayScale() : InnerBorderColor1;
|
||||
Color borderColor2 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? InnerBorderColor2.ToGrayScale() : InnerBorderColor2;
|
||||
|
||||
using (Brush borderBrush = new LinearGradientBrush(borderRectangle, borderColor1, borderColor2, LinearGradientMode.Vertical))
|
||||
{
|
||||
g.FillPath(borderBrush, innerBorderPath);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
|
||||
Rectangle backgroundRectangle = new Rectangle(borderRectangle.X + 2, borderRectangle.Y + 2, borderRectangle.Width - 4, borderRectangle.Height - 4);
|
||||
_innerControlPath = GetRoundedRectanglePath(backgroundRectangle, CornerRadius);
|
||||
}
|
||||
|
||||
public override void RenderLeftToggleField(Graphics g, Rectangle leftRectangle, int totalToggleFieldWidth)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
|
||||
|
||||
int buttonWidth = GetButtonWidth();
|
||||
|
||||
//Draw inner background
|
||||
int gradientRectWidth = leftRectangle.Width + buttonWidth / 2;
|
||||
Rectangle gradientRectangle = new Rectangle(leftRectangle.X, leftRectangle.Y, gradientRectWidth, leftRectangle.Height);
|
||||
|
||||
Color leftSideBackColor1 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? LeftSideBackColor1.ToGrayScale() : LeftSideBackColor1;
|
||||
Color leftSideBackColor2 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? LeftSideBackColor2.ToGrayScale() : LeftSideBackColor2;
|
||||
|
||||
if (_innerControlPath != null)
|
||||
{
|
||||
g.SetClip(_innerControlPath);
|
||||
g.IntersectClip(gradientRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.SetClip(gradientRectangle);
|
||||
}
|
||||
|
||||
using (Brush backgroundBrush = new LinearGradientBrush(gradientRectangle, leftSideBackColor1, leftSideBackColor2, LinearGradientMode.Vertical))
|
||||
{
|
||||
g.FillRectangle(backgroundBrush, gradientRectangle);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
|
||||
Rectangle leftShadowRectangle = new Rectangle();
|
||||
leftShadowRectangle.X = leftRectangle.X + leftRectangle.Width - ButtonShadowWidth;
|
||||
leftShadowRectangle.Y = leftRectangle.Y;
|
||||
leftShadowRectangle.Width = ButtonShadowWidth + CornerRadius;
|
||||
leftShadowRectangle.Height = leftRectangle.Height;
|
||||
|
||||
if (_innerControlPath != null)
|
||||
{
|
||||
g.SetClip(_innerControlPath);
|
||||
g.IntersectClip(leftShadowRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.SetClip(leftShadowRectangle);
|
||||
}
|
||||
|
||||
using (Brush buttonShadowBrush = new LinearGradientBrush(leftShadowRectangle, ButtonShadowColor2, ButtonShadowColor1, LinearGradientMode.Horizontal))
|
||||
{
|
||||
g.FillRectangle(buttonShadowBrush, leftShadowRectangle);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
|
||||
//Draw image or text
|
||||
if (ToggleSwitch.OnSideImage != null || !string.IsNullOrEmpty(ToggleSwitch.OnText))
|
||||
{
|
||||
RectangleF fullRectangle = new RectangleF(leftRectangle.X + 1 - (totalToggleFieldWidth - leftRectangle.Width), 1, totalToggleFieldWidth - 1, ToggleSwitch.Height - 2);
|
||||
|
||||
if (_innerControlPath != null)
|
||||
{
|
||||
g.SetClip(_innerControlPath);
|
||||
g.IntersectClip(fullRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.SetClip(fullRectangle);
|
||||
}
|
||||
|
||||
if (ToggleSwitch.OnSideImage != null)
|
||||
{
|
||||
Size imageSize = ToggleSwitch.OnSideImage.Size;
|
||||
Rectangle imageRectangle;
|
||||
|
||||
int imageXPos = (int)fullRectangle.X;
|
||||
|
||||
if (ToggleSwitch.OnSideScaleImageToFit)
|
||||
{
|
||||
Size canvasSize = new Size((int)fullRectangle.Width, (int)fullRectangle.Height);
|
||||
Size resizedImageSize = ImageHelper.RescaleImageToFit(imageSize, canvasSize);
|
||||
|
||||
if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)resizedImageSize.Width) / 2));
|
||||
}
|
||||
else if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Near)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)resizedImageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)resizedImageSize.Height) / 2)), resizedImageSize.Width, resizedImageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)imageSize.Width) / 2));
|
||||
}
|
||||
else if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Near)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)imageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)imageSize.Height) / 2)), imageSize.Width, imageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImageUnscaled(ToggleSwitch.OnSideImage, imageRectangle);
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(ToggleSwitch.OnText))
|
||||
{
|
||||
SizeF textSize = g.MeasureString(ToggleSwitch.OnText, ToggleSwitch.OnFont);
|
||||
|
||||
float textXPos = fullRectangle.X;
|
||||
|
||||
if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
textXPos = (float)fullRectangle.X + (((float)fullRectangle.Width - (float)textSize.Width) / 2);
|
||||
}
|
||||
else if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Near)
|
||||
{
|
||||
textXPos = (float)fullRectangle.X + (float)fullRectangle.Width - (float)textSize.Width;
|
||||
}
|
||||
|
||||
RectangleF textRectangle = new RectangleF(textXPos, (float)fullRectangle.Y + (((float)fullRectangle.Height - (float)textSize.Height) / 2), textSize.Width, textSize.Height);
|
||||
|
||||
Color textForeColor = ToggleSwitch.OnForeColor;
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
textForeColor = textForeColor.ToGrayScale();
|
||||
|
||||
using (Brush textBrush = new SolidBrush(textForeColor))
|
||||
{
|
||||
g.DrawString(ToggleSwitch.OnText, ToggleSwitch.OnFont, textBrush, textRectangle);
|
||||
}
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
}
|
||||
|
||||
public override void RenderRightToggleField(Graphics g, Rectangle rightRectangle, int totalToggleFieldWidth)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
|
||||
|
||||
int buttonWidth = GetButtonWidth();
|
||||
|
||||
//Draw inner background
|
||||
int gradientRectWidth = rightRectangle.Width + buttonWidth / 2;
|
||||
Rectangle gradientRectangle = new Rectangle(rightRectangle.X - buttonWidth / 2, rightRectangle.Y, gradientRectWidth, rightRectangle.Height);
|
||||
|
||||
Color rightSideBackColor1 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? RightSideBackColor1.ToGrayScale() : RightSideBackColor1;
|
||||
Color rightSideBackColor2 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? RightSideBackColor2.ToGrayScale() : RightSideBackColor2;
|
||||
|
||||
if (_innerControlPath != null)
|
||||
{
|
||||
g.SetClip(_innerControlPath);
|
||||
g.IntersectClip(gradientRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.SetClip(gradientRectangle);
|
||||
}
|
||||
|
||||
using (Brush backgroundBrush = new LinearGradientBrush(gradientRectangle, rightSideBackColor1, rightSideBackColor2, LinearGradientMode.Vertical))
|
||||
{
|
||||
g.FillRectangle(backgroundBrush, gradientRectangle);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
|
||||
Rectangle rightShadowRectangle = new Rectangle();
|
||||
rightShadowRectangle.X = rightRectangle.X - CornerRadius;
|
||||
rightShadowRectangle.Y = rightRectangle.Y;
|
||||
rightShadowRectangle.Width = ButtonShadowWidth + CornerRadius;
|
||||
rightShadowRectangle.Height = rightRectangle.Height;
|
||||
|
||||
if (_innerControlPath != null)
|
||||
{
|
||||
g.SetClip(_innerControlPath);
|
||||
g.IntersectClip(rightShadowRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.SetClip(rightShadowRectangle);
|
||||
}
|
||||
|
||||
using (Brush buttonShadowBrush = new LinearGradientBrush(rightShadowRectangle, ButtonShadowColor1, ButtonShadowColor2, LinearGradientMode.Horizontal))
|
||||
{
|
||||
g.FillRectangle(buttonShadowBrush, rightShadowRectangle);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
|
||||
//Draw image or text
|
||||
if (ToggleSwitch.OffSideImage != null || !string.IsNullOrEmpty(ToggleSwitch.OffText))
|
||||
{
|
||||
RectangleF fullRectangle = new RectangleF(rightRectangle.X, 1, totalToggleFieldWidth - 1, ToggleSwitch.Height - 2);
|
||||
|
||||
if (_innerControlPath != null)
|
||||
{
|
||||
g.SetClip(_innerControlPath);
|
||||
g.IntersectClip(fullRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.SetClip(fullRectangle);
|
||||
}
|
||||
|
||||
if (ToggleSwitch.OffSideImage != null)
|
||||
{
|
||||
Size imageSize = ToggleSwitch.OffSideImage.Size;
|
||||
Rectangle imageRectangle;
|
||||
|
||||
int imageXPos = (int)fullRectangle.X;
|
||||
|
||||
if (ToggleSwitch.OffSideScaleImageToFit)
|
||||
{
|
||||
Size canvasSize = new Size((int)fullRectangle.Width, (int)fullRectangle.Height);
|
||||
Size resizedImageSize = ImageHelper.RescaleImageToFit(imageSize, canvasSize);
|
||||
|
||||
if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)resizedImageSize.Width) / 2));
|
||||
}
|
||||
else if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Far)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)resizedImageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)resizedImageSize.Height) / 2)), resizedImageSize.Width, resizedImageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)imageSize.Width) / 2));
|
||||
}
|
||||
else if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Far)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)imageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)imageSize.Height) / 2)), imageSize.Width, imageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImageUnscaled(ToggleSwitch.OffSideImage, imageRectangle);
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(ToggleSwitch.OffText))
|
||||
{
|
||||
SizeF textSize = g.MeasureString(ToggleSwitch.OffText, ToggleSwitch.OffFont);
|
||||
|
||||
float textXPos = fullRectangle.X;
|
||||
|
||||
if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
textXPos = (float)fullRectangle.X + (((float)fullRectangle.Width - (float)textSize.Width) / 2);
|
||||
}
|
||||
else if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Far)
|
||||
{
|
||||
textXPos = (float)fullRectangle.X + (float)fullRectangle.Width - (float)textSize.Width;
|
||||
}
|
||||
|
||||
RectangleF textRectangle = new RectangleF(textXPos, (float)fullRectangle.Y + (((float)fullRectangle.Height - (float)textSize.Height) / 2), textSize.Width, textSize.Height);
|
||||
|
||||
Color textForeColor = ToggleSwitch.OffForeColor;
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
textForeColor = textForeColor.ToGrayScale();
|
||||
|
||||
using (Brush textBrush = new SolidBrush(textForeColor))
|
||||
{
|
||||
g.DrawString(ToggleSwitch.OffText, ToggleSwitch.OffFont, textBrush, textRectangle);
|
||||
}
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
}
|
||||
|
||||
public override void RenderButton(Graphics g, Rectangle buttonRectangle)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
|
||||
|
||||
if (_innerControlPath != null)
|
||||
{
|
||||
g.SetClip(_innerControlPath);
|
||||
g.IntersectClip(buttonRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.SetClip(buttonRectangle);
|
||||
}
|
||||
|
||||
using (GraphicsPath buttonPath = GetRoundedRectanglePath(buttonRectangle, ButtonCornerRadius))
|
||||
{
|
||||
//Draw button surface
|
||||
Color buttonSurfaceColor1 = ButtonNormalSurfaceColor1;
|
||||
Color buttonSurfaceColor2 = ButtonNormalSurfaceColor2;
|
||||
|
||||
if (ToggleSwitch.IsButtonPressed)
|
||||
{
|
||||
buttonSurfaceColor1 = ButtonPressedSurfaceColor1;
|
||||
buttonSurfaceColor2 = ButtonPressedSurfaceColor2;
|
||||
}
|
||||
else if (ToggleSwitch.IsButtonHovered)
|
||||
{
|
||||
buttonSurfaceColor1 = ButtonHoverSurfaceColor1;
|
||||
buttonSurfaceColor2 = ButtonHoverSurfaceColor2;
|
||||
}
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
{
|
||||
buttonSurfaceColor1 = buttonSurfaceColor1.ToGrayScale();
|
||||
buttonSurfaceColor2 = buttonSurfaceColor2.ToGrayScale();
|
||||
}
|
||||
|
||||
using (Brush buttonSurfaceBrush = new LinearGradientBrush(buttonRectangle, buttonSurfaceColor1, buttonSurfaceColor2, LinearGradientMode.Vertical))
|
||||
{
|
||||
g.FillPath(buttonSurfaceBrush, buttonPath);
|
||||
}
|
||||
|
||||
//Draw button border
|
||||
Color buttonBorderColor1 = ButtonNormalBorderColor1;
|
||||
Color buttonBorderColor2 = ButtonNormalBorderColor2;
|
||||
|
||||
if (ToggleSwitch.IsButtonPressed)
|
||||
{
|
||||
buttonBorderColor1 = ButtonPressedBorderColor1;
|
||||
buttonBorderColor2 = ButtonPressedBorderColor2;
|
||||
}
|
||||
else if (ToggleSwitch.IsButtonHovered)
|
||||
{
|
||||
buttonBorderColor1 = ButtonHoverBorderColor1;
|
||||
buttonBorderColor2 = ButtonHoverBorderColor2;
|
||||
}
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
{
|
||||
buttonBorderColor1 = buttonBorderColor1.ToGrayScale();
|
||||
buttonBorderColor2 = buttonBorderColor2.ToGrayScale();
|
||||
}
|
||||
|
||||
using (Brush buttonBorderBrush = new LinearGradientBrush(buttonRectangle, buttonBorderColor1, buttonBorderColor2, LinearGradientMode.Vertical))
|
||||
{
|
||||
using (Pen buttonBorderPen = new Pen(buttonBorderBrush))
|
||||
{
|
||||
g.DrawPath(buttonBorderPen, buttonPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
|
||||
//Draw button arrows
|
||||
Color arrowColor = ArrowNormalColor;
|
||||
|
||||
if (ToggleSwitch.IsButtonPressed)
|
||||
arrowColor = ArrowPressedColor;
|
||||
else if (ToggleSwitch.IsButtonHovered)
|
||||
arrowColor = ArrowHoverColor;
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
arrowColor = arrowColor.ToGrayScale();
|
||||
|
||||
Rectangle arrowRectangle = new Rectangle();
|
||||
arrowRectangle.Height = 9;
|
||||
arrowRectangle.Width = 22;
|
||||
arrowRectangle.X = buttonRectangle.X + (int)(((double)buttonRectangle.Width - (double)arrowRectangle.Width) / 2);
|
||||
arrowRectangle.Y = buttonRectangle.Y + (int)(((double)buttonRectangle.Height - (double)arrowRectangle.Height) / 2);
|
||||
|
||||
using (Brush arrowBrush = new SolidBrush(arrowColor))
|
||||
{
|
||||
using (GraphicsPath arrowLeftPath = GetArrowLeftPath(arrowRectangle))
|
||||
{
|
||||
g.FillPath(arrowBrush, arrowLeftPath);
|
||||
}
|
||||
|
||||
using (GraphicsPath arrowRightPath = GetArrowRightPath(arrowRectangle))
|
||||
{
|
||||
g.FillPath(arrowBrush, arrowRightPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Render Method Implementations
|
||||
|
||||
#region Helper Method Implementations
|
||||
|
||||
public GraphicsPath GetRoundedRectanglePath(Rectangle rectangle, int radius)
|
||||
{
|
||||
GraphicsPath gp = new GraphicsPath();
|
||||
int diameter = 2*radius;
|
||||
|
||||
if (diameter > ToggleSwitch.Height)
|
||||
diameter = ToggleSwitch.Height;
|
||||
|
||||
if (diameter > ToggleSwitch.Width)
|
||||
diameter = ToggleSwitch.Width;
|
||||
|
||||
gp.AddArc(rectangle.X, rectangle.Y, diameter, diameter, 180, 90);
|
||||
gp.AddArc(rectangle.X + rectangle.Width - diameter, rectangle.Y, diameter, diameter, 270, 90);
|
||||
gp.AddArc(rectangle.X + rectangle.Width - diameter, rectangle.Y + rectangle.Height - diameter, diameter, diameter, 0, 90);
|
||||
gp.AddArc(rectangle.X, rectangle.Y + rectangle.Height - diameter, diameter, diameter, 90, 90);
|
||||
gp.CloseFigure();
|
||||
|
||||
return gp;
|
||||
}
|
||||
|
||||
public GraphicsPath GetArrowLeftPath(Rectangle arrowRectangle)
|
||||
{
|
||||
GraphicsPath gp = new GraphicsPath();
|
||||
|
||||
Point top = new Point(arrowRectangle.X + 8, arrowRectangle.Y);
|
||||
Point bottom = new Point(arrowRectangle.X + 8, arrowRectangle.Y + arrowRectangle.Height);
|
||||
Point tip = new Point(arrowRectangle.X, arrowRectangle.Y + (arrowRectangle.Height/2));
|
||||
|
||||
gp.AddLine(top, bottom);
|
||||
gp.AddLine(bottom, tip);
|
||||
gp.AddLine(tip, top);
|
||||
|
||||
return gp;
|
||||
}
|
||||
|
||||
public GraphicsPath GetArrowRightPath(Rectangle arrowRectangle)
|
||||
{
|
||||
GraphicsPath gp = new GraphicsPath();
|
||||
|
||||
Point top = new Point(arrowRectangle.X + 14, arrowRectangle.Y);
|
||||
Point bottom = new Point(arrowRectangle.X + 14, arrowRectangle.Y + arrowRectangle.Height);
|
||||
Point tip = new Point(arrowRectangle.X + arrowRectangle.Width, arrowRectangle.Y + (arrowRectangle.Height / 2));
|
||||
|
||||
gp.AddLine(top, bottom);
|
||||
gp.AddLine(bottom, tip);
|
||||
gp.AddLine(tip, top);
|
||||
|
||||
return gp;
|
||||
}
|
||||
|
||||
public override int GetButtonWidth()
|
||||
{
|
||||
float buttonWidth = 1.41f*ToggleSwitch.Height;
|
||||
return (int) buttonWidth;
|
||||
}
|
||||
|
||||
public override Rectangle GetButtonRectangle()
|
||||
{
|
||||
int buttonWidth = GetButtonWidth();
|
||||
return GetButtonRectangle(buttonWidth);
|
||||
}
|
||||
|
||||
public override Rectangle GetButtonRectangle(int buttonWidth)
|
||||
{
|
||||
Rectangle buttonRect = new Rectangle(ToggleSwitch.ButtonValue, 0, buttonWidth, ToggleSwitch.Height);
|
||||
return buttonRect;
|
||||
}
|
||||
|
||||
#endregion Helper Method Implementations
|
||||
}
|
||||
}
|
556
ToggleSwitch/Renderers/ToggleSwitchOSXRenderer.cs
Normal file
|
@ -0,0 +1,556 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using ToggleSwitch;
|
||||
|
||||
namespace JCS
|
||||
{
|
||||
public class ToggleSwitchOSXRenderer : ToggleSwitchRendererBase, IDisposable
|
||||
{
|
||||
#region Constructor
|
||||
|
||||
private GraphicsPath _innerControlPath = null;
|
||||
|
||||
public ToggleSwitchOSXRenderer()
|
||||
{
|
||||
OuterBorderColor = Color.FromArgb(255, 108, 108, 108);
|
||||
InnerBorderColor1 = Color.FromArgb(255, 137, 138, 139);
|
||||
InnerBorderColor2 = Color.FromArgb(255, 167, 168, 169);
|
||||
BackColor1 = Color.FromArgb(255, 108, 108, 108);
|
||||
BackColor2 = Color.FromArgb(255, 163, 163, 163);
|
||||
ButtonNormalBorderColor1 = Color.FromArgb(255, 147, 147, 148);
|
||||
ButtonNormalBorderColor2 = Color.FromArgb(255, 167, 168, 169);
|
||||
ButtonNormalSurfaceColor1 = Color.FromArgb(255, 250, 250, 250);
|
||||
ButtonNormalSurfaceColor2 = Color.FromArgb(255, 224, 224, 224);
|
||||
ButtonHoverBorderColor1 = Color.FromArgb(255, 145, 146, 147);
|
||||
ButtonHoverBorderColor2 = Color.FromArgb(255, 164, 165, 166);
|
||||
ButtonHoverSurfaceColor1 = Color.FromArgb(255, 238, 238, 238);
|
||||
ButtonHoverSurfaceColor2 = Color.FromArgb(255, 213, 213, 213);
|
||||
ButtonPressedBorderColor1 = Color.FromArgb(255, 138, 138, 140);
|
||||
ButtonPressedBorderColor2 = Color.FromArgb(255, 158, 158, 160);
|
||||
ButtonPressedSurfaceColor1 = Color.FromArgb(255, 187, 187, 187);
|
||||
ButtonPressedSurfaceColor2 = Color.FromArgb(255, 168, 168, 168);
|
||||
ButtonShadowColor1 = Color.FromArgb(50, 0, 0, 0);
|
||||
ButtonShadowColor2 = Color.FromArgb(0, 0, 0, 0);
|
||||
|
||||
ButtonShadowWidth = 7;
|
||||
CornerRadius = 4;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_innerControlPath != null)
|
||||
_innerControlPath.Dispose();
|
||||
}
|
||||
|
||||
#endregion Constructor
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public Color OuterBorderColor { get; set; }
|
||||
public Color InnerBorderColor1 { get; set; }
|
||||
public Color InnerBorderColor2 { get; set; }
|
||||
public Color BackColor1 { get; set; }
|
||||
public Color BackColor2 { get; set; }
|
||||
public Color ButtonNormalBorderColor1 { get; set; }
|
||||
public Color ButtonNormalBorderColor2 { get; set; }
|
||||
public Color ButtonNormalSurfaceColor1 { get; set; }
|
||||
public Color ButtonNormalSurfaceColor2 { get; set; }
|
||||
public Color ButtonHoverBorderColor1 { get; set; }
|
||||
public Color ButtonHoverBorderColor2 { get; set; }
|
||||
public Color ButtonHoverSurfaceColor1 { get; set; }
|
||||
public Color ButtonHoverSurfaceColor2 { get; set; }
|
||||
public Color ButtonPressedBorderColor1 { get; set; }
|
||||
public Color ButtonPressedBorderColor2 { get; set; }
|
||||
public Color ButtonPressedSurfaceColor1 { get; set; }
|
||||
public Color ButtonPressedSurfaceColor2 { get; set; }
|
||||
public Color ButtonShadowColor1 { get; set; }
|
||||
public Color ButtonShadowColor2 { get; set; }
|
||||
|
||||
public int ButtonShadowWidth { get; set; }
|
||||
public int CornerRadius { get; set; }
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Render Method Implementations
|
||||
|
||||
public override void RenderBorder(Graphics g, Rectangle borderRectangle)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
|
||||
|
||||
//Draw outer border
|
||||
using (GraphicsPath outerBorderPath = GetRoundedRectanglePath(borderRectangle, CornerRadius))
|
||||
{
|
||||
g.SetClip(outerBorderPath);
|
||||
|
||||
Color outerBorderColor = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? OuterBorderColor.ToGrayScale() : OuterBorderColor;
|
||||
|
||||
using (Brush outerBorderBrush = new SolidBrush(outerBorderColor))
|
||||
{
|
||||
g.FillPath(outerBorderBrush, outerBorderPath);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
|
||||
//Draw inner border
|
||||
Rectangle innerborderRectangle = new Rectangle(borderRectangle.X + 1, borderRectangle.Y +1 , borderRectangle.Width - 2, borderRectangle.Height - 2);
|
||||
|
||||
using (GraphicsPath innerBorderPath = GetRoundedRectanglePath(innerborderRectangle, CornerRadius))
|
||||
{
|
||||
g.SetClip(innerBorderPath);
|
||||
|
||||
Color borderColor1 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? InnerBorderColor1.ToGrayScale() : InnerBorderColor1;
|
||||
Color borderColor2 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? InnerBorderColor2.ToGrayScale() : InnerBorderColor2;
|
||||
|
||||
using (Brush borderBrush = new LinearGradientBrush(borderRectangle, borderColor1, borderColor2, LinearGradientMode.Vertical))
|
||||
{
|
||||
g.FillPath(borderBrush, innerBorderPath);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
|
||||
//Draw inner background
|
||||
Rectangle backgroundRectangle = new Rectangle(borderRectangle.X + 2, borderRectangle.Y + 2, borderRectangle.Width - 4, borderRectangle.Height - 4);
|
||||
|
||||
_innerControlPath = GetRoundedRectanglePath(backgroundRectangle, CornerRadius);
|
||||
|
||||
g.SetClip(_innerControlPath);
|
||||
|
||||
Color backColor1 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? BackColor1.ToGrayScale() : BackColor1;
|
||||
Color backColor2 = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? BackColor2.ToGrayScale() : BackColor2;
|
||||
|
||||
using (Brush backgroundBrush = new LinearGradientBrush(borderRectangle, backColor1, backColor2, LinearGradientMode.Vertical))
|
||||
{
|
||||
g.FillPath(backgroundBrush, _innerControlPath);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
|
||||
public override void RenderLeftToggleField(Graphics g, Rectangle leftRectangle, int totalToggleFieldWidth)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
|
||||
|
||||
Rectangle leftShadowRectangle = new Rectangle();
|
||||
leftShadowRectangle.X = leftRectangle.X + leftRectangle.Width - ButtonShadowWidth;
|
||||
leftShadowRectangle.Y = leftRectangle.Y;
|
||||
leftShadowRectangle.Width = ButtonShadowWidth + CornerRadius;
|
||||
leftShadowRectangle.Height = leftRectangle.Height;
|
||||
|
||||
if (_innerControlPath != null)
|
||||
{
|
||||
g.SetClip(_innerControlPath);
|
||||
g.IntersectClip(leftShadowRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.SetClip(leftShadowRectangle);
|
||||
}
|
||||
|
||||
using (Brush buttonShadowBrush = new LinearGradientBrush(leftShadowRectangle, ButtonShadowColor2, ButtonShadowColor1, LinearGradientMode.Horizontal))
|
||||
{
|
||||
g.FillRectangle(buttonShadowBrush, leftShadowRectangle);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
|
||||
//Draw image or text
|
||||
if (ToggleSwitch.OnSideImage != null || !string.IsNullOrEmpty(ToggleSwitch.OnText))
|
||||
{
|
||||
RectangleF fullRectangle = new RectangleF(leftRectangle.X + 1 - (totalToggleFieldWidth - leftRectangle.Width), 1, totalToggleFieldWidth - 1, ToggleSwitch.Height - 2);
|
||||
|
||||
if (_innerControlPath != null)
|
||||
{
|
||||
g.SetClip(_innerControlPath);
|
||||
g.IntersectClip(fullRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.SetClip(fullRectangle);
|
||||
}
|
||||
|
||||
if (ToggleSwitch.OnSideImage != null)
|
||||
{
|
||||
Size imageSize = ToggleSwitch.OnSideImage.Size;
|
||||
Rectangle imageRectangle;
|
||||
|
||||
int imageXPos = (int)fullRectangle.X;
|
||||
|
||||
if (ToggleSwitch.OnSideScaleImageToFit)
|
||||
{
|
||||
Size canvasSize = new Size((int)fullRectangle.Width, (int)fullRectangle.Height);
|
||||
Size resizedImageSize = ImageHelper.RescaleImageToFit(imageSize, canvasSize);
|
||||
|
||||
if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)resizedImageSize.Width) / 2));
|
||||
}
|
||||
else if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Near)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)resizedImageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)resizedImageSize.Height) / 2)), resizedImageSize.Width, resizedImageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)imageSize.Width) / 2));
|
||||
}
|
||||
else if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Near)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)imageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)imageSize.Height) / 2)), imageSize.Width, imageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImageUnscaled(ToggleSwitch.OnSideImage, imageRectangle);
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(ToggleSwitch.OnText))
|
||||
{
|
||||
SizeF textSize = g.MeasureString(ToggleSwitch.OnText, ToggleSwitch.OnFont);
|
||||
|
||||
float textXPos = fullRectangle.X;
|
||||
|
||||
if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
textXPos = (float)fullRectangle.X + (((float)fullRectangle.Width - (float)textSize.Width) / 2);
|
||||
}
|
||||
else if (ToggleSwitch.OnSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Near)
|
||||
{
|
||||
textXPos = (float)fullRectangle.X + (float)fullRectangle.Width - (float)textSize.Width;
|
||||
}
|
||||
|
||||
RectangleF textRectangle = new RectangleF(textXPos, (float)fullRectangle.Y + (((float)fullRectangle.Height - (float)textSize.Height) / 2), textSize.Width, textSize.Height);
|
||||
|
||||
Color textForeColor = ToggleSwitch.OnForeColor;
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
textForeColor = textForeColor.ToGrayScale();
|
||||
|
||||
using (Brush textBrush = new SolidBrush(textForeColor))
|
||||
{
|
||||
g.DrawString(ToggleSwitch.OnText, ToggleSwitch.OnFont, textBrush, textRectangle);
|
||||
}
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
}
|
||||
|
||||
public override void RenderRightToggleField(Graphics g, Rectangle rightRectangle, int totalToggleFieldWidth)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
|
||||
|
||||
Rectangle rightShadowRectangle = new Rectangle();
|
||||
rightShadowRectangle.X = rightRectangle.X - CornerRadius;
|
||||
rightShadowRectangle.Y = rightRectangle.Y;
|
||||
rightShadowRectangle.Width = ButtonShadowWidth + CornerRadius;
|
||||
rightShadowRectangle.Height = rightRectangle.Height;
|
||||
|
||||
if (_innerControlPath != null)
|
||||
{
|
||||
g.SetClip(_innerControlPath);
|
||||
g.IntersectClip(rightShadowRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.SetClip(rightShadowRectangle);
|
||||
}
|
||||
|
||||
using (Brush buttonShadowBrush = new LinearGradientBrush(rightShadowRectangle, ButtonShadowColor1, ButtonShadowColor2, LinearGradientMode.Horizontal))
|
||||
{
|
||||
g.FillRectangle(buttonShadowBrush, rightShadowRectangle);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
|
||||
//Draw image or text
|
||||
if (ToggleSwitch.OffSideImage != null || !string.IsNullOrEmpty(ToggleSwitch.OffText))
|
||||
{
|
||||
RectangleF fullRectangle = new RectangleF(rightRectangle.X, 1, totalToggleFieldWidth - 1, ToggleSwitch.Height - 2);
|
||||
|
||||
if (_innerControlPath != null)
|
||||
{
|
||||
g.SetClip(_innerControlPath);
|
||||
g.IntersectClip(fullRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.SetClip(fullRectangle);
|
||||
}
|
||||
|
||||
if (ToggleSwitch.OffSideImage != null)
|
||||
{
|
||||
Size imageSize = ToggleSwitch.OffSideImage.Size;
|
||||
Rectangle imageRectangle;
|
||||
|
||||
int imageXPos = (int)fullRectangle.X;
|
||||
|
||||
if (ToggleSwitch.OffSideScaleImageToFit)
|
||||
{
|
||||
Size canvasSize = new Size((int)fullRectangle.Width, (int)fullRectangle.Height);
|
||||
Size resizedImageSize = ImageHelper.RescaleImageToFit(imageSize, canvasSize);
|
||||
|
||||
if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)resizedImageSize.Width) / 2));
|
||||
}
|
||||
else if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Far)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)resizedImageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)resizedImageSize.Height) / 2)), resizedImageSize.Width, resizedImageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (((float)fullRectangle.Width - (float)imageSize.Width) / 2));
|
||||
}
|
||||
else if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Far)
|
||||
{
|
||||
imageXPos = (int)((float)fullRectangle.X + (float)fullRectangle.Width - (float)imageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)fullRectangle.Y + (((float)fullRectangle.Height - (float)imageSize.Height) / 2)), imageSize.Width, imageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(ToggleSwitch.OnSideImage, imageRectangle, 0, 0, ToggleSwitch.OnSideImage.Width, ToggleSwitch.OnSideImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImageUnscaled(ToggleSwitch.OffSideImage, imageRectangle);
|
||||
}
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(ToggleSwitch.OffText))
|
||||
{
|
||||
SizeF textSize = g.MeasureString(ToggleSwitch.OffText, ToggleSwitch.OffFont);
|
||||
|
||||
float textXPos = fullRectangle.X;
|
||||
|
||||
if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Center)
|
||||
{
|
||||
textXPos = (float)fullRectangle.X + (((float)fullRectangle.Width - (float)textSize.Width) / 2);
|
||||
}
|
||||
else if (ToggleSwitch.OffSideAlignment == ToggleSwitch.ToggleSwitchAlignment.Far)
|
||||
{
|
||||
textXPos = (float)fullRectangle.X + (float)fullRectangle.Width - (float)textSize.Width;
|
||||
}
|
||||
|
||||
RectangleF textRectangle = new RectangleF(textXPos, (float)fullRectangle.Y + (((float)fullRectangle.Height - (float)textSize.Height) / 2), textSize.Width, textSize.Height);
|
||||
|
||||
Color textForeColor = ToggleSwitch.OffForeColor;
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
textForeColor = textForeColor.ToGrayScale();
|
||||
|
||||
using (Brush textBrush = new SolidBrush(textForeColor))
|
||||
{
|
||||
g.DrawString(ToggleSwitch.OffText, ToggleSwitch.OffFont, textBrush, textRectangle);
|
||||
}
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
}
|
||||
|
||||
public override void RenderButton(Graphics g, Rectangle buttonRectangle)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
|
||||
|
||||
buttonRectangle.Inflate(-1, -1);
|
||||
|
||||
using (GraphicsPath buttonPath = GetRoundedRectanglePath(buttonRectangle, CornerRadius))
|
||||
{
|
||||
g.SetClip(buttonPath);
|
||||
|
||||
//Draw button surface
|
||||
Color buttonSurfaceColor1 = ButtonNormalSurfaceColor1;
|
||||
Color buttonSurfaceColor2 = ButtonNormalSurfaceColor2;
|
||||
|
||||
if (ToggleSwitch.IsButtonPressed)
|
||||
{
|
||||
buttonSurfaceColor1 = ButtonPressedSurfaceColor1;
|
||||
buttonSurfaceColor2 = ButtonPressedSurfaceColor2;
|
||||
}
|
||||
else if (ToggleSwitch.IsButtonHovered)
|
||||
{
|
||||
buttonSurfaceColor1 = ButtonHoverSurfaceColor1;
|
||||
buttonSurfaceColor2 = ButtonHoverSurfaceColor2;
|
||||
}
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
{
|
||||
buttonSurfaceColor1 = buttonSurfaceColor1.ToGrayScale();
|
||||
buttonSurfaceColor2 = buttonSurfaceColor2.ToGrayScale();
|
||||
}
|
||||
|
||||
using (Brush buttonSurfaceBrush = new LinearGradientBrush(buttonRectangle, buttonSurfaceColor1, buttonSurfaceColor2, LinearGradientMode.Vertical))
|
||||
{
|
||||
g.FillPath(buttonSurfaceBrush, buttonPath);
|
||||
}
|
||||
|
||||
//Draw button border
|
||||
Color buttonBorderColor1 = ButtonNormalBorderColor1;
|
||||
Color buttonBorderColor2 = ButtonNormalBorderColor2;
|
||||
|
||||
if (ToggleSwitch.IsButtonPressed)
|
||||
{
|
||||
buttonBorderColor1 = ButtonPressedBorderColor1;
|
||||
buttonBorderColor2 = ButtonPressedBorderColor2;
|
||||
}
|
||||
else if (ToggleSwitch.IsButtonHovered)
|
||||
{
|
||||
buttonBorderColor1 = ButtonHoverBorderColor1;
|
||||
buttonBorderColor2 = ButtonHoverBorderColor2;
|
||||
}
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
{
|
||||
buttonBorderColor1 = buttonBorderColor1.ToGrayScale();
|
||||
buttonBorderColor2 = buttonBorderColor2.ToGrayScale();
|
||||
}
|
||||
|
||||
using (Brush buttonBorderBrush = new LinearGradientBrush(buttonRectangle, buttonBorderColor1, buttonBorderColor2, LinearGradientMode.Vertical))
|
||||
{
|
||||
using (Pen buttonBorderPen = new Pen(buttonBorderBrush))
|
||||
{
|
||||
g.DrawPath(buttonBorderPen, buttonPath);
|
||||
}
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
|
||||
//Draw button image
|
||||
Image buttonImage = ToggleSwitch.ButtonImage ?? (ToggleSwitch.Checked ? ToggleSwitch.OnButtonImage : ToggleSwitch.OffButtonImage);
|
||||
|
||||
if (buttonImage != null)
|
||||
{
|
||||
g.SetClip(buttonPath);
|
||||
|
||||
ToggleSwitch.ToggleSwitchButtonAlignment alignment = ToggleSwitch.ButtonImage != null ? ToggleSwitch.ButtonAlignment : (ToggleSwitch.Checked ? ToggleSwitch.OnButtonAlignment : ToggleSwitch.OffButtonAlignment);
|
||||
|
||||
Size imageSize = buttonImage.Size;
|
||||
|
||||
Rectangle imageRectangle;
|
||||
|
||||
int imageXPos = buttonRectangle.X;
|
||||
|
||||
bool scaleImage = ToggleSwitch.ButtonImage != null ? ToggleSwitch.ButtonScaleImageToFit : (ToggleSwitch.Checked ? ToggleSwitch.OnButtonScaleImageToFit : ToggleSwitch.OffButtonScaleImageToFit);
|
||||
|
||||
if (scaleImage)
|
||||
{
|
||||
Size canvasSize = buttonRectangle.Size;
|
||||
Size resizedImageSize = ImageHelper.RescaleImageToFit(imageSize, canvasSize);
|
||||
|
||||
if (alignment == ToggleSwitch.ToggleSwitchButtonAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)buttonRectangle.X + (((float)buttonRectangle.Width - (float)resizedImageSize.Width) / 2));
|
||||
}
|
||||
else if (alignment == ToggleSwitch.ToggleSwitchButtonAlignment.Right)
|
||||
{
|
||||
imageXPos = (int)((float)buttonRectangle.X + (float)buttonRectangle.Width - (float)resizedImageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)buttonRectangle.Y + (((float)buttonRectangle.Height - (float)resizedImageSize.Height) / 2)), resizedImageSize.Width, resizedImageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(buttonImage, imageRectangle, 0, 0, buttonImage.Width, buttonImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImage(buttonImage, imageRectangle);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (alignment == ToggleSwitch.ToggleSwitchButtonAlignment.Center)
|
||||
{
|
||||
imageXPos = (int)((float)buttonRectangle.X + (((float)buttonRectangle.Width - (float)imageSize.Width) / 2));
|
||||
}
|
||||
else if (alignment == ToggleSwitch.ToggleSwitchButtonAlignment.Right)
|
||||
{
|
||||
imageXPos = (int)((float)buttonRectangle.X + (float)buttonRectangle.Width - (float)imageSize.Width);
|
||||
}
|
||||
|
||||
imageRectangle = new Rectangle(imageXPos, (int)((float)buttonRectangle.Y + (((float)buttonRectangle.Height - (float)imageSize.Height) / 2)), imageSize.Width, imageSize.Height);
|
||||
|
||||
if (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled)
|
||||
g.DrawImage(buttonImage, imageRectangle, 0, 0, buttonImage.Width, buttonImage.Height, GraphicsUnit.Pixel, ImageHelper.GetGrayscaleAttributes());
|
||||
else
|
||||
g.DrawImageUnscaled(buttonImage, imageRectangle);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Render Method Implementations
|
||||
|
||||
#region Helper Method Implementations
|
||||
|
||||
public GraphicsPath GetRoundedRectanglePath(Rectangle rectangle, int radius)
|
||||
{
|
||||
GraphicsPath gp = new GraphicsPath();
|
||||
int diameter = 2*radius;
|
||||
|
||||
if (diameter > ToggleSwitch.Height)
|
||||
diameter = ToggleSwitch.Height;
|
||||
|
||||
if (diameter > ToggleSwitch.Width)
|
||||
diameter = ToggleSwitch.Width;
|
||||
|
||||
gp.AddArc(rectangle.X, rectangle.Y, diameter, diameter, 180, 90);
|
||||
gp.AddArc(rectangle.X + rectangle.Width - diameter, rectangle.Y, diameter, diameter, 270, 90);
|
||||
gp.AddArc(rectangle.X + rectangle.Width - diameter, rectangle.Y + rectangle.Height - diameter, diameter, diameter, 0, 90);
|
||||
gp.AddArc(rectangle.X, rectangle.Y + rectangle.Height - diameter, diameter, diameter, 90, 90);
|
||||
gp.CloseFigure();
|
||||
|
||||
return gp;
|
||||
}
|
||||
|
||||
public override int GetButtonWidth()
|
||||
{
|
||||
float buttonWidth = 1.53f*(ToggleSwitch.Height - 2);
|
||||
return (int) buttonWidth;
|
||||
}
|
||||
|
||||
public override Rectangle GetButtonRectangle()
|
||||
{
|
||||
int buttonWidth = GetButtonWidth();
|
||||
return GetButtonRectangle(buttonWidth);
|
||||
}
|
||||
|
||||
public override Rectangle GetButtonRectangle(int buttonWidth)
|
||||
{
|
||||
Rectangle buttonRect = new Rectangle(ToggleSwitch.ButtonValue, 0, buttonWidth, ToggleSwitch.Height);
|
||||
return buttonRect;
|
||||
}
|
||||
|
||||
#endregion Helper Method Implementations
|
||||
}
|
||||
}
|
||||
|
204
ToggleSwitch/Renderers/ToggleSwitchPlainAndSimpleRenderer.cs
Normal file
|
@ -0,0 +1,204 @@
|
|||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
|
||||
namespace JCS
|
||||
{
|
||||
public class ToggleSwitchPlainAndSimpleRenderer : ToggleSwitchRendererBase
|
||||
{
|
||||
#region Constructor
|
||||
|
||||
public ToggleSwitchPlainAndSimpleRenderer()
|
||||
{
|
||||
BorderColorChecked = Color.Black;
|
||||
BorderColorUnchecked = Color.Black;
|
||||
BorderWidth = 2;
|
||||
ButtonMargin = 1;
|
||||
InnerBackgroundColor = Color.White;
|
||||
ButtonColor = Color.Black;
|
||||
}
|
||||
|
||||
#endregion Constructor
|
||||
|
||||
#region Public Properties
|
||||
|
||||
public Color BorderColorChecked { get; set; }
|
||||
public Color BorderColorUnchecked { get; set; }
|
||||
public int BorderWidth { get; set; }
|
||||
public int ButtonMargin { get; set; }
|
||||
public Color InnerBackgroundColor { get; set; }
|
||||
public Color ButtonColor { get; set; }
|
||||
|
||||
#endregion Public Properties
|
||||
|
||||
#region Render Method Implementations
|
||||
|
||||
public override void RenderBorder(Graphics g, Rectangle borderRectangle)
|
||||
{
|
||||
//Draw this one AFTER the button is drawn in the RenderButton method
|
||||
}
|
||||
|
||||
public override void RenderLeftToggleField(Graphics g, Rectangle leftRectangle, int totalToggleFieldWidth)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
|
||||
int buttonWidth = GetButtonWidth();
|
||||
|
||||
Rectangle controlRectangle = new Rectangle(0, 0, ToggleSwitch.Width, ToggleSwitch.Height);
|
||||
GraphicsPath innerBorderClipPath = GetInnerBorderClipPath(controlRectangle);
|
||||
|
||||
g.SetClip(innerBorderClipPath);
|
||||
g.IntersectClip(leftRectangle);
|
||||
|
||||
using (Brush innerBackgroundBrush = new SolidBrush(InnerBackgroundColor))
|
||||
{
|
||||
g.FillPath(innerBackgroundBrush, innerBorderClipPath);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
|
||||
public override void RenderRightToggleField(Graphics g, Rectangle rightRectangle, int totalToggleFieldWidth)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
|
||||
int buttonWidth = GetButtonWidth();
|
||||
|
||||
Rectangle controlRectangle = new Rectangle(0, 0, ToggleSwitch.Width, ToggleSwitch.Height);
|
||||
GraphicsPath innerBorderClipPath = GetInnerBorderClipPath(controlRectangle);
|
||||
|
||||
g.SetClip(innerBorderClipPath);
|
||||
g.IntersectClip(rightRectangle);
|
||||
|
||||
using (Brush innerBackgroundBrush = new SolidBrush(InnerBackgroundColor))
|
||||
{
|
||||
g.FillPath(innerBackgroundBrush, innerBorderClipPath);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
|
||||
public override void RenderButton(Graphics g, Rectangle buttonRectangle)
|
||||
{
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
|
||||
GraphicsPath buttonClipPath = GetButtonClipPath();
|
||||
|
||||
Rectangle controlRectangle = new Rectangle(0, 0, ToggleSwitch.Width, ToggleSwitch.Height);
|
||||
GraphicsPath outerBorderClipPath = GetControlClipPath(controlRectangle);
|
||||
GraphicsPath innerBorderClipPath = GetInnerBorderClipPath(controlRectangle);
|
||||
|
||||
g.SetClip(innerBorderClipPath);
|
||||
g.IntersectClip(buttonRectangle);
|
||||
|
||||
//Fill the button surface with the background color
|
||||
|
||||
using (Brush innerBackgroundBrush = new SolidBrush(InnerBackgroundColor))
|
||||
{
|
||||
g.FillRectangle(innerBackgroundBrush, buttonRectangle);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
|
||||
g.SetClip(GetButtonClipPath());
|
||||
g.IntersectClip(controlRectangle);
|
||||
|
||||
//Render the button
|
||||
|
||||
using (Brush buttonBrush = new SolidBrush(ButtonColor))
|
||||
{
|
||||
g.FillPath(buttonBrush, buttonClipPath);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
|
||||
//Render the border
|
||||
|
||||
g.SetClip(outerBorderClipPath);
|
||||
g.ExcludeClip(new Region(innerBorderClipPath));
|
||||
|
||||
Color borderColor = ToggleSwitch.Checked ? BorderColorChecked : BorderColorUnchecked;
|
||||
|
||||
using (Brush borderBrush = new SolidBrush(borderColor))
|
||||
{
|
||||
g.FillPath(borderBrush, outerBorderClipPath);
|
||||
}
|
||||
|
||||
g.ResetClip();
|
||||
}
|
||||
|
||||
#endregion Render Method Implementations
|
||||
|
||||
#region Helper Method Implementations
|
||||
|
||||
public GraphicsPath GetControlClipPath(Rectangle controlRectangle)
|
||||
{
|
||||
GraphicsPath borderPath = new GraphicsPath();
|
||||
borderPath.AddArc(controlRectangle.X, controlRectangle.Y, controlRectangle.Height, controlRectangle.Height, 90, 180);
|
||||
borderPath.AddArc(controlRectangle.X + controlRectangle.Width - controlRectangle.Height, controlRectangle.Y, controlRectangle.Height, controlRectangle.Height, 270, 180);
|
||||
borderPath.CloseFigure();
|
||||
|
||||
return borderPath;
|
||||
}
|
||||
|
||||
public GraphicsPath GetInnerBorderClipPath(Rectangle controlRectangle)
|
||||
{
|
||||
Rectangle innerBorderRectangle = new Rectangle(controlRectangle.X + BorderWidth,
|
||||
controlRectangle.Y + BorderWidth,
|
||||
controlRectangle.Width - (2 * BorderWidth),
|
||||
controlRectangle.Height - (2 * BorderWidth));
|
||||
|
||||
GraphicsPath borderPath = new GraphicsPath();
|
||||
borderPath.AddArc(innerBorderRectangle.X, innerBorderRectangle.Y, innerBorderRectangle.Height, innerBorderRectangle.Height, 90, 180);
|
||||
borderPath.AddArc(innerBorderRectangle.X + innerBorderRectangle.Width - innerBorderRectangle.Height, innerBorderRectangle.Y, innerBorderRectangle.Height, innerBorderRectangle.Height, 270, 180);
|
||||
borderPath.CloseFigure();
|
||||
|
||||
return borderPath;
|
||||
}
|
||||
|
||||
public GraphicsPath GetButtonClipPath()
|
||||
{
|
||||
Rectangle buttonRectangle = GetButtonRectangle();
|
||||
|
||||
GraphicsPath buttonPath = new GraphicsPath();
|
||||
|
||||
buttonPath.AddArc(buttonRectangle.X + ButtonMargin, buttonRectangle.Y + ButtonMargin, buttonRectangle.Height - (2 * ButtonMargin), buttonRectangle.Height - (2 * ButtonMargin), 0, 360);
|
||||
|
||||
return buttonPath;
|
||||
}
|
||||
|
||||
public override int GetButtonWidth()
|
||||
{
|
||||
int buttonWidth = ToggleSwitch.Height - (2 * BorderWidth);
|
||||
return buttonWidth > 0 ? buttonWidth : 0;
|
||||
}
|
||||
|
||||
public override Rectangle GetButtonRectangle()
|
||||
{
|
||||
int buttonWidth = GetButtonWidth();
|
||||
return GetButtonRectangle(buttonWidth);
|
||||
}
|
||||
|
||||
public override Rectangle GetButtonRectangle(int buttonWidth)
|
||||
{
|
||||
if (buttonWidth <= 0)
|
||||
{
|
||||
return Rectangle.Empty;
|
||||
}
|
||||
|
||||
Rectangle buttonRect = new Rectangle(ToggleSwitch.ButtonValue, BorderWidth, buttonWidth, buttonWidth);
|
||||
|
||||
if (buttonRect.X < BorderWidth + ButtonMargin - 1)
|
||||
buttonRect.X = BorderWidth + ButtonMargin - 1;
|
||||
|
||||
if (buttonRect.X + buttonRect.Width > ToggleSwitch.Width - BorderWidth - ButtonMargin + 1)
|
||||
buttonRect.X = ToggleSwitch.Width - buttonRect.Width - BorderWidth - ButtonMargin + 1;
|
||||
|
||||
return buttonRect;
|
||||
}
|
||||
|
||||
#endregion Helper Method Implementations
|
||||
}
|
||||
}
|
101
ToggleSwitch/Renderers/ToggleSwitchRendererBase.cs
Normal file
|
@ -0,0 +1,101 @@
|
|||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace JCS
|
||||
{
|
||||
public abstract class ToggleSwitchRendererBase
|
||||
{
|
||||
#region Private Members
|
||||
|
||||
private ToggleSwitch _toggleSwitch;
|
||||
|
||||
#endregion Private Members
|
||||
|
||||
#region Constructor
|
||||
|
||||
protected ToggleSwitchRendererBase()
|
||||
{}
|
||||
|
||||
internal void SetToggleSwitch(ToggleSwitch toggleSwitch)
|
||||
{
|
||||
_toggleSwitch = toggleSwitch;
|
||||
}
|
||||
|
||||
internal ToggleSwitch ToggleSwitch
|
||||
{
|
||||
get { return _toggleSwitch; }
|
||||
}
|
||||
|
||||
#endregion Constructor
|
||||
|
||||
#region Render Methods
|
||||
|
||||
public void RenderBackground(PaintEventArgs e)
|
||||
{
|
||||
if (_toggleSwitch == null)
|
||||
return;
|
||||
|
||||
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
|
||||
|
||||
Rectangle controlRectangle = new Rectangle(0, 0, _toggleSwitch.Width, _toggleSwitch.Height);
|
||||
|
||||
FillBackground(e.Graphics, controlRectangle);
|
||||
|
||||
RenderBorder(e.Graphics, controlRectangle);
|
||||
}
|
||||
|
||||
public void RenderControl(PaintEventArgs e)
|
||||
{
|
||||
if (_toggleSwitch == null)
|
||||
return;
|
||||
|
||||
e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
|
||||
|
||||
Rectangle buttonRectangle = GetButtonRectangle();
|
||||
int totalToggleFieldWidth = ToggleSwitch.Width - buttonRectangle.Width;
|
||||
|
||||
if (buttonRectangle.X > 0)
|
||||
{
|
||||
Rectangle leftRectangle = new Rectangle(0, 0, buttonRectangle.X, ToggleSwitch.Height);
|
||||
|
||||
if (leftRectangle.Width > 0)
|
||||
RenderLeftToggleField(e.Graphics, leftRectangle, totalToggleFieldWidth);
|
||||
}
|
||||
|
||||
if (buttonRectangle.X + buttonRectangle.Width < e.ClipRectangle.Width)
|
||||
{
|
||||
Rectangle rightRectangle = new Rectangle(buttonRectangle.X + buttonRectangle.Width, 0, ToggleSwitch.Width - buttonRectangle.X - buttonRectangle.Width, ToggleSwitch.Height);
|
||||
|
||||
if (rightRectangle.Width > 0)
|
||||
RenderRightToggleField(e.Graphics, rightRectangle, totalToggleFieldWidth);
|
||||
}
|
||||
|
||||
RenderButton(e.Graphics, buttonRectangle);
|
||||
}
|
||||
|
||||
public void FillBackground(Graphics g, Rectangle controlRectangle)
|
||||
{
|
||||
Color backColor = (!ToggleSwitch.Enabled && ToggleSwitch.GrayWhenDisabled) ? ToggleSwitch.BackColor.ToGrayScale() : ToggleSwitch.BackColor;
|
||||
|
||||
using (Brush backBrush = new SolidBrush(backColor))
|
||||
{
|
||||
g.FillRectangle(backBrush, controlRectangle);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void RenderBorder(Graphics g, Rectangle borderRectangle);
|
||||
public abstract void RenderLeftToggleField(Graphics g, Rectangle leftRectangle, int totalToggleFieldWidth);
|
||||
public abstract void RenderRightToggleField(Graphics g, Rectangle rightRectangle, int totalToggleFieldWidth);
|
||||
public abstract void RenderButton(Graphics g, Rectangle buttonRectangle);
|
||||
|
||||
#endregion Render Methods
|
||||
|
||||
#region Helper Methods
|
||||
|
||||
public abstract int GetButtonWidth();
|
||||
public abstract Rectangle GetButtonRectangle();
|
||||
public abstract Rectangle GetButtonRectangle(int buttonWidth);
|
||||
|
||||
#endregion Helper Methods
|
||||
}
|
||||
}
|
1189
ToggleSwitch/ToggleSwitch.cs
Normal file
71
ToggleSwitch/ToggleSwitch.csproj
Normal file
|
@ -0,0 +1,71 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{49B88FFA-F02C-4709-BA65-9F8996444ECD}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>ToggleSwitch</RootNamespace>
|
||||
<AssemblyName>ToggleSwitch</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<UseVSHostingProcess>true</UseVSHostingProcess>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="GraphicsExtensionMethods.cs" />
|
||||
<Compile Include="ImageHelper.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="RendererChangedEventArgs.cs" />
|
||||
<Compile Include="Renderers\ToggleSwitchCarbonRenderer.cs" />
|
||||
<Compile Include="Renderers\ToggleSwitchFancyRenderer.cs" />
|
||||
<Compile Include="Renderers\ToggleSwitchIphoneRenderer.cs" />
|
||||
<Compile Include="Renderers\ToggleSwitchModernRenderer.cs" />
|
||||
<Compile Include="Renderers\ToggleSwitchPlainAndSimpleRenderer.cs" />
|
||||
<Compile Include="ToggleSwitch.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Renderers\ToggleSwitchAndroidRenderer.cs" />
|
||||
<Compile Include="Renderers\ToggleSwitchBrushedMetalRenderer.cs" />
|
||||
<Compile Include="Renderers\ToggleSwitchIOS5Renderer.cs" />
|
||||
<Compile Include="Renderers\ToggleSwitchMetroRenderer.cs" />
|
||||
<Compile Include="Renderers\ToggleSwitchOSXRenderer.cs" />
|
||||
<Compile Include="Renderers\ToggleSwitchRendererBase.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="VersionHistory.txt" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
11
ToggleSwitch/VersionHistory.txt
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
Version 1.1
|
||||
-----------
|
||||
NEW: BeforeRendering event added to make it easier to customize the renderer properties
|
||||
NEW: Style and Renderer added: PlainAndSimple
|
||||
UPDATED: Demo app updated with the new features
|
||||
|
||||
|
||||
Version 1.0
|
||||
------------
|
||||
Initial Release
|
BIN
ToggleSwitch/bin/Debug/ToggleSwitch.dll
Normal file
BIN
ToggleSwitch/bin/Debug/ToggleSwitch.pdb
Normal file
|
@ -0,0 +1,4 @@
|
|||
// <autogenerated />
|
||||
using System;
|
||||
using System.Reflection;
|
||||
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.0", FrameworkDisplayName = ".NET Framework 4")]
|
BIN
ToggleSwitch/obj/Debug/DesignTimeResolveAssemblyReferences.cache
Normal file
|
@ -0,0 +1 @@
|
|||
b9f63ef76dca6d00d7314d042b5bc449c6f8367e
|
|
@ -0,0 +1,16 @@
|
|||
C:\Users\Johnny\Documents\_Visual Studio Projects\ToggleSwitch\ToggleSwitch\bin\Debug\ToggleSwitch.dll
|
||||
C:\Users\Johnny\Documents\_Visual Studio Projects\ToggleSwitch\ToggleSwitch\bin\Debug\ToggleSwitch.pdb
|
||||
C:\Users\Johnny\Documents\_Visual Studio Projects\ToggleSwitch\ToggleSwitch\obj\Debug\ToggleSwitch.dll
|
||||
C:\Users\Johnny\Documents\_Visual Studio Projects\ToggleSwitch\ToggleSwitch\obj\Debug\ToggleSwitch.pdb
|
||||
C:\Users\Johnny\Documents\_Visual Studio Projects\ToggleSwitch\ToggleSwitch\obj\Debug\ToggleSwitch.csprojResolveAssemblyReference.cache
|
||||
D:\Projekt\CodeProject\ToggleSwitch\ToggleSwitch\bin\Debug\ToggleSwitch.dll
|
||||
D:\Projekt\CodeProject\ToggleSwitch\ToggleSwitch\bin\Debug\ToggleSwitch.pdb
|
||||
D:\Projekt\CodeProject\ToggleSwitch\ToggleSwitch\obj\Debug\ToggleSwitch.csproj.CoreCompileInputs.cache
|
||||
D:\Projekt\CodeProject\ToggleSwitch\ToggleSwitch\obj\Debug\ToggleSwitch.dll
|
||||
D:\Projekt\CodeProject\ToggleSwitch\ToggleSwitch\obj\Debug\ToggleSwitch.pdb
|
||||
D:\CKMAI_Documents\Programming\GitHub\ToggleSwitch\ToggleSwitch\bin\Debug\ToggleSwitch.dll
|
||||
D:\CKMAI_Documents\Programming\GitHub\ToggleSwitch\ToggleSwitch\bin\Debug\ToggleSwitch.pdb
|
||||
D:\CKMAI_Documents\Programming\GitHub\ToggleSwitch\ToggleSwitch\obj\Debug\ToggleSwitch.csprojAssemblyReference.cache
|
||||
D:\CKMAI_Documents\Programming\GitHub\ToggleSwitch\ToggleSwitch\obj\Debug\ToggleSwitch.csproj.CoreCompileInputs.cache
|
||||
D:\CKMAI_Documents\Programming\GitHub\ToggleSwitch\ToggleSwitch\obj\Debug\ToggleSwitch.dll
|
||||
D:\CKMAI_Documents\Programming\GitHub\ToggleSwitch\ToggleSwitch\obj\Debug\ToggleSwitch.pdb
|
BIN
ToggleSwitch/obj/Debug/ToggleSwitch.dll
Normal file
BIN
ToggleSwitch/obj/Debug/ToggleSwitch.pdb
Normal file
|
@ -0,0 +1 @@
|
|||
1f5b776f29663f5f08aa19abd20108ea10358598
|
|
@ -0,0 +1,9 @@
|
|||
C:\Users\Johnny\Documents\_Visual Studio Projects\ToggleSwitch\ToggleSwitch\bin\Release\ToggleSwitch.dll
|
||||
C:\Users\Johnny\Documents\_Visual Studio Projects\ToggleSwitch\ToggleSwitch\bin\Release\ToggleSwitch.pdb
|
||||
C:\Users\Johnny\Documents\_Visual Studio Projects\ToggleSwitch\ToggleSwitch\obj\Release\ToggleSwitch.dll
|
||||
C:\Users\Johnny\Documents\_Visual Studio Projects\ToggleSwitch\ToggleSwitch\obj\Release\ToggleSwitch.pdb
|
||||
D:\Projekt\CodeProject\ToggleSwitch\ToggleSwitch\bin\Release\ToggleSwitch.dll
|
||||
D:\Projekt\CodeProject\ToggleSwitch\ToggleSwitch\bin\Release\ToggleSwitch.pdb
|
||||
D:\Projekt\CodeProject\ToggleSwitch\ToggleSwitch\obj\Release\ToggleSwitch.csproj.CoreCompileInputs.cache
|
||||
D:\Projekt\CodeProject\ToggleSwitch\ToggleSwitch\obj\Release\ToggleSwitch.dll
|
||||
D:\Projekt\CodeProject\ToggleSwitch\ToggleSwitch\obj\Release\ToggleSwitch.pdb
|
BIN
ToggleSwitch/obj/Release/ToggleSwitch.dll
Normal file
BIN
ToggleSwitch/obj/Release/ToggleSwitch.pdb
Normal file
1176
ToggleSwitchDemo/DemoForm.Designer.cs
generated
Normal file
407
ToggleSwitchDemo/DemoForm.cs
Normal file
|
@ -0,0 +1,407 @@
|
|||
using System.Drawing;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using JCS;
|
||||
using ToggleSwitchDemo.Properties;
|
||||
|
||||
namespace ToggleSwitchDemo
|
||||
{
|
||||
public partial class DemoForm : Form
|
||||
{
|
||||
public DemoForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
SetPropertiesForStylesTabSwitches();
|
||||
SetPropertiesForPropertiesTabSwitches();
|
||||
SetPropertiesForCustomizationsTabSwitches();
|
||||
}
|
||||
|
||||
public void SetPropertiesForStylesTabSwitches()
|
||||
{
|
||||
//Set the properties for the ToggleSwitches on the "Styles" tab
|
||||
|
||||
MetroStyleToggleSwitch.Style = JCS.ToggleSwitch.ToggleSwitchStyle.Metro; //Default
|
||||
MetroStyleToggleSwitch.Size = new Size(75, 23);
|
||||
|
||||
IOS5StyleToggleSwitch.Style = JCS.ToggleSwitch.ToggleSwitchStyle.IOS5;
|
||||
IOS5StyleToggleSwitch.Size = new Size(98, 42);
|
||||
IOS5StyleToggleSwitch.OnText = "ON";
|
||||
IOS5StyleToggleSwitch.OnFont = new Font(DemoTabControl.Font.FontFamily, 12, FontStyle.Bold);
|
||||
IOS5StyleToggleSwitch.OnForeColor = Color.White;
|
||||
IOS5StyleToggleSwitch.OffText = "OFF";
|
||||
IOS5StyleToggleSwitch.OffFont = new Font(DemoTabControl.Font.FontFamily, 12, FontStyle.Bold);
|
||||
IOS5StyleToggleSwitch.OffForeColor = Color.FromArgb(141, 123, 141);
|
||||
|
||||
AndroidStyleToggleSwitch.Style = JCS.ToggleSwitch.ToggleSwitchStyle.Android;
|
||||
AndroidStyleToggleSwitch.Size = new Size(78, 23);
|
||||
AndroidStyleToggleSwitch.OnText = "ON";
|
||||
AndroidStyleToggleSwitch.OnFont = new Font(DemoTabControl.Font.FontFamily, 8, FontStyle.Bold);
|
||||
AndroidStyleToggleSwitch.OnForeColor = Color.White;
|
||||
AndroidStyleToggleSwitch.OffText = "OFF";
|
||||
AndroidStyleToggleSwitch.OffFont = new Font(DemoTabControl.Font.FontFamily, 8, FontStyle.Bold);
|
||||
AndroidStyleToggleSwitch.OffForeColor = Color.FromArgb(141, 123, 141);
|
||||
|
||||
BrushedMetalStyleToggleSwitch.Style = JCS.ToggleSwitch.ToggleSwitchStyle.BrushedMetal;
|
||||
BrushedMetalStyleToggleSwitch.Size = new Size(93, 30);
|
||||
BrushedMetalStyleToggleSwitch.OnText = "ON";
|
||||
BrushedMetalStyleToggleSwitch.OnFont = new Font(DemoTabControl.Font.FontFamily, 10, FontStyle.Bold);
|
||||
BrushedMetalStyleToggleSwitch.OnForeColor = Color.White;
|
||||
BrushedMetalStyleToggleSwitch.OffText = "OFF";
|
||||
BrushedMetalStyleToggleSwitch.OffFont = new Font(DemoTabControl.Font.FontFamily, 10, FontStyle.Bold);
|
||||
BrushedMetalStyleToggleSwitch.OffForeColor = Color.White;
|
||||
|
||||
IphoneStyleToggleSwitch.Style = JCS.ToggleSwitch.ToggleSwitchStyle.Iphone;
|
||||
IphoneStyleToggleSwitch.Size = new Size(93, 30);
|
||||
IphoneStyleToggleSwitch.OnText = "ON";
|
||||
IphoneStyleToggleSwitch.OnFont = new Font(DemoTabControl.Font.FontFamily, 10, FontStyle.Bold);
|
||||
IphoneStyleToggleSwitch.OnForeColor = Color.White;
|
||||
IphoneStyleToggleSwitch.OffText = "OFF";
|
||||
IphoneStyleToggleSwitch.OffFont = new Font(DemoTabControl.Font.FontFamily, 10, FontStyle.Bold);
|
||||
IphoneStyleToggleSwitch.OffForeColor = Color.FromArgb(92, 92, 92);
|
||||
|
||||
ModernStyleToggleSwitch.Style = JCS.ToggleSwitch.ToggleSwitchStyle.Modern;
|
||||
ModernStyleToggleSwitch.Size = new Size(85, 32);
|
||||
ModernStyleToggleSwitch.OnText = "ON";
|
||||
ModernStyleToggleSwitch.OnFont = new Font(DemoTabControl.Font.FontFamily, 10, FontStyle.Bold);
|
||||
ModernStyleToggleSwitch.OnForeColor = Color.White;
|
||||
ModernStyleToggleSwitch.OffText = "OFF";
|
||||
ModernStyleToggleSwitch.OffFont = new Font(DemoTabControl.Font.FontFamily, 10, FontStyle.Bold);
|
||||
ModernStyleToggleSwitch.OffForeColor = Color.FromArgb(153, 153, 153);
|
||||
|
||||
CarbonStyleToggleSwitch.Style = JCS.ToggleSwitch.ToggleSwitchStyle.Carbon;
|
||||
CarbonStyleToggleSwitch.Size = new Size(93, 30);
|
||||
CarbonStyleToggleSwitch.OnText = "On";
|
||||
CarbonStyleToggleSwitch.OnFont = new Font(DemoTabControl.Font.FontFamily, 10, FontStyle.Bold);
|
||||
CarbonStyleToggleSwitch.OnForeColor = Color.White;
|
||||
CarbonStyleToggleSwitch.OffText = "Off";
|
||||
CarbonStyleToggleSwitch.OffFont = new Font(DemoTabControl.Font.FontFamily, 10, FontStyle.Bold);
|
||||
CarbonStyleToggleSwitch.OffForeColor = Color.White;
|
||||
|
||||
OSXStyleToggleSwitch.Style = JCS.ToggleSwitch.ToggleSwitchStyle.OSX;
|
||||
OSXStyleToggleSwitch.Size = new Size(93, 25);
|
||||
|
||||
FancyStyleToggleSwitch.Style = JCS.ToggleSwitch.ToggleSwitchStyle.Fancy;
|
||||
FancyStyleToggleSwitch.Size = new Size(100, 30);
|
||||
FancyStyleToggleSwitch.OnText = "ON";
|
||||
FancyStyleToggleSwitch.OnFont = new Font(DemoTabControl.Font.FontFamily, 10, FontStyle.Bold);
|
||||
FancyStyleToggleSwitch.OnForeColor = Color.White;
|
||||
FancyStyleToggleSwitch.OffText = "OFF";
|
||||
FancyStyleToggleSwitch.OffFont = new Font(DemoTabControl.Font.FontFamily, 10, FontStyle.Bold);
|
||||
FancyStyleToggleSwitch.OffForeColor = Color.White;
|
||||
FancyStyleToggleSwitch.ButtonImage = Resources.handle;
|
||||
|
||||
PlainAndSimpleStyleToggleSwitch.Style = JCS.ToggleSwitch.ToggleSwitchStyle.PlainAndSimpel;
|
||||
PlainAndSimpleStyleToggleSwitch.Size = new Size(44, 22);
|
||||
}
|
||||
|
||||
public void SetPropertiesForPropertiesTabSwitches()
|
||||
{
|
||||
//Set the properties for the ToggleSwitches on the "(Semi)-Important Properties" tab
|
||||
|
||||
//AllowUserChange example:
|
||||
|
||||
AllowUserChangeToggleSwitch1.AllowUserChange = false;
|
||||
AllowUserChangeToggleSwitch2.AllowUserChange = true;
|
||||
|
||||
//Animation example:
|
||||
|
||||
NoAnimationToggleSwitch.Style = JCS.ToggleSwitch.ToggleSwitchStyle.Carbon; //Only to provide an interesting look
|
||||
NoAnimationToggleSwitch.Size = new Size(93, 30); //Only to provide an interesting look
|
||||
NoAnimationToggleSwitch.OnText = "On"; //Only to provide an interesting look
|
||||
NoAnimationToggleSwitch.OnFont = new Font(DemoTabControl.Font.FontFamily, 10, FontStyle.Bold); //Only to provide an interesting look
|
||||
NoAnimationToggleSwitch.OnForeColor = Color.White; //Only to provide an interesting look
|
||||
NoAnimationToggleSwitch.OffText = "Off"; //Only to provide an interesting look
|
||||
NoAnimationToggleSwitch.OffFont = new Font(DemoTabControl.Font.FontFamily, 10, FontStyle.Bold); //Only to provide an interesting look
|
||||
NoAnimationToggleSwitch.OffForeColor = Color.White; //Only to provide an interesting look
|
||||
NoAnimationToggleSwitch.UseAnimation = false;
|
||||
|
||||
FastAnimationToggleSwitch.Style = JCS.ToggleSwitch.ToggleSwitchStyle.Carbon; //Only to provide an interesting look
|
||||
FastAnimationToggleSwitch.Size = new Size(93, 30); //Only to provide an interesting look
|
||||
FastAnimationToggleSwitch.OnText = "On"; //Only to provide an interesting look
|
||||
FastAnimationToggleSwitch.OnFont = new Font(DemoTabControl.Font.FontFamily, 10, FontStyle.Bold); //Only to provide an interesting look
|
||||
FastAnimationToggleSwitch.OnForeColor = Color.White; //Only to provide an interesting look
|
||||
FastAnimationToggleSwitch.OffText = "Off"; //Only to provide an interesting look
|
||||
FastAnimationToggleSwitch.OffFont = new Font(DemoTabControl.Font.FontFamily, 10, FontStyle.Bold); //Only to provide an interesting look
|
||||
FastAnimationToggleSwitch.OffForeColor = Color.White; //Only to provide an interesting look
|
||||
FastAnimationToggleSwitch.UseAnimation = true; //Default
|
||||
FastAnimationToggleSwitch.AnimationInterval = 1; //Default
|
||||
FastAnimationToggleSwitch.AnimationStep = 10; //Default
|
||||
|
||||
SlowAnimationToggleSwitch.Style = JCS.ToggleSwitch.ToggleSwitchStyle.Carbon; //Only to provide an interesting look
|
||||
SlowAnimationToggleSwitch.Size = new Size(93, 30); //Only to provide an interesting look
|
||||
SlowAnimationToggleSwitch.OnText = "On"; //Only to provide an interesting look
|
||||
SlowAnimationToggleSwitch.OnFont = new Font(DemoTabControl.Font.FontFamily, 10, FontStyle.Bold); //Only to provide an interesting look
|
||||
SlowAnimationToggleSwitch.OnForeColor = Color.White; //Only to provide an interesting look
|
||||
SlowAnimationToggleSwitch.OffText = "Off"; //Only to provide an interesting look
|
||||
SlowAnimationToggleSwitch.OffFont = new Font(DemoTabControl.Font.FontFamily, 10, FontStyle.Bold); //Only to provide an interesting look
|
||||
SlowAnimationToggleSwitch.OffForeColor = Color.White; //Only to provide an interesting look
|
||||
SlowAnimationToggleSwitch.UseAnimation = true; //Default
|
||||
SlowAnimationToggleSwitch.AnimationInterval = 10;
|
||||
SlowAnimationToggleSwitch.AnimationStep = 1;
|
||||
|
||||
//GrayWhenDisabled example:
|
||||
|
||||
GrayWhenDisabledToggleSwitch1.Style = JCS.ToggleSwitch.ToggleSwitchStyle.Fancy; //Only to provide an interesting look
|
||||
GrayWhenDisabledToggleSwitch1.Size = new Size(100, 30); //Only to provide an interesting look
|
||||
GrayWhenDisabledToggleSwitch1.OnText = "ON"; //Only to provide an interesting look
|
||||
GrayWhenDisabledToggleSwitch1.OnFont = new Font(DemoTabControl.Font.FontFamily, 10, FontStyle.Bold); //Only to provide an interesting look
|
||||
GrayWhenDisabledToggleSwitch1.OnForeColor = Color.White; //Only to provide an interesting look
|
||||
GrayWhenDisabledToggleSwitch1.OffText = "OFF"; //Only to provide an interesting look
|
||||
GrayWhenDisabledToggleSwitch1.OffFont = new Font(DemoTabControl.Font.FontFamily, 10, FontStyle.Bold); //Only to provide an interesting look
|
||||
GrayWhenDisabledToggleSwitch1.OffForeColor = Color.White; //Only to provide an interesting look
|
||||
GrayWhenDisabledToggleSwitch1.ButtonImage = Resources.arrowright; //Only to provide an interesting look
|
||||
GrayWhenDisabledToggleSwitch1.GrayWhenDisabled = false;
|
||||
|
||||
GrayWhenDisabledToggleSwitch2.Style = JCS.ToggleSwitch.ToggleSwitchStyle.Fancy; //Only to provide an interesting look
|
||||
GrayWhenDisabledToggleSwitch2.Size = new Size(100, 30); //Only to provide an interesting look
|
||||
GrayWhenDisabledToggleSwitch2.OnText = "ON"; //Only to provide an interesting look
|
||||
GrayWhenDisabledToggleSwitch2.OnFont = new Font(DemoTabControl.Font.FontFamily, 10, FontStyle.Bold); //Only to provide an interesting look
|
||||
GrayWhenDisabledToggleSwitch2.OnForeColor = Color.White; //Only to provide an interesting look
|
||||
GrayWhenDisabledToggleSwitch2.OffText = "OFF"; //Only to provide an interesting look
|
||||
GrayWhenDisabledToggleSwitch2.OffFont = new Font(DemoTabControl.Font.FontFamily, 10, FontStyle.Bold); //Only to provide an interesting look
|
||||
GrayWhenDisabledToggleSwitch2.OffForeColor = Color.White; //Only to provide an interesting look
|
||||
GrayWhenDisabledToggleSwitch2.ButtonImage = Resources.arrowright; //Only to provide an interesting look
|
||||
GrayWhenDisabledToggleSwitch2.GrayWhenDisabled = true; //Default
|
||||
|
||||
//ThresholdPercentage example:
|
||||
|
||||
ThresholdPercentageToggleSwitch.Style = JCS.ToggleSwitch.ToggleSwitchStyle.IOS5; //Only to provide an interesting look
|
||||
ThresholdPercentageToggleSwitch.Size = new Size(98, 42); //Only to provide an interesting look
|
||||
ThresholdPercentageToggleSwitch.OnText = "ON"; //Only to provide an interesting look
|
||||
ThresholdPercentageToggleSwitch.OnFont = new Font(DemoTabControl.Font.FontFamily, 12, FontStyle.Bold); //Only to provide an interesting look
|
||||
ThresholdPercentageToggleSwitch.OnForeColor = Color.White; //Only to provide an interesting look
|
||||
ThresholdPercentageToggleSwitch.OffText = "OFF"; //Only to provide an interesting look
|
||||
ThresholdPercentageToggleSwitch.OffFont = new Font(DemoTabControl.Font.FontFamily, 12, FontStyle.Bold); //Only to provide an interesting look
|
||||
ThresholdPercentageToggleSwitch.OffForeColor = Color.FromArgb(141, 123, 141); //Only to provide an interesting look
|
||||
ThresholdPercentageToggleSwitch.ThresholdPercentage = 50; //Default
|
||||
|
||||
//ToggleOnButtonClick & ToggleOnSideClick example:
|
||||
|
||||
ToggleOnClickToggleSwitch.Style = JCS.ToggleSwitch.ToggleSwitchStyle.BrushedMetal; //Only to provide an interesting look
|
||||
ToggleOnClickToggleSwitch.Size = new Size(93, 30); //Only to provide an interesting look
|
||||
ToggleOnClickToggleSwitch.OnText = "ON"; //Only to provide an interesting look
|
||||
ToggleOnClickToggleSwitch.OnFont = new Font(DemoTabControl.Font.FontFamily, 10, FontStyle.Bold); //Only to provide an interesting look
|
||||
ToggleOnClickToggleSwitch.OnForeColor = Color.White; //Only to provide an interesting look
|
||||
ToggleOnClickToggleSwitch.OffText = "OFF"; //Only to provide an interesting look
|
||||
ToggleOnClickToggleSwitch.OffFont = new Font(DemoTabControl.Font.FontFamily, 10, FontStyle.Bold); //Only to provide an interesting look
|
||||
ToggleOnClickToggleSwitch.OffForeColor = Color.White; //Only to provide an interesting look
|
||||
ToggleOnClickToggleSwitch.ToggleOnButtonClick = true; //Default
|
||||
ToggleOnClickToggleSwitch.ToggleOnSideClick = true; //Default
|
||||
}
|
||||
|
||||
public void SetPropertiesForCustomizationsTabSwitches()
|
||||
{
|
||||
//Set the properties for the ToggleSwitches on the "Special Customizations" tab
|
||||
|
||||
//Color customization example, Metro Style ToggleSwitch:
|
||||
|
||||
NormalMetroToggleSwitch.Style = JCS.ToggleSwitch.ToggleSwitchStyle.Metro; //Default
|
||||
NormalMetroToggleSwitch.Size = new Size(75, 23);
|
||||
|
||||
ToggleSwitchMetroRenderer customizedMetroRenderer = new ToggleSwitchMetroRenderer();
|
||||
customizedMetroRenderer.LeftSideColor = Color.Red;
|
||||
customizedMetroRenderer.LeftSideColorHovered = Color.FromArgb(210, 0, 0);
|
||||
customizedMetroRenderer.LeftSideColorPressed = Color.FromArgb(190, 0, 0);
|
||||
customizedMetroRenderer.RightSideColor = Color.Yellow;
|
||||
customizedMetroRenderer.RightSideColorHovered = Color.FromArgb(245, 245, 0);
|
||||
customizedMetroRenderer.RightSideColorPressed = Color.FromArgb(235, 235, 0);
|
||||
|
||||
CustomizedMetroToggleSwitch.Style = JCS.ToggleSwitch.ToggleSwitchStyle.Metro; //Default
|
||||
CustomizedMetroToggleSwitch.Size = new Size(75, 23);
|
||||
CustomizedMetroToggleSwitch.SetRenderer(customizedMetroRenderer);
|
||||
|
||||
//Color customization example, IOS5 Style ToggleSwitch:
|
||||
|
||||
NormalIOS5ToggleSwitch.Style = JCS.ToggleSwitch.ToggleSwitchStyle.IOS5;
|
||||
NormalIOS5ToggleSwitch.Size = new Size(98, 42);
|
||||
NormalIOS5ToggleSwitch.OnText = "ON";
|
||||
NormalIOS5ToggleSwitch.OnFont = new Font(DemoTabControl.Font.FontFamily, 12, FontStyle.Bold);
|
||||
NormalIOS5ToggleSwitch.OnForeColor = Color.White;
|
||||
NormalIOS5ToggleSwitch.OffText = "OFF";
|
||||
NormalIOS5ToggleSwitch.OffFont = new Font(DemoTabControl.Font.FontFamily, 12, FontStyle.Bold);
|
||||
NormalIOS5ToggleSwitch.OffForeColor = Color.FromArgb(141, 123, 141);
|
||||
|
||||
//Maybe not the prettiest color scheme in the world - It's just for demonstration :-)
|
||||
ToggleSwitchIOS5Renderer customizedIos5Renderer = new ToggleSwitchIOS5Renderer();
|
||||
customizedIos5Renderer.LeftSideUpperColor1 = Color.FromArgb(128, 0, 64);
|
||||
customizedIos5Renderer.LeftSideUpperColor2 = Color.FromArgb(180, 0, 90);
|
||||
customizedIos5Renderer.LeftSideLowerColor1 = Color.FromArgb(250, 0, 125);
|
||||
customizedIos5Renderer.LeftSideLowerColor2 = Color.FromArgb(255, 120, 190);
|
||||
customizedIos5Renderer.RightSideUpperColor1 = Color.FromArgb(0, 64, 128);
|
||||
customizedIos5Renderer.RightSideUpperColor2 = Color.FromArgb(0, 90, 180);
|
||||
customizedIos5Renderer.RightSideLowerColor1 = Color.FromArgb(0, 125, 250);
|
||||
customizedIos5Renderer.RightSideLowerColor2 = Color.FromArgb(120, 190, 255);
|
||||
customizedIos5Renderer.ButtonNormalOuterBorderColor = Color.Green;
|
||||
customizedIos5Renderer.ButtonNormalInnerBorderColor = Color.Green;
|
||||
customizedIos5Renderer.ButtonNormalSurfaceColor1 = Color.Red;
|
||||
customizedIos5Renderer.ButtonNormalSurfaceColor2 = Color.Red;
|
||||
customizedIos5Renderer.ButtonHoverOuterBorderColor = Color.Green;
|
||||
customizedIos5Renderer.ButtonHoverInnerBorderColor = Color.Green;
|
||||
customizedIos5Renderer.ButtonHoverSurfaceColor1 = Color.Red;
|
||||
customizedIos5Renderer.ButtonHoverSurfaceColor2 = Color.Red;
|
||||
customizedIos5Renderer.ButtonPressedOuterBorderColor = Color.Green;
|
||||
customizedIos5Renderer.ButtonPressedInnerBorderColor = Color.Green;
|
||||
customizedIos5Renderer.ButtonPressedSurfaceColor1 = Color.Red;
|
||||
customizedIos5Renderer.ButtonPressedSurfaceColor2 = Color.Red;
|
||||
|
||||
CustomizedIOS5ToggleSwitch.Style = JCS.ToggleSwitch.ToggleSwitchStyle.IOS5;
|
||||
CustomizedIOS5ToggleSwitch.Size = new Size(98, 42);
|
||||
CustomizedIOS5ToggleSwitch.OnText = "ON";
|
||||
CustomizedIOS5ToggleSwitch.OnFont = new Font(DemoTabControl.Font.FontFamily, 12, FontStyle.Bold);
|
||||
CustomizedIOS5ToggleSwitch.OnForeColor = Color.White;
|
||||
CustomizedIOS5ToggleSwitch.OffText = "OFF";
|
||||
CustomizedIOS5ToggleSwitch.OffFont = new Font(DemoTabControl.Font.FontFamily, 12, FontStyle.Bold);
|
||||
CustomizedIOS5ToggleSwitch.OffForeColor = Color.White; //OBS: Need to change this for text visibility
|
||||
CustomizedIOS5ToggleSwitch.SetRenderer(customizedIos5Renderer);
|
||||
|
||||
//Color customization example using RendererChanged event
|
||||
|
||||
NormalPlainAndSimpleToggleSwitch.Style = JCS.ToggleSwitch.ToggleSwitchStyle.PlainAndSimpel;
|
||||
NormalPlainAndSimpleToggleSwitch.Size = new Size(44, 22);
|
||||
|
||||
CustomizedPlainAndSimpleToggleSwitch.Style = JCS.ToggleSwitch.ToggleSwitchStyle.PlainAndSimpel;
|
||||
CustomizedPlainAndSimpleToggleSwitch.Size = new Size(44, 22);
|
||||
CustomizedPlainAndSimpleToggleSwitch.BeforeRendering += CustomizedPlainAndSimpleToggleSwitch_BeforeRendering;
|
||||
|
||||
//Image customization example, Fancy Style ToggleSwitch:
|
||||
|
||||
NormalFancyToggleSwitch.Style = JCS.ToggleSwitch.ToggleSwitchStyle.Fancy;
|
||||
NormalFancyToggleSwitch.Size = new Size(100, 30);
|
||||
NormalFancyToggleSwitch.OnText = "ON";
|
||||
NormalFancyToggleSwitch.OnFont = new Font(DemoTabControl.Font.FontFamily, 10, FontStyle.Bold);
|
||||
NormalFancyToggleSwitch.OnForeColor = Color.White;
|
||||
NormalFancyToggleSwitch.OffText = "OFF";
|
||||
NormalFancyToggleSwitch.OffFont = new Font(DemoTabControl.Font.FontFamily, 10, FontStyle.Bold);
|
||||
NormalFancyToggleSwitch.OffForeColor = Color.White;
|
||||
|
||||
CustomizedFancyToggleSwitch.Style = JCS.ToggleSwitch.ToggleSwitchStyle.Fancy;
|
||||
CustomizedFancyToggleSwitch.Size = new Size(100, 30);
|
||||
CustomizedFancyToggleSwitch.OffButtonImage = Resources.arrowright;
|
||||
CustomizedFancyToggleSwitch.OffSideImage = Resources.cross;
|
||||
CustomizedFancyToggleSwitch.OnButtonImage = Resources.arrowleft;
|
||||
CustomizedFancyToggleSwitch.OnSideImage = Resources.check;
|
||||
|
||||
//Advanced behavior example, Fancy Style ToggleSwitch:
|
||||
|
||||
Color tempColor;
|
||||
|
||||
ToggleSwitchFancyRenderer customizedFancyRenderer = new ToggleSwitchFancyRenderer();
|
||||
tempColor = customizedFancyRenderer.LeftSideBackColor1;
|
||||
customizedFancyRenderer.LeftSideBackColor1 = customizedFancyRenderer.RightSideBackColor1;
|
||||
customizedFancyRenderer.RightSideBackColor1 = tempColor;
|
||||
tempColor = customizedFancyRenderer.LeftSideBackColor2;
|
||||
customizedFancyRenderer.LeftSideBackColor2 = customizedFancyRenderer.RightSideBackColor2;
|
||||
customizedFancyRenderer.RightSideBackColor2 = tempColor;
|
||||
|
||||
AdvancedBehaviorFancyToggleSwitch.Style = JCS.ToggleSwitch.ToggleSwitchStyle.Fancy;
|
||||
AdvancedBehaviorFancyToggleSwitch.Size = new Size(150, 30);
|
||||
AdvancedBehaviorFancyToggleSwitch.OnText = "Restart";
|
||||
AdvancedBehaviorFancyToggleSwitch.OnFont = new Font(DemoTabControl.Font.FontFamily, 10, FontStyle.Bold);
|
||||
AdvancedBehaviorFancyToggleSwitch.OnForeColor = Color.White;
|
||||
AdvancedBehaviorFancyToggleSwitch.OffText = "Online";
|
||||
AdvancedBehaviorFancyToggleSwitch.OffFont = new Font(DemoTabControl.Font.FontFamily, 10, FontStyle.Bold);
|
||||
AdvancedBehaviorFancyToggleSwitch.OffForeColor = Color.White;
|
||||
AdvancedBehaviorFancyToggleSwitch.OffButtonImage = Resources.arrowright;
|
||||
AdvancedBehaviorFancyToggleSwitch.UseAnimation = false;
|
||||
AdvancedBehaviorFancyToggleSwitch.SetRenderer(customizedFancyRenderer);
|
||||
AdvancedBehaviorFancyToggleSwitch.CheckedChanged += AdvancedBehaviorFancyToggleSwitch_CheckedChanged;
|
||||
|
||||
AnimatedGifPictureBox.Parent = AdvancedBehaviorFancyToggleSwitch; //Necessary to get the ToggleSwitch button to show through the picture box' transparent background
|
||||
}
|
||||
|
||||
private void CustomizedPlainAndSimpleToggleSwitch_BeforeRendering(object sender, ToggleSwitch.BeforeRenderingEventArgs e)
|
||||
{
|
||||
if (e.Renderer is ToggleSwitchPlainAndSimpleRenderer)
|
||||
{
|
||||
ToggleSwitchPlainAndSimpleRenderer renderer = e.Renderer as ToggleSwitchPlainAndSimpleRenderer;
|
||||
|
||||
renderer.BorderColorChecked = Color.Green;
|
||||
renderer.BorderColorUnchecked = Color.Red;
|
||||
|
||||
//Observe: in the BeforeRendering event, the Checked property will not yet have changed to the final state
|
||||
if (!CustomizedPlainAndSimpleToggleSwitch.Checked)
|
||||
{
|
||||
renderer.ButtonColor = Color.DarkGray;
|
||||
renderer.InnerBackgroundColor = Color.LightGray;
|
||||
}
|
||||
else
|
||||
{
|
||||
renderer.ButtonColor = Color.DarkBlue;
|
||||
renderer.InnerBackgroundColor = Color.LightBlue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void AllowUserChangeCheckBox_CheckedChanged(object sender, System.EventArgs e)
|
||||
{
|
||||
AllowUserChangeToggleSwitch1.Checked = AllowUserChangeCheckBox.Checked;
|
||||
AllowUserChangeToggleSwitch2.Checked = AllowUserChangeCheckBox.Checked;
|
||||
}
|
||||
|
||||
private void GrayWhenDisabledCheckBox_CheckedChanged(object sender, System.EventArgs e)
|
||||
{
|
||||
GrayWhenDisabledToggleSwitch1.Enabled = GrayWhenDisabledCheckBox.Checked;
|
||||
GrayWhenDisabledToggleSwitch2.Enabled = GrayWhenDisabledCheckBox.Checked;
|
||||
}
|
||||
|
||||
private void ThresholdPercentageTrackBar_Scroll(object sender, System.EventArgs e)
|
||||
{
|
||||
label15.Text = string.Format("Value = {0} (Default = 50)", ThresholdPercentageTrackBar.Value);
|
||||
ThresholdPercentageToggleSwitch.ThresholdPercentage = ThresholdPercentageTrackBar.Value;
|
||||
}
|
||||
|
||||
private void ToggleOnButtonClickCheckBox_CheckedChanged(object sender, System.EventArgs e)
|
||||
{
|
||||
ToggleOnClickToggleSwitch.ToggleOnButtonClick = ToggleOnButtonClickCheckBox.Checked;
|
||||
}
|
||||
|
||||
private void ToggleOnSideClickCheckBox_CheckedChanged(object sender, System.EventArgs e)
|
||||
{
|
||||
ToggleOnClickToggleSwitch.ToggleOnSideClick = ToggleOnSideClickCheckBox.Checked;
|
||||
}
|
||||
|
||||
private void AdvancedBehaviorFancyToggleSwitch_CheckedChanged(object sender, System.EventArgs e)
|
||||
{
|
||||
if (AdvancedBehaviorFancyToggleSwitch.Checked)
|
||||
{
|
||||
AdvancedBehaviorFancyToggleSwitch.AllowUserChange = false;
|
||||
AdvancedBehaviorFancyToggleSwitch.OnText = "Restarting...";
|
||||
|
||||
PositionAniGifPictureBox();
|
||||
AnimatedGifPictureBox.Visible = true;
|
||||
|
||||
if (!SimulateRestartBackgroundWorker.IsBusy)
|
||||
SimulateRestartBackgroundWorker.RunWorkerAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
AdvancedBehaviorFancyToggleSwitch.AllowUserChange = true;
|
||||
AdvancedBehaviorFancyToggleSwitch.OnText = "Restart";
|
||||
}
|
||||
}
|
||||
|
||||
private void PositionAniGifPictureBox()
|
||||
{
|
||||
//Position anigif picturebox
|
||||
|
||||
Rectangle buttonRectangle = AdvancedBehaviorFancyToggleSwitch.ButtonRectangle;
|
||||
|
||||
AnimatedGifPictureBox.Height = buttonRectangle.Height - 2;
|
||||
AnimatedGifPictureBox.Width = AnimatedGifPictureBox.Height;
|
||||
AnimatedGifPictureBox.Left = buttonRectangle.X + ((buttonRectangle.Width - AnimatedGifPictureBox.Width) / 2);
|
||||
AnimatedGifPictureBox.Top = buttonRectangle.Y + ((buttonRectangle.Height - AnimatedGifPictureBox.Height) / 2);
|
||||
}
|
||||
|
||||
private void SimulateRestartBackgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
|
||||
{
|
||||
//Simulate restart delay
|
||||
Thread.Sleep(1500);
|
||||
}
|
||||
|
||||
private void SimulateRestartBackgroundWorker_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
|
||||
{
|
||||
AnimatedGifPictureBox.Visible = false;
|
||||
AdvancedBehaviorFancyToggleSwitch.Checked = false;
|
||||
}
|
||||
}
|
||||
}
|
1880
ToggleSwitchDemo/DemoForm.resx
Normal file
19
ToggleSwitchDemo/Program.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ToggleSwitchDemo
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new DemoForm());
|
||||
}
|
||||
}
|
||||
}
|
36
ToggleSwitchDemo/Properties/AssemblyInfo.cs
Normal file
|
@ -0,0 +1,36 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("ToggleSwitchDemo")]
|
||||
[assembly: AssemblyDescription("JCS ToggleSwitch Demo Application")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("JC Software Solutions")]
|
||||
[assembly: AssemblyProduct("JCS ToggleSwitch")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2015")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("6fd40b22-0c51-4557-af5c-879774fec629")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
113
ToggleSwitchDemo/Properties/Resources.Designer.cs
generated
Normal file
|
@ -0,0 +1,113 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.34209
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace ToggleSwitchDemo.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ToggleSwitchDemo.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap arrowleft {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("arrowleft", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap arrowright {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("arrowright", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap check {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("check", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap cross {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("cross", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
internal static System.Drawing.Bitmap handle {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("handle", resourceCulture);
|
||||
return ((System.Drawing.Bitmap)(obj));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
136
ToggleSwitchDemo/Properties/Resources.resx
Normal file
|
@ -0,0 +1,136 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="arrowleft" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\arrowleft.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="arrowright" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\Image70.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="check" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\check.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="cross" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\cross.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
<data name="handle" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\handle.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||
</data>
|
||||
</root>
|
30
ToggleSwitchDemo/Properties/Settings.Designer.cs
generated
Normal file
|
@ -0,0 +1,30 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.34209
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace ToggleSwitchDemo.Properties
|
||||
{
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
|
||||
{
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
public static Settings Default
|
||||
{
|
||||
get
|
||||
{
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
7
ToggleSwitchDemo/Properties/Settings.settings
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
|
||||
<Profiles>
|
||||
<Profile Name="(Default)" />
|
||||
</Profiles>
|
||||
<Settings />
|
||||
</SettingsFile>
|
BIN
ToggleSwitchDemo/Resources/Image70.png
Normal file
After Width: | Height: | Size: 322 B |
BIN
ToggleSwitchDemo/Resources/arrowleft.png
Normal file
After Width: | Height: | Size: 326 B |
BIN
ToggleSwitchDemo/Resources/check.png
Normal file
After Width: | Height: | Size: 407 B |
BIN
ToggleSwitchDemo/Resources/cross.png
Normal file
After Width: | Height: | Size: 467 B |
BIN
ToggleSwitchDemo/Resources/handle.png
Normal file
After Width: | Height: | Size: 315 B |
107
ToggleSwitchDemo/ToggleSwitchDemo.csproj
Normal file
|
@ -0,0 +1,107 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{2F7ADBD8-EC70-4407-8B09-474E8F2043AC}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>ToggleSwitchDemo</RootNamespace>
|
||||
<AssemblyName>ToggleSwitchDemo</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Deployment" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DemoForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="DemoForm.Designer.cs">
|
||||
<DependentUpon>DemoForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<EmbeddedResource Include="DemoForm.resx">
|
||||
<DependentUpon>DemoForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
<DesignTime>True</DesignTime>
|
||||
</Compile>
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Resources\Image70.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ToggleSwitch\ToggleSwitch.csproj">
|
||||
<Project>{49b88ffa-f02c-4709-ba65-9f8996444ecd}</Project>
|
||||
<Name>ToggleSwitch</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Resources\handle.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Resources\arrowleft.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Resources\check.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Resources\cross.png" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
|
@ -0,0 +1,4 @@
|
|||
// <autogenerated />
|
||||
using System;
|
||||
using System.Reflection;
|
||||
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.0", FrameworkDisplayName = ".NET Framework 4")]
|
BIN
ToggleSwitchDemo/obj/Debug/ToggleSwitchDemo.DemoForm.resources
Normal file
|
@ -0,0 +1 @@
|
|||
a3b23e74090a80e3128188f6cf3a320fb2c4b627
|
|
@ -0,0 +1,25 @@
|
|||
C:\Users\Johnny\Documents\_Visual Studio Projects\ToggleSwitch\ToggleSwitchDemo\bin\Debug\ToggleSwitchDemo.exe
|
||||
C:\Users\Johnny\Documents\_Visual Studio Projects\ToggleSwitch\ToggleSwitchDemo\bin\Debug\ToggleSwitchDemo.pdb
|
||||
C:\Users\Johnny\Documents\_Visual Studio Projects\ToggleSwitch\ToggleSwitchDemo\bin\Debug\ToggleSwitch.dll
|
||||
C:\Users\Johnny\Documents\_Visual Studio Projects\ToggleSwitch\ToggleSwitchDemo\bin\Debug\ToggleSwitch.pdb
|
||||
C:\Users\Johnny\Documents\_Visual Studio Projects\ToggleSwitch\ToggleSwitchDemo\obj\Debug\ToggleSwitchDemo.csprojResolveAssemblyReference.cache
|
||||
C:\Users\Johnny\Documents\_Visual Studio Projects\ToggleSwitch\ToggleSwitchDemo\obj\Debug\ToggleSwitchDemo.DemoForm.resources
|
||||
C:\Users\Johnny\Documents\_Visual Studio Projects\ToggleSwitch\ToggleSwitchDemo\obj\Debug\ToggleSwitchDemo.Properties.Resources.resources
|
||||
C:\Users\Johnny\Documents\_Visual Studio Projects\ToggleSwitch\ToggleSwitchDemo\obj\Debug\ToggleSwitchDemo.csproj.GenerateResource.Cache
|
||||
C:\Users\Johnny\Documents\_Visual Studio Projects\ToggleSwitch\ToggleSwitchDemo\obj\Debug\ToggleSwitchDemo.exe
|
||||
C:\Users\Johnny\Documents\_Visual Studio Projects\ToggleSwitch\ToggleSwitchDemo\obj\Debug\ToggleSwitchDemo.pdb
|
||||
D:\Projekt\CodeProject\ToggleSwitch\ToggleSwitchDemo\bin\Debug\ToggleSwitchDemo.exe
|
||||
D:\Projekt\CodeProject\ToggleSwitch\ToggleSwitchDemo\bin\Debug\ToggleSwitchDemo.pdb
|
||||
D:\Projekt\CodeProject\ToggleSwitch\ToggleSwitchDemo\bin\Debug\ToggleSwitch.dll
|
||||
D:\Projekt\CodeProject\ToggleSwitch\ToggleSwitchDemo\bin\Debug\ToggleSwitch.pdb
|
||||
D:\Projekt\CodeProject\ToggleSwitch\ToggleSwitchDemo\obj\Debug\ToggleSwitchDemo.csprojAssemblyReference.cache
|
||||
D:\Projekt\CodeProject\ToggleSwitch\ToggleSwitchDemo\obj\Debug\ToggleSwitchDemo.DemoForm.resources
|
||||
D:\Projekt\CodeProject\ToggleSwitch\ToggleSwitchDemo\obj\Debug\ToggleSwitchDemo.Properties.Resources.resources
|
||||
D:\Projekt\CodeProject\ToggleSwitch\ToggleSwitchDemo\obj\Debug\ToggleSwitchDemo.csproj.GenerateResource.cache
|
||||
D:\Projekt\CodeProject\ToggleSwitch\ToggleSwitchDemo\obj\Debug\ToggleSwitchDemo.csproj.CoreCompileInputs.cache
|
||||
D:\Projekt\CodeProject\ToggleSwitch\ToggleSwitchDemo\obj\Debug\ToggleSwitchDemo.csproj.CopyComplete
|
||||
D:\Projekt\CodeProject\ToggleSwitch\ToggleSwitchDemo\obj\Debug\ToggleSwitchDemo.exe
|
||||
D:\Projekt\CodeProject\ToggleSwitch\ToggleSwitchDemo\obj\Debug\ToggleSwitchDemo.pdb
|
||||
D:\CKMAI_Documents\Programming\GitHub\ToggleSwitch\ToggleSwitchDemo\obj\Debug\ToggleSwitchDemo.csprojAssemblyReference.cache
|
||||
D:\CKMAI_Documents\Programming\GitHub\ToggleSwitch\ToggleSwitchDemo\obj\Debug\ToggleSwitchDemo.exe
|
||||
D:\CKMAI_Documents\Programming\GitHub\ToggleSwitch\ToggleSwitchDemo\obj\Debug\ToggleSwitchDemo.pdb
|
BIN
ToggleSwitchDemo/obj/Debug/ToggleSwitchDemo.exe
Normal file
BIN
ToggleSwitchDemo/obj/Debug/ToggleSwitchDemo.pdb
Normal file
BIN
ToggleSwitchDemo/obj/Release/ToggleSwitchDemo.DemoForm.resources
Normal file
|
@ -0,0 +1 @@
|
|||
fd4dbdbc4ebb23053bb7500549871212fffaf366
|
|
@ -0,0 +1,22 @@
|
|||
C:\Users\Johnny\Documents\_Visual Studio Projects\ToggleSwitch\ToggleSwitchDemo\bin\Release\ToggleSwitchDemo.exe
|
||||
C:\Users\Johnny\Documents\_Visual Studio Projects\ToggleSwitch\ToggleSwitchDemo\bin\Release\ToggleSwitchDemo.pdb
|
||||
C:\Users\Johnny\Documents\_Visual Studio Projects\ToggleSwitch\ToggleSwitchDemo\bin\Release\ToggleSwitch.dll
|
||||
C:\Users\Johnny\Documents\_Visual Studio Projects\ToggleSwitch\ToggleSwitchDemo\bin\Release\ToggleSwitch.pdb
|
||||
C:\Users\Johnny\Documents\_Visual Studio Projects\ToggleSwitch\ToggleSwitchDemo\obj\Release\ToggleSwitchDemo.csprojResolveAssemblyReference.cache
|
||||
C:\Users\Johnny\Documents\_Visual Studio Projects\ToggleSwitch\ToggleSwitchDemo\obj\Release\ToggleSwitchDemo.DemoForm.resources
|
||||
C:\Users\Johnny\Documents\_Visual Studio Projects\ToggleSwitch\ToggleSwitchDemo\obj\Release\ToggleSwitchDemo.Properties.Resources.resources
|
||||
C:\Users\Johnny\Documents\_Visual Studio Projects\ToggleSwitch\ToggleSwitchDemo\obj\Release\ToggleSwitchDemo.csproj.GenerateResource.Cache
|
||||
C:\Users\Johnny\Documents\_Visual Studio Projects\ToggleSwitch\ToggleSwitchDemo\obj\Release\ToggleSwitchDemo.exe
|
||||
C:\Users\Johnny\Documents\_Visual Studio Projects\ToggleSwitch\ToggleSwitchDemo\obj\Release\ToggleSwitchDemo.pdb
|
||||
D:\Projekt\CodeProject\ToggleSwitch\ToggleSwitchDemo\bin\Release\ToggleSwitchDemo.exe
|
||||
D:\Projekt\CodeProject\ToggleSwitch\ToggleSwitchDemo\bin\Release\ToggleSwitchDemo.pdb
|
||||
D:\Projekt\CodeProject\ToggleSwitch\ToggleSwitchDemo\bin\Release\ToggleSwitch.dll
|
||||
D:\Projekt\CodeProject\ToggleSwitch\ToggleSwitchDemo\bin\Release\ToggleSwitch.pdb
|
||||
D:\Projekt\CodeProject\ToggleSwitch\ToggleSwitchDemo\obj\Release\ToggleSwitchDemo.csprojAssemblyReference.cache
|
||||
D:\Projekt\CodeProject\ToggleSwitch\ToggleSwitchDemo\obj\Release\ToggleSwitchDemo.DemoForm.resources
|
||||
D:\Projekt\CodeProject\ToggleSwitch\ToggleSwitchDemo\obj\Release\ToggleSwitchDemo.Properties.Resources.resources
|
||||
D:\Projekt\CodeProject\ToggleSwitch\ToggleSwitchDemo\obj\Release\ToggleSwitchDemo.csproj.GenerateResource.cache
|
||||
D:\Projekt\CodeProject\ToggleSwitch\ToggleSwitchDemo\obj\Release\ToggleSwitchDemo.csproj.CoreCompileInputs.cache
|
||||
D:\Projekt\CodeProject\ToggleSwitch\ToggleSwitchDemo\obj\Release\ToggleSwitchDemo.csproj.CopyComplete
|
||||
D:\Projekt\CodeProject\ToggleSwitch\ToggleSwitchDemo\obj\Release\ToggleSwitchDemo.exe
|
||||
D:\Projekt\CodeProject\ToggleSwitch\ToggleSwitchDemo\obj\Release\ToggleSwitchDemo.pdb
|
BIN
ToggleSwitchDemo/obj/Release/ToggleSwitchDemo.exe
Normal file
BIN
ToggleSwitchDemo/obj/Release/ToggleSwitchDemo.pdb
Normal file
BIN
arrowleft.png
Normal file
After Width: | Height: | Size: 326 B |
BIN
favicon.ico
Normal file
After Width: | Height: | Size: 6.7 KiB |
BIN
handle.png
Normal file
After Width: | Height: | Size: 315 B |
BIN
loading-circle.gif
Normal file
After Width: | Height: | Size: 6.7 KiB |