📄 drawhelper.cs
字号:
// *****************************************************************************
//
// (c) Crownwood Consulting Limited 2002
// All rights reserved. The software and associated documentation
// supplied hereunder are the proprietary information of Crownwood Consulting
// Limited, Haxey, North Lincolnshire, England and are supplied subject to
// licence terms.
//
// Magic Version 1.7 www.dotnetmagic.com
// *****************************************************************************
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using Crownwood.Magic.Win32;
namespace Crownwood.Magic.Common
{
public class DrawHelper
{
public enum CommandState
{
Normal,
HotTrack,
Pushed
}
protected static IntPtr _halfToneBrush = IntPtr.Zero;
public static void DrawReverseString(Graphics g,
String drawText,
Font drawFont,
Rectangle drawRect,
Brush drawBrush,
StringFormat drawFormat)
{
GraphicsContainer container = g.BeginContainer();
// The text will be rotated around the origin (0,0) and so needs moving
// back into position by using a transform
g.TranslateTransform(drawRect.Left * 2 + drawRect.Width,
drawRect.Top * 2 + drawRect.Height);
// Rotate the text by 180 degress to reverse the direction
g.RotateTransform(180);
// Draw the string as normal and let then transforms do the work
g.DrawString(drawText, drawFont, drawBrush, drawRect, drawFormat);
g.EndContainer(container);
}
public static void DrawPlainRaised(Graphics g,
Rectangle boxRect,
Color baseColor)
{
using(Pen lighlight = new Pen(ControlPaint.LightLight(baseColor)),
dark = new Pen(ControlPaint.DarkDark(baseColor)))
{
g.DrawLine(lighlight, boxRect.Left, boxRect.Bottom, boxRect.Left, boxRect.Top);
g.DrawLine(lighlight, boxRect.Left, boxRect.Top, boxRect.Right, boxRect.Top);
g.DrawLine(dark, boxRect.Right, boxRect.Top, boxRect.Right, boxRect.Bottom);
g.DrawLine(dark, boxRect.Right, boxRect.Bottom, boxRect.Left, boxRect.Bottom);
}
}
public static void DrawPlainSunken(Graphics g,
Rectangle boxRect,
Color baseColor)
{
using(Pen lighlight = new Pen(ControlPaint.LightLight(baseColor)),
dark = new Pen(ControlPaint.DarkDark(baseColor)))
{
g.DrawLine(dark, boxRect.Left, boxRect.Bottom, boxRect.Left, boxRect.Top);
g.DrawLine(dark, boxRect.Left, boxRect.Top, boxRect.Right, boxRect.Top);
g.DrawLine(lighlight, boxRect.Right, boxRect.Top, boxRect.Right, boxRect.Bottom);
g.DrawLine(lighlight, boxRect.Right, boxRect.Bottom, boxRect.Left, boxRect.Bottom);
}
}
public static void DrawPlainRaisedBorder(Graphics g,
Rectangle rect,
Color lightLight,
Color baseColor,
Color dark,
Color darkDark)
{
if ((rect.Width > 2) && (rect.Height > 2))
{
using(Pen ll = new Pen(lightLight),
b = new Pen(baseColor),
d = new Pen(dark),
dd = new Pen(darkDark))
{
int left = rect.Left;
int top = rect.Top;
int right = rect.Right;
int bottom = rect.Bottom;
// Draw the top border
g.DrawLine(b, right-1, top, left, top);
g.DrawLine(ll, right-2, top+1, left+1, top+1);
g.DrawLine(b, right-3, top+2, left+2, top+2);
// Draw the left border
g.DrawLine(b, left, top, left, bottom-1);
g.DrawLine(ll, left+1, top+1, left+1, bottom-2);
g.DrawLine(b, left+2, top+2, left+2, bottom-3);
// Draw the right
g.DrawLine(dd, right-1, top+1, right-1, bottom-1);
g.DrawLine(d, right-2, top+2, right-2, bottom-2);
g.DrawLine(b, right-3, top+3, right-3, bottom-3);
// Draw the bottom
g.DrawLine(dd, right-1, bottom-1, left, bottom-1);
g.DrawLine(d, right-2, bottom-2, left+1, bottom-2);
g.DrawLine(b, right-3, bottom-3, left+2, bottom-3);
}
}
}
public static void DrawPlainRaisedBorderTopOrBottom(Graphics g,
Rectangle rect,
Color lightLight,
Color baseColor,
Color dark,
Color darkDark,
bool drawTop)
{
if ((rect.Width > 2) && (rect.Height > 2))
{
using(Pen ll = new Pen(lightLight),
b = new Pen(baseColor),
d = new Pen(dark),
dd = new Pen(darkDark))
{
int left = rect.Left;
int top = rect.Top;
int right = rect.Right;
int bottom = rect.Bottom;
if (drawTop)
{
// Draw the top border
g.DrawLine(b, right-1, top, left, top);
g.DrawLine(ll, right-1, top+1, left, top+1);
g.DrawLine(b, right-1, top+2, left, top+2);
}
else
{
// Draw the bottom
g.DrawLine(dd, right-1, bottom-1, left, bottom-1);
g.DrawLine(d, right-1, bottom-2, left, bottom-2);
g.DrawLine(b, right-1, bottom-3, left, bottom-3);
}
}
}
}
public static void DrawPlainSunkenBorder(Graphics g,
Rectangle rect,
Color lightLight,
Color baseColor,
Color dark,
Color darkDark)
{
if ((rect.Width > 2) && (rect.Height > 2))
{
using(Pen ll = new Pen(lightLight),
b = new Pen(baseColor),
d = new Pen(dark),
dd = new Pen(darkDark))
{
int left = rect.Left;
int top = rect.Top;
int right = rect.Right;
int bottom = rect.Bottom;
// Draw the top border
g.DrawLine(d, right-1, top, left, top);
g.DrawLine(dd, right-2, top+1, left+1, top+1);
g.DrawLine(b, right-3, top+2, left+2, top+2);
// Draw the left border
g.DrawLine(d, left, top, left, bottom-1);
g.DrawLine(dd, left+1, top+1, left+1, bottom-2);
g.DrawLine(b, left+2, top+2, left+2, bottom-3);
// Draw the right
g.DrawLine(ll, right-1, top+1, right-1, bottom-1);
g.DrawLine(b, right-2, top+2, right-2, bottom-2);
g.DrawLine(b, right-3, top+3, right-3, bottom-3);
// Draw the bottom
g.DrawLine(ll, right-1, bottom-1, left, bottom-1);
g.DrawLine(b, right-2, bottom-2, left+1, bottom-2);
g.DrawLine(b, right-3, bottom-3, left+2, bottom-3);
}
}
}
public static void DrawPlainSunkenBorderTopOrBottom(Graphics g,
Rectangle rect,
Color lightLight,
Color baseColor,
Color dark,
Color darkDark,
bool drawTop)
{
if ((rect.Width > 2) && (rect.Height > 2))
{
using(Pen ll = new Pen(lightLight),
b = new Pen(baseColor),
d = new Pen(dark),
dd = new Pen(darkDark))
{
int left = rect.Left;
int top = rect.Top;
int right = rect.Right;
int bottom = rect.Bottom;
if (drawTop)
{
// Draw the top border
g.DrawLine(d, right-1, top, left, top);
g.DrawLine(dd, right-1, top+1, left, top+1);
g.DrawLine(b, right-1, top+2, left, top+2);
}
else
{
// Draw the bottom
g.DrawLine(ll, right-1, bottom-1, left, bottom-1);
g.DrawLine(b, right-1, bottom-2, left, bottom-2);
g.DrawLine(b, right-1, bottom-3, left, bottom-3);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -