📄 form1.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace Palette
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox tbX1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox tbY1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox tbX2;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox tbY2;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Button btLine;
private System.Windows.Forms.TextBox tbWidth;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.TextBox tbColor;
/// <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 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.tbX1 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.tbY1 = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.tbX2 = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.tbY2 = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.tbWidth = new System.Windows.Forms.TextBox();
this.btLine = new System.Windows.Forms.Button();
this.label6 = new System.Windows.Forms.Label();
this.tbColor = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// tbX1
//
this.tbX1.Location = new System.Drawing.Point(464, 64);
this.tbX1.Name = "tbX1";
this.tbX1.Size = new System.Drawing.Size(80, 21);
this.tbX1.TabIndex = 0;
this.tbX1.Text = "0";
//
// label1
//
this.label1.Location = new System.Drawing.Point(433, 68);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(24, 16);
this.label1.TabIndex = 1;
this.label1.Text = "x1:";
//
// label2
//
this.label2.Location = new System.Drawing.Point(432, 112);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(24, 16);
this.label2.TabIndex = 3;
this.label2.Text = "y1:";
//
// tbY1
//
this.tbY1.Location = new System.Drawing.Point(464, 104);
this.tbY1.Name = "tbY1";
this.tbY1.Size = new System.Drawing.Size(80, 21);
this.tbY1.TabIndex = 2;
this.tbY1.Text = "0";
//
// label3
//
this.label3.Location = new System.Drawing.Point(432, 144);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(24, 16);
this.label3.TabIndex = 5;
this.label3.Text = "x2:";
//
// tbX2
//
this.tbX2.Location = new System.Drawing.Point(464, 144);
this.tbX2.Name = "tbX2";
this.tbX2.Size = new System.Drawing.Size(80, 21);
this.tbX2.TabIndex = 4;
this.tbX2.Text = "0";
//
// label4
//
this.label4.Location = new System.Drawing.Point(432, 185);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(24, 16);
this.label4.TabIndex = 7;
this.label4.Text = "y2:";
//
// tbY2
//
this.tbY2.Location = new System.Drawing.Point(464, 181);
this.tbY2.Name = "tbY2";
this.tbY2.Size = new System.Drawing.Size(80, 21);
this.tbY2.TabIndex = 6;
this.tbY2.Text = "0";
//
// label5
//
this.label5.Location = new System.Drawing.Point(416, 223);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(48, 16);
this.label5.TabIndex = 9;
this.label5.Text = "width:";
//
// tbWidth
//
this.tbWidth.Location = new System.Drawing.Point(464, 216);
this.tbWidth.Name = "tbWidth";
this.tbWidth.Size = new System.Drawing.Size(80, 21);
this.tbWidth.TabIndex = 8;
this.tbWidth.Text = "";
//
// btLine
//
this.btLine.Location = new System.Drawing.Point(440, 320);
this.btLine.Name = "btLine";
this.btLine.Size = new System.Drawing.Size(96, 24);
this.btLine.TabIndex = 10;
this.btLine.Text = "直 线";
this.btLine.Click += new System.EventHandler(this.btLine_Click);
//
// label6
//
this.label6.Location = new System.Drawing.Point(416, 264);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(48, 16);
this.label6.TabIndex = 12;
this.label6.Text = "color:";
//
// tbColor
//
this.tbColor.Location = new System.Drawing.Point(464, 256);
this.tbColor.Name = "tbColor";
this.tbColor.Size = new System.Drawing.Size(80, 21);
this.tbColor.TabIndex = 11;
this.tbColor.Text = "";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(600, 382);
this.Controls.Add(this.label6);
this.Controls.Add(this.tbColor);
this.Controls.Add(this.btLine);
this.Controls.Add(this.label5);
this.Controls.Add(this.tbWidth);
this.Controls.Add(this.label4);
this.Controls.Add(this.tbY2);
this.Controls.Add(this.label3);
this.Controls.Add(this.tbX2);
this.Controls.Add(this.label2);
this.Controls.Add(this.tbY1);
this.Controls.Add(this.label1);
this.Controls.Add(this.tbX1);
this.Name = "Form1";
this.Text = "绘直线";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void btLine_Click(object sender, System.EventArgs e)
{
Graphics g=this.CreateGraphics();
int x1=int.Parse(tbX1.Text);
int y1=int.Parse(tbY1.Text);
int x2=int.Parse(tbX2.Text);
int y2=int.Parse(tbY2.Text);
int width = int.Parse(tbWidth.Text);
Color color=Color.FromName(tbColor.Text);
CLine cl=new CLine(x1,y1,x2,y2,color,width,g);
cl.DrawLine();
//Graphics g=this.CreateGraphics();
//Pen pen1 = new Pen(Color.Red,3);
//g.DrawLine(pen1,30,10,200,220);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -