📄 form1.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Drawing2D;
namespace 圆整错误
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "Form1";
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
protected override void OnPaint( PaintEventArgs e)
{
Graphics g = e.Graphics;
g.FillRectangle(Brushes.White, this.ClientRectangle);
//整型坐标下的端点
Point p1=new Point(1, 1);
Point p2=new Point(11, 20);
//浮点坐标下的端点
PointF p3=new PointF(1, 1);
PointF p4=new PointF(11, 20);
//求以前两点为端点的直线段的中点
//整形坐标下的中点
Point pMiddle1=new Point((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2);
//浮点坐标下的中点
PointF pMiddle2=new PointF((p3.X + p4.X) / 2, (p3.Y + p4.Y) / 2);
//放大15倍显示
g.ScaleTransform(15, 15);
Pen pen1= new Pen(Color.Black);
Pen pen2= new Pen(Color.Red);
//放大后笔宽也放大了,除以放大倍数,保持原宽
pen1.Width = pen1.Width / 15;
pen2.Width = pen2.Width / 15;
//整型坐标下直接绘制整条直线段
g.DrawLine(pen1, p1, p2);
//整型坐标下用虚线分别把直线段的端点与整型坐标下得到的中点相连
pen2.DashStyle = DashStyle.Dash;
g.DrawLine(pen2, p1, pMiddle1);
g.DrawLine(pen2, pMiddle1, p2);
//右移
g.TranslateTransform(10, 0);
//浮点坐标下直接绘制整条直线段
g.DrawLine(pen1, p3, p4);
//浮点坐标下用虚线分别把直线段的端点与整型坐标下得到的中点相连
pen2.DashStyle = DashStyle.Dash;
g.DrawLine(pen2, p3, pMiddle2);
g.DrawLine(pen2, pMiddle2, p4);
pen1.Dispose();
pen2.Dispose();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -