【转】WinForm窗体刻度尺
`using System;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace IntegrationAPP
{
public partial class Form2 : Form
{
public static float MonitorDPI = 96f ;
private int originLocation = 0; //坐标原地起始位置
private int maxScaleX = 1000; //X轴最大刻度
private int maxScaleY = 1000; //Y轴最大刻度
private float scaling = 1.0F; //缩放比例
private int offSetX = 0; //X轴偏移位置
private int offSetY = 0; //Y轴偏移位置
private Font font = new Font("Arial", 9); //刻度值显示字体
private TextureBrush textureBrush;
private Bitmap bit;
int x = 0;
int y = 0;
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// bit = new Bitmap((int)(MonitorDPI / 25.4 * 1 * scaling) - offSetX, (int)(MonitorDPI / 25.4 * 1 * scaling) - offSetX);
Graphics g1 = CreateGraphics();
PaintEventArgs pe = new PaintEventArgs(g1, this.ClientRectangle);
RulerControl_Paint(g1,pe );
// g1.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
// g1.Dispose();
// textureBrush = new TextureBrush(bit);//使用TextureBrush可以有效减少窗体拉伸时的闪烁
}
private void RulerControl_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
int widthInmm = maxScaleX;
int heightInmm = maxScaleY;
//绘制X轴
for (int i = 0; i <= widthInmm; i++)
{
SizeF size = g.MeasureString(Convert.ToString(i), font);
float x = originLocation + (float)(MonitorDPI / 25.4 * i * scaling) - offSetX;
if (x >= originLocation)
{
PointF start = new PointF(x, originLocation);
PointF end = new PointF(x, 3);
if (i % 5 == 0)
{
end = new PointF(x, 6);
}
if (i % 10 == 0 && i != 0)
{
end = new PointF(x, 12);
g.DrawString(Convert.ToString(i), font, Brushes.Black, new PointF(x - (float)(MonitorDPI / 25.4 * Convert.ToString(i).Length * scaling), 12));
}
g.DrawLine(Pens.Black, start, end);
}
}
g.DrawLine(Pens.Black, new PointF(originLocation, originLocation), new PointF(this.Width, originLocation));
//绘制Y轴
for (int i = 0; i <= heightInmm; i++)
{
SizeF size = g.MeasureString(Convert.ToString(i), font);
float y = originLocation + (float)(MonitorDPI / 25.4 * i * scaling) - offSetY;
if (y >= originLocation)
{
PointF start = new PointF(originLocation, y);
PointF end = new PointF(3, y);
if (i % 5 == 0)
{
end = new PointF(6, y);
}
if (i % 10 == 0 && i != 0)
{
end = new PointF(12, y);
g.DrawString(Convert.ToString(i), font, Brushes.Black, new PointF(12, y - (float)(MonitorDPI / 25.4 * Convert.ToString(i).Length * scaling)));
}
g.DrawLine(Pens.Black, start, end);
}
}
g.DrawLine(Pens.Black, new PointF(originLocation, originLocation), new PointF(originLocation, this.Height));
Pen p = new Pen(Color.Gray, 1);
p.DashStyle = DashStyle.Solid;
p.DashPattern = new float[] { 1, (float)(MonitorDPI / 25.4 * 5 * scaling) - 1 };
for (int i = 0; i <= heightInmm; i += 5)
{
g.DrawLine(p, 0, (float)(MonitorDPI / 25.4 * i * scaling), 1000, (float)(MonitorDPI / 25.4 * i * scaling));
}
}
}
}

`
【转】WinForm窗体刻度尺的更多相关文章
- winform 窗体圆角设计
网上看到的很多winform窗体圆角设计代码都比较累赘,这里分享一个少量代码就可以实现的圆角.主要运用了System.Drawing.Drawing2D. 效果图 代码如下. private void ...
- WinForm 窗体属性 窗体美化
WinForm是·Net开发平台中对Windows Form的一种称谓. Windows窗体的一些重要特点如下: 功能强大:Windows窗体可用于设计窗体和可视控件,以创建丰富的基于Windows的 ...
- winform窗体置顶
winform窗体置顶 金刚 winform 置顶 今天做了一个winform小工具.需要设置置顶功能. 网上找了下,发现百度真的很垃圾... 还是必应靠谱些. 找到一个可以链接. https://s ...
- winform窗体控件(全)
回顾跟补充下除了昨天那常用6个其他的winform窗体控件作用 1:Button:按钮 (1)AutoSize:如果是True的情况下,内容将会撑开:False的话会另起一行 (2)Enabled: ...
- C#将exe运行程序嵌入到自己的winform窗体中
以下例子是将Word打开,然后将它嵌入到winform窗体中,效果如下图:C将exe运行程序嵌入到自己的winform窗体中 - kingmax_res - iSport注意:该方法只适用于com的e ...
- Winform 窗体单例
有窗体Form1和窗体Form2,单击Form1上按钮,只弹出一个Form2. Form2里自定义一个方法,里面判断是否弹出Form2,没有时弹出Form2. public static Form2 ...
- WinForm窗体嵌入
一.在winform窗体上添加两个控件 1.容器>Panel 2.添加 SideBar.dll (下载链接:http://pan.baidu.com/s/1o6qhf9w) (1)将SideBa ...
- C#实现WinForm窗体逐渐显示效果
C#实现WinForm窗体逐渐显示效果,这个博客园里面已经有其它人已经实现了,原理很简单,就是通过定时改变窗体的透明度(从0到1,即透明度从完全透明到不透明),我这里也是按照这个思路来实现的,但是我做 ...
- .NET vs2010中使用IrisSkin2.dll轻松实现winForm窗体换肤功能
IrisSkin2.dll是一款很不错的免费皮肤控件,利用它可以轻松的实现winForm窗体换肤! 网上很多朋友说在VS2010中不能使用IrisSkin2.dll,我这里提供一个取巧的办法. Iri ...
随机推荐
- 在 Java 中 CycliBarriar 和 CountdownLatch 有什么区别?
CyclicBarrier 可以重复使用,而 CountdownLatch 不能重复使用. Java 的 concurrent 包里面的 CountDownLatch 其实可以把它看作一个计数器, 只 ...
- kafka中consumer group 是什么概念?
同样是逻辑上的概念,是Kafka实现单播和广播两种消息模型的手段.同一个topic的数据,会广播给不同的group:同一个group中的worker,只有一个worker能拿到这个数据.换句话说,对于 ...
- java-集合-realdo-集合一对多
school类: package setdone; import java.util.List; public class School { private String schoolname; pr ...
- Unsafe Rust 能做什么
在不安全的 Rust 中唯一不同的是,你可以: 对原始指针进行解引用 调用"不安全"的函数(包括 C 函数.编译器的内建指令和原始分配器. 实现"不安全"的特性 ...
- apollo规划控制视频-12basic motion planning and overview
- cpu指令如何读写硬盘
我们提到cpu的主要作用之一就是控制设备之间的数据交互.这其中自然也包括了硬盘.系统的所有数据基本都在硬盘中,所以知道怎么读写硬盘,对程序来说非常重要,所以我们先来探索下传说中的pio模式. cpu要 ...
- CSS 文本控制
one more time one more chance. 一歩重头学前端, css入门. 学习一些 CSS 文本控制的属性,防止做傻事.请大家对照下面列表检验下: 会的.不会的.似懂非懂的.笔者是 ...
- 微信小程序:自定义组件的数据传递
一.前言 如果小程序中有可复用的UI且具有一定的功能性,就可以使用自定义组件将其封装起来.下面介绍一个简单的组件和一个复杂的组件. 二.简单的组件(计数器) 1. 组件功能介绍 这个组件常见于外卖软件 ...
- 利用Docker快速部署Mysql
写在前面 我又来更新了~~~,今天内容较少,主要是利用Docker快速部署Mysql和初始化数据 利用Docker下载Mysql 简洁明了,在命令提示符中输入 docker pull mysql:8. ...
- Jedis的基本操作
jedis jedis 是 redis推荐的java客户端.通过Jedis我们可以很方便地使用java代码的方式,对redis进行操作.jedis使用起来比较简单,它的操作方法与redis命令相类似. ...