📄 drawingutilities.cs
字号:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
namespace SimpleKMeans
{
class DrawingUtilities
{
public static void DrawRulers(Control x, Control y, Color color)
{
DrawXRuler(x,color);
DrawYRuler(y,color);
}
public static void DrawXRuler(Control c, Color color)
{
using (Graphics g = c.CreateGraphics())
{
for (int i = 0; i <= c.Width; i += 5)
{
#region 绘制横向标尺
if (i % 25 != 0 && i % 50 != 0)
{
g.DrawLine(new Pen(new SolidBrush(color), 1), new Point(i, 0), new Point(i, 4));
}
if (i % 25 == 0 && i % 50 != 0)
{
g.DrawLine(new Pen(new SolidBrush(color), 1), new Point(i, 0), new Point(i, 7));
}
if (i % 50 == 0)
{
Font font = new Font("Tahoma", 8, FontStyle.Regular);
g.DrawLine(new Pen(new SolidBrush(color), 1), new Point(i, 0), new Point(i, 9));
g.DrawString(i.ToString(), font, new SolidBrush(color), i-10, 10);
}
#endregion
}
}
}
public static void DrawYRuler(Control c, Color color)
{
using (Graphics g = c.CreateGraphics())
{
for (int i = 0; i <= c.Height; i += 5)
{
#region 绘制纵向标尺
if (i % 25 != 0 && i % 50 != 0)
{
g.DrawLine(new Pen(new SolidBrush(color), 1), new Point(0, i), new Point(4, i));
}
if (i % 25 == 0 && i % 50 != 0)
{
g.DrawLine(new Pen(new SolidBrush(color), 1), new Point(0, i), new Point(7, i));
}
if (i % 50 == 0)
{
Font font = new Font("Tahoma", 8, FontStyle.Regular);
StringFormat s = new StringFormat();
s.FormatFlags = StringFormatFlags.DirectionVertical;
s.Alignment = StringAlignment.Center;
g.DrawLine(new Pen(new SolidBrush(color), 1), new Point(0, i), new Point(9, i));
g.DrawString(i.ToString(), font, new SolidBrush(color), 10, i,s);
}
#endregion
}
}
}
public static void DrawDot(Control c, int x, int y, Color color)
{
using (Graphics g = c.CreateGraphics())
{
g.DrawEllipse(new Pen(new SolidBrush(color), 1), x + 10, y - 10, 4, 4);
}
}
public static void DrawCross(Control c, int x, int y, Color color)
{
using (Graphics g = c.CreateGraphics())
{
g.DrawLine(new Pen(new SolidBrush(color), 2), new Point(x, y), new Point(x + 6, y));
g.DrawLine(new Pen(new SolidBrush(color), 2), new Point(x, y), new Point(x - 6, y));
g.DrawLine(new Pen(new SolidBrush(color), 2), new Point(x, y), new Point(x, y + 6));
g.DrawLine(new Pen(new SolidBrush(color), 2), new Point(x, y), new Point(x, y - 6));
g.DrawEllipse(new Pen(new SolidBrush(color), 1), x - 6, y - 6, 12, 12);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -