Commit 83a938e3 刘韬

添加项目文件。

1 个父辈 f998f143

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30104.148
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrintLabel", "PrintLabel\PrintLabel.csproj", "{B8F25ECE-DEE6-41D6-8EF0-8AFBF2577C17}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrintLabel_Test", "PrintLabel_Test\PrintLabel_Test.csproj", "{857ACBBF-F326-4AD0-AD6F-B7F7479AFE2C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B8F25ECE-DEE6-41D6-8EF0-8AFBF2577C17}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B8F25ECE-DEE6-41D6-8EF0-8AFBF2577C17}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B8F25ECE-DEE6-41D6-8EF0-8AFBF2577C17}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B8F25ECE-DEE6-41D6-8EF0-8AFBF2577C17}.Release|Any CPU.Build.0 = Release|Any CPU
{857ACBBF-F326-4AD0-AD6F-B7F7479AFE2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{857ACBBF-F326-4AD0-AD6F-B7F7479AFE2C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{857ACBBF-F326-4AD0-AD6F-B7F7479AFE2C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{857ACBBF-F326-4AD0-AD6F-B7F7479AFE2C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {98BC07CF-B6E4-4B45-AEE5-2FC4133EB666}
EndGlobalSection
EndGlobal
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace BLL
{
public static class ClassExtend
{
public static string ReplaceIC(this string msgs, string org, string dst)
{
if (string.IsNullOrEmpty(dst))
dst = "";
return Regex.Replace(msgs, org, dst, RegexOptions.IgnoreCase | RegexOptions.Multiline);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PrintLabel
{
internal static class Common
{
internal static List<Model.ClsLabel> Label;
internal static BLL.LabelPrint LabelPrint;
/// <summary>
/// 像素毫米转换的倍数
/// </summary>
internal const float MULTIPLE = 100f;
/// <summary>
/// 添加标签时初始的大小,mm
/// </summary>
internal const string LABEL_SIZE = "50,70";
/// <summary>
/// 毫米转像素
/// </summary>
/// <param name="mm"></param>
/// <returns></returns>
internal static float MMToPx(float mm)
{
return mm / 25.4f * MULTIPLE;
}
/// <summary>
/// 像素转毫米
/// </summary>
/// <param name="px"></param>
/// <returns></returns>
internal static float PxToMM(float px)
{
return px / MULTIPLE * 25.4f;
}
}
}

namespace Asa
{
partial class FormTextBox
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.btn_cancel = new System.Windows.Forms.Button();
this.btn_ok = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(92, 57);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(321, 21);
this.textBox1.TabIndex = 0;
//
// btn_cancel
//
this.btn_cancel.Location = new System.Drawing.Point(29, 136);
this.btn_cancel.Name = "btn_cancel";
this.btn_cancel.Size = new System.Drawing.Size(75, 23);
this.btn_cancel.TabIndex = 1;
this.btn_cancel.Text = "Cancel";
this.btn_cancel.UseVisualStyleBackColor = true;
this.btn_cancel.Click += new System.EventHandler(this.btn_cancel_Click);
//
// btn_ok
//
this.btn_ok.Location = new System.Drawing.Point(417, 136);
this.btn_ok.Name = "btn_ok";
this.btn_ok.Size = new System.Drawing.Size(75, 23);
this.btn_ok.TabIndex = 2;
this.btn_ok.Text = "OK";
this.btn_ok.UseVisualStyleBackColor = true;
this.btn_ok.Click += new System.EventHandler(this.btn_ok_Click);
//
// FormTextBox
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(525, 178);
this.ControlBox = false;
this.Controls.Add(this.btn_ok);
this.Controls.Add(this.btn_cancel);
this.Controls.Add(this.textBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "FormTextBox";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "FormTextBox";
this.Load += new System.EventHandler(this.FormTextBox_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button btn_cancel;
private System.Windows.Forms.Button btn_ok;
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Asa
{
public partial class FormTextBox : Form
{
public string InputText;
public FormTextBox()
{
InitializeComponent();
}
private void btn_cancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
this.Close();
}
private void btn_ok_Click(object sender, EventArgs e)
{
InputText = textBox1.Text;
DialogResult = DialogResult.OK;
this.Close();
}
private void FormTextBox_Load(object sender, EventArgs e)
{
textBox1.Text = InputText;
}
public static bool ShowInput(string title,ref string input) {
FormTextBox formTextBox = new FormTextBox();
formTextBox.TopMost = true;
formTextBox.Text = title;
formTextBox.InputText = input;
if (formTextBox.ShowDialog() == DialogResult.OK)
{
input = formTextBox.InputText;
return true;
}
else {
return false;
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file
namespace PrintLabel
{
partial class FrmLabel
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.LstLabelName = new System.Windows.Forms.ListBox();
this.BtnLabelNew = new System.Windows.Forms.Button();
this.BtnLabelDel = new System.Windows.Forms.Button();
this.BtnRename = new System.Windows.Forms.Button();
this.BtnPrintTest = new System.Windows.Forms.Button();
this.BtnSave = new System.Windows.Forms.Button();
this.BtnFieldAdd = new System.Windows.Forms.Button();
this.BtnFieldDel = new System.Windows.Forms.Button();
this.BtnFieldFont = new System.Windows.Forms.Button();
this.CboFieldType = new System.Windows.Forms.ComboBox();
this.NumX = new System.Windows.Forms.NumericUpDown();
this.NumY = new System.Windows.Forms.NumericUpDown();
this.NumW = new System.Windows.Forms.NumericUpDown();
this.NumH = new System.Windows.Forms.NumericUpDown();
this.TxtFormatText = new System.Windows.Forms.TextBox();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label_desc = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.NumX)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.NumY)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.NumW)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.NumH)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// LstLabelName
//
this.LstLabelName.FormattingEnabled = true;
this.LstLabelName.IntegralHeight = false;
this.LstLabelName.ItemHeight = 12;
this.LstLabelName.Location = new System.Drawing.Point(12, 12);
this.LstLabelName.Name = "LstLabelName";
this.LstLabelName.Size = new System.Drawing.Size(179, 90);
this.LstLabelName.TabIndex = 0;
this.LstLabelName.SelectedIndexChanged += new System.EventHandler(this.LstLabelName_SelectedIndexChanged);
//
// BtnLabelNew
//
this.BtnLabelNew.Location = new System.Drawing.Point(12, 108);
this.BtnLabelNew.Name = "BtnLabelNew";
this.BtnLabelNew.Size = new System.Drawing.Size(85, 26);
this.BtnLabelNew.TabIndex = 1;
this.BtnLabelNew.Text = "新建";
this.BtnLabelNew.UseVisualStyleBackColor = true;
this.BtnLabelNew.Click += new System.EventHandler(this.BtnLabelNew_Click);
//
// BtnLabelDel
//
this.BtnLabelDel.Location = new System.Drawing.Point(103, 108);
this.BtnLabelDel.Name = "BtnLabelDel";
this.BtnLabelDel.Size = new System.Drawing.Size(85, 26);
this.BtnLabelDel.TabIndex = 2;
this.BtnLabelDel.Text = "删除";
this.BtnLabelDel.UseVisualStyleBackColor = true;
this.BtnLabelDel.Click += new System.EventHandler(this.BtnLabelDel_Click);
//
// BtnRename
//
this.BtnRename.Location = new System.Drawing.Point(103, 140);
this.BtnRename.Name = "BtnRename";
this.BtnRename.Size = new System.Drawing.Size(85, 26);
this.BtnRename.TabIndex = 3;
this.BtnRename.Text = "重命名";
this.BtnRename.UseVisualStyleBackColor = true;
this.BtnRename.Click += new System.EventHandler(this.BtnRename_Click);
//
// BtnPrintTest
//
this.BtnPrintTest.Location = new System.Drawing.Point(12, 236);
this.BtnPrintTest.Name = "BtnPrintTest";
this.BtnPrintTest.Size = new System.Drawing.Size(166, 26);
this.BtnPrintTest.TabIndex = 4;
this.BtnPrintTest.Text = "打印测试";
this.BtnPrintTest.UseVisualStyleBackColor = true;
this.BtnPrintTest.Click += new System.EventHandler(this.BtnPrintTest_Click);
//
// BtnSave
//
this.BtnSave.Location = new System.Drawing.Point(12, 268);
this.BtnSave.Name = "BtnSave";
this.BtnSave.Size = new System.Drawing.Size(166, 26);
this.BtnSave.TabIndex = 5;
this.BtnSave.Text = "保存";
this.BtnSave.UseVisualStyleBackColor = true;
this.BtnSave.Click += new System.EventHandler(this.BtnSave_Click);
//
// BtnFieldAdd
//
this.BtnFieldAdd.Location = new System.Drawing.Point(12, 172);
this.BtnFieldAdd.Name = "BtnFieldAdd";
this.BtnFieldAdd.Size = new System.Drawing.Size(85, 26);
this.BtnFieldAdd.TabIndex = 6;
this.BtnFieldAdd.Text = "字段添加";
this.BtnFieldAdd.UseVisualStyleBackColor = true;
this.BtnFieldAdd.Click += new System.EventHandler(this.BtnFieldAdd_Click);
//
// BtnFieldDel
//
this.BtnFieldDel.Location = new System.Drawing.Point(103, 172);
this.BtnFieldDel.Name = "BtnFieldDel";
this.BtnFieldDel.Size = new System.Drawing.Size(85, 26);
this.BtnFieldDel.TabIndex = 7;
this.BtnFieldDel.Text = "字段删除";
this.BtnFieldDel.UseVisualStyleBackColor = true;
this.BtnFieldDel.Click += new System.EventHandler(this.BtnFieldDel_Click);
//
// BtnFieldFont
//
this.BtnFieldFont.Location = new System.Drawing.Point(12, 204);
this.BtnFieldFont.Name = "BtnFieldFont";
this.BtnFieldFont.Size = new System.Drawing.Size(85, 26);
this.BtnFieldFont.TabIndex = 8;
this.BtnFieldFont.Text = "字段字体";
this.BtnFieldFont.UseVisualStyleBackColor = true;
this.BtnFieldFont.Click += new System.EventHandler(this.BtnFieldFont_Click);
//
// CboFieldType
//
this.CboFieldType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.CboFieldType.Font = new System.Drawing.Font("宋体", 11F);
this.CboFieldType.FormattingEnabled = true;
this.CboFieldType.Location = new System.Drawing.Point(197, 12);
this.CboFieldType.Name = "CboFieldType";
this.CboFieldType.Size = new System.Drawing.Size(120, 23);
this.CboFieldType.TabIndex = 9;
this.CboFieldType.SelectedIndexChanged += new System.EventHandler(this.CboFieldType_SelectedIndexChanged);
//
// NumX
//
this.NumX.DecimalPlaces = 2;
this.NumX.Font = new System.Drawing.Font("宋体", 11F);
this.NumX.Location = new System.Drawing.Point(219, 41);
this.NumX.Minimum = new decimal(new int[] {
100,
0,
0,
-2147483648});
this.NumX.Name = "NumX";
this.NumX.Size = new System.Drawing.Size(98, 24);
this.NumX.TabIndex = 10;
this.NumX.ValueChanged += new System.EventHandler(this.NumX_ValueChanged);
//
// NumY
//
this.NumY.DecimalPlaces = 2;
this.NumY.Font = new System.Drawing.Font("宋体", 11F);
this.NumY.Location = new System.Drawing.Point(219, 71);
this.NumY.Minimum = new decimal(new int[] {
100,
0,
0,
-2147483648});
this.NumY.Name = "NumY";
this.NumY.Size = new System.Drawing.Size(98, 24);
this.NumY.TabIndex = 11;
this.NumY.ValueChanged += new System.EventHandler(this.NumY_ValueChanged);
//
// NumW
//
this.NumW.DecimalPlaces = 2;
this.NumW.Font = new System.Drawing.Font("宋体", 11F);
this.NumW.Location = new System.Drawing.Point(219, 101);
this.NumW.Minimum = new decimal(new int[] {
1,
0,
0,
131072});
this.NumW.Name = "NumW";
this.NumW.Size = new System.Drawing.Size(98, 24);
this.NumW.TabIndex = 12;
this.NumW.Value = new decimal(new int[] {
1,
0,
0,
131072});
this.NumW.ValueChanged += new System.EventHandler(this.NumW_ValueChanged);
//
// NumH
//
this.NumH.DecimalPlaces = 2;
this.NumH.Font = new System.Drawing.Font("宋体", 11F);
this.NumH.Location = new System.Drawing.Point(219, 131);
this.NumH.Minimum = new decimal(new int[] {
1,
0,
0,
131072});
this.NumH.Name = "NumH";
this.NumH.Size = new System.Drawing.Size(98, 24);
this.NumH.TabIndex = 13;
this.NumH.Value = new decimal(new int[] {
1,
0,
0,
131072});
this.NumH.ValueChanged += new System.EventHandler(this.NumH_ValueChanged);
//
// TxtFormatText
//
this.TxtFormatText.Location = new System.Drawing.Point(197, 161);
this.TxtFormatText.Multiline = true;
this.TxtFormatText.Name = "TxtFormatText";
this.TxtFormatText.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.TxtFormatText.Size = new System.Drawing.Size(120, 133);
this.TxtFormatText.TabIndex = 14;
this.TxtFormatText.TextChanged += new System.EventHandler(this.TxtFormatText_TextChanged);
//
// pictureBox1
//
this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.pictureBox1.Location = new System.Drawing.Point(325, 12);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(463, 426);
this.pictureBox1.TabIndex = 15;
this.pictureBox1.TabStop = false;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label1.Location = new System.Drawing.Point(197, 44);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(16, 16);
this.label1.TabIndex = 16;
this.label1.Text = "X";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label2.Location = new System.Drawing.Point(197, 74);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(16, 16);
this.label2.TabIndex = 17;
this.label2.Text = "Y";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label3.Location = new System.Drawing.Point(197, 104);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(16, 16);
this.label3.TabIndex = 18;
this.label3.Text = "W";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label4.Location = new System.Drawing.Point(197, 134);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(16, 16);
this.label4.TabIndex = 19;
this.label4.Text = "H";
//
// groupBox1
//
this.groupBox1.Controls.Add(this.label_desc);
this.groupBox1.Location = new System.Drawing.Point(12, 335);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(262, 100);
this.groupBox1.TabIndex = 20;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "字段说明";
//
// label_desc
//
this.label_desc.Dock = System.Windows.Forms.DockStyle.Fill;
this.label_desc.Location = new System.Drawing.Point(3, 17);
this.label_desc.Name = "label_desc";
this.label_desc.Size = new System.Drawing.Size(256, 80);
this.label_desc.TabIndex = 0;
this.label_desc.Text = " ";
//
// FrmLabel
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.TxtFormatText);
this.Controls.Add(this.NumH);
this.Controls.Add(this.NumW);
this.Controls.Add(this.NumY);
this.Controls.Add(this.NumX);
this.Controls.Add(this.CboFieldType);
this.Controls.Add(this.BtnFieldFont);
this.Controls.Add(this.BtnFieldDel);
this.Controls.Add(this.BtnFieldAdd);
this.Controls.Add(this.BtnSave);
this.Controls.Add(this.BtnPrintTest);
this.Controls.Add(this.BtnRename);
this.Controls.Add(this.BtnLabelDel);
this.Controls.Add(this.BtnLabelNew);
this.Controls.Add(this.LstLabelName);
this.Name = "FrmLabel";
this.Text = "标签编辑";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FrmLabel_FormClosing);
this.Load += new System.EventHandler(this.FrmLabel_Load);
((System.ComponentModel.ISupportInitialize)(this.NumX)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.NumY)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.NumW)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.NumH)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.ListBox LstLabelName;
private System.Windows.Forms.Button BtnLabelNew;
private System.Windows.Forms.Button BtnLabelDel;
private System.Windows.Forms.Button BtnRename;
private System.Windows.Forms.Button BtnPrintTest;
private System.Windows.Forms.Button BtnSave;
private System.Windows.Forms.Button BtnFieldAdd;
private System.Windows.Forms.Button BtnFieldDel;
private System.Windows.Forms.Button BtnFieldFont;
private System.Windows.Forms.ComboBox CboFieldType;
private System.Windows.Forms.NumericUpDown NumX;
private System.Windows.Forms.NumericUpDown NumY;
private System.Windows.Forms.NumericUpDown NumW;
private System.Windows.Forms.NumericUpDown NumH;
private System.Windows.Forms.TextBox TxtFormatText;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label_desc;
}
}
\ No newline at end of file
using Asa;
using Microsoft.VisualBasic;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PrintLabel
{
public partial class FrmLabel : Form
{
private bool change = false;
private bool isLabel = false;
public string desc = "";
public FrmLabel()
{
InitializeComponent();
}
private void LabelPrint_FieldSelected(PointF location, SizeF size, Model.LabelFieldType type)
{
change = true;
NumX.Enabled = true;
NumY.Enabled = true;
NumW.Value = Convert.ToDecimal(size.Width < 0.01 ? 0.01 : size.Width);
NumH.Value = Convert.ToDecimal(size.Height < 0.01 ? 0.01 : size.Height);
NumX.Value = Convert.ToDecimal(location.X);
NumY.Value = Convert.ToDecimal(location.Y);
CboFieldType.Enabled = true;
CboFieldType.Text = type.ToString();
change = false;
isLabel = false;
}
private void LabelPrint_FieldFormat(string s)
{
change = true;
TxtFormatText.Text = s;
change = false;
}
private void LabelPrint_LabelSelected(SizeF size)
{
change = true;
NumW.Value = Convert.ToDecimal(size.Width);
NumH.Value = Convert.ToDecimal(size.Height);
NumX.Value = 0;
NumY.Value = 0;
NumX.Enabled = false;
NumY.Enabled = false;
TxtFormatText.Text = "";
CboFieldType.SelectedIndex = -1;
CboFieldType.Enabled = false;
change = false;
isLabel = true;
}
private void FrmLabel_Load(object sender, EventArgs e)
{
Common.LabelPrint.FieldFormat += LabelPrint_FieldFormat;
Common.LabelPrint.FieldSelected += LabelPrint_FieldSelected;
Common.LabelPrint.LabelSelected += LabelPrint_LabelSelected;
Common.LabelPrint.LabelIndex = -1;
LstLabelName.Items.AddRange(Common.LabelPrint.GetName());
Common.LabelPrint.EditControl(pictureBox1);
CboFieldType.Items.AddRange(Common.LabelPrint.FieldType);
groupBox1.Visible = false;
if (desc != "") {
label_desc.Text = desc;
groupBox1.Visible = true;
}
}
private void FrmLabel_FormClosing(object sender, FormClosingEventArgs e)
{
Common.LabelPrint.FieldFormat -= LabelPrint_FieldFormat;
Common.LabelPrint.FieldSelected -= LabelPrint_FieldSelected;
Common.LabelPrint.LabelSelected -= LabelPrint_LabelSelected;
Common.LabelPrint.EditControl(null);
Common.LabelPrint.LabelIndex = -1;
}
private void LstLabelName_SelectedIndexChanged(object sender, EventArgs e)
{
Common.LabelPrint.LabelIndex = LstLabelName.SelectedIndex;
if (LstLabelName.SelectedIndex == -1) return;
NumW.Value = Convert.ToDecimal(Common.Label[Common.LabelPrint.LabelIndex].Size_mm.Width);
NumH.Value = Convert.ToDecimal(Common.Label[Common.LabelPrint.LabelIndex].Size_mm.Height);
NumX.Value = 0;
NumY.Value = 0;
NumX.Enabled = false;
NumY.Enabled = false;
CboFieldType.Enabled = false;
}
private void BtnLabelNew_Click(object sender, EventArgs e)
{
string name = "";
FormTextBox.ShowInput("New Label Name", ref name);
if (string.IsNullOrWhiteSpace(name)) return;
Common.LabelPrint.LabelNew(name);
LstLabelName.Items.Add(name);
LstLabelName.SelectedIndex = LstLabelName.Items.Count - 1;
}
private void BtnLabelDel_Click(object sender, EventArgs e)
{
if (LstLabelName.SelectedIndex == -1) return;
DialogResult dr = MessageBox.Show("确定要删除 " + LstLabelName.Text + " 吗?", "删除", MessageBoxButtons.YesNo);
if (dr == DialogResult.No) return;
Common.LabelPrint.LabelDel();
LstLabelName.Items.RemoveAt(LstLabelName.SelectedIndex);
if (LstLabelName.Items.Count > 0)
LstLabelName.SelectedIndex = 0;
}
private void BtnRename_Click(object sender, EventArgs e)
{
if (LstLabelName.SelectedIndex == -1) return;
string name = LstLabelName.Text;
FormTextBox.ShowInput("New Label Name", ref name);
if (string.IsNullOrWhiteSpace(name)) return;
Common.LabelPrint.LabelRename(name);
LstLabelName.Items[LstLabelName.SelectedIndex] = name;
}
private void BtnPrintTest_Click(object sender, EventArgs e)
{
if (LstLabelName.SelectedIndex == -1) return;
Common.LabelPrint.PrintTest();
}
private void BtnSave_Click(object sender, EventArgs e)
{
if (LstLabelName.SelectedIndex == -1) return;
Common.LabelPrint.Save();
MessageBox.Show("OK.", "Save", MessageBoxButtons.OK);
}
private void BtnFieldAdd_Click(object sender, EventArgs e)
{
if (LstLabelName.SelectedIndex == -1) return;
Common.LabelPrint.FieldAdd();
}
private void BtnFieldDel_Click(object sender, EventArgs e)
{
if (LstLabelName.SelectedIndex == -1) return;
Common.LabelPrint.FieldDel();
}
private void BtnFieldFont_Click(object sender, EventArgs e)
{
if (LstLabelName.SelectedIndex == -1) return;
Common.LabelPrint.SetFieldFont();
}
private void CboFieldType_SelectedIndexChanged(object sender, EventArgs e)
{
if (change) return;
Common.LabelPrint.SetFieldType(CboFieldType.SelectedIndex);
}
private void NumX_ValueChanged(object sender, EventArgs e)
{
if (change) return;
if (isLabel)
Common.LabelPrint.SetLabelSize(Convert.ToSingle(NumW.Value), Convert.ToSingle(NumH.Value));
else
Common.LabelPrint.SetFieldSize(Convert.ToSingle(NumX.Value), Convert.ToSingle(NumY.Value), Convert.ToSingle(NumW.Value), Convert.ToSingle(NumH.Value));
}
private void NumY_ValueChanged(object sender, EventArgs e)
{
if (change) return;
if (isLabel)
Common.LabelPrint.SetLabelSize(Convert.ToSingle(NumW.Value), Convert.ToSingle(NumH.Value));
else
Common.LabelPrint.SetFieldSize(Convert.ToSingle(NumX.Value), Convert.ToSingle(NumY.Value), Convert.ToSingle(NumW.Value), Convert.ToSingle(NumH.Value));
}
private void NumW_ValueChanged(object sender, EventArgs e)
{
if (change) return;
if (isLabel)
Common.LabelPrint.SetLabelSize(Convert.ToSingle(NumW.Value), Convert.ToSingle(NumH.Value));
else
Common.LabelPrint.SetFieldSize(Convert.ToSingle(NumX.Value), Convert.ToSingle(NumY.Value), Convert.ToSingle(NumW.Value), Convert.ToSingle(NumH.Value));
}
private void NumH_ValueChanged(object sender, EventArgs e)
{
if (change) return;
if (isLabel)
Common.LabelPrint.SetLabelSize(Convert.ToSingle(NumW.Value), Convert.ToSingle(NumH.Value));
else
Common.LabelPrint.SetFieldSize(Convert.ToSingle(NumX.Value), Convert.ToSingle(NumY.Value), Convert.ToSingle(NumW.Value), Convert.ToSingle(NumH.Value));
}
private void TxtFormatText_TextChanged(object sender, EventArgs e)
{
if (change) return;
Common.LabelPrint.SetFieldFormat(TxtFormatText.Text);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
using System.Xml;
using PrintLabel;
namespace BLL
{
/// <summary>
/// 标签打印
/// </summary>
internal class LabelPrint
{
private PictureBox _pic;
private XmlDocument _doc;
private XmlNode _root, _node;
public int labelIdx;
private int fieldIdx;
private bool fieldFormatShow;
private string _path;
/// <summary>
/// 标签左上角偏移量
/// </summary>
private Point offset;
/// <summary>
/// 鼠标按下时的点
/// </summary>
private Point oldPoint;
/// <summary>
/// 标签显示大小的位置,包含偏移
/// </summary>
private RectangleF labelSizeShow;
/// <summary>
/// 字段显示大小的位置,包含偏移
/// </summary>
private RectangleF fieldSizeShow;
/// <summary>
/// 矩形边缘
/// </summary>
private Model.FieldMargin fieldMargin = Model.FieldMargin.Outside;
/// <summary>
/// 字段区域的4个角的矩形大小,用于显示鼠标的不同光标
/// </summary>
private const int FIELD_MARGIN = 5;
public delegate void LabelSelectEvent(SizeF size);
public event LabelSelectEvent LabelSelected;
internal delegate void FieldSelectEvent(PointF location, SizeF size, Model.LabelFieldType type);
internal event FieldSelectEvent FieldSelected;
public delegate void FieldFormatStringEvent(string s);
public event FieldFormatStringEvent FieldFormat;
/// <summary>
/// 标签打印
/// </summary>
public LabelPrint()
{
}
/// <summary>
/// 标签的索引
/// </summary>
public int LabelIndex
{
set
{
labelIdx = value;
fieldIdx = -1;
if (_pic != null && labelIdx > -1 && labelIdx < Common.Label.Count)
{
if (value == -1)
{
offset = new Point();
}
else
{
int x = Convert.ToInt32((_pic.Width - Common.Label[labelIdx].Size_px.Width) / 2);
int y = Convert.ToInt32((_pic.Height - Common.Label[labelIdx].Size_px.Height) / 2);
offset = new Point(x, y);
}
_pic.Refresh();
}
}
get
{
return labelIdx;
}
}
/// <summary>
/// 标签名称
/// </summary>
public string LabelName
{
set
{
int n = Common.Label.FindIndex(s => s.Name == value);
if (n == -1) return;
LabelIndex = n;
}
get
{
return Common.Label[labelIdx].Name;
}
}
/// <summary>
/// 字段的索引
/// </summary>
public int FieldIndex
{
get { return fieldIdx; }
}
/// <summary>
/// 字段类型文本
/// </summary>
public string[] FieldType
{
get
{
return new string[]
{
Model.LabelFieldType.Code39.ToString(),
Model.LabelFieldType.Code93.ToString(),
Model.LabelFieldType.Code128.ToString(),
Model.LabelFieldType.DataMatrix.ToString(),
Model.LabelFieldType.QRCode.ToString(),
Model.LabelFieldType.Text.ToString(),
Model.LabelFieldType.PDF417.ToString()
};
}
}
public string PrinterName { set; get; }
public bool PrintLandscape { set; get; }
/// <summary>
/// 用于编辑的控件
/// </summary>
/// <param name="pic"></param>
public void EditControl(PictureBox pic)
{
if (pic == null)
{
if (_pic != null)
{
_pic.MouseDown -= PicEdit_MouseDown;
_pic.MouseMove -= PicEdit_MouseMove;
_pic.MouseUp -= PicEdit_MouseUp;
_pic.Paint -= PicEdit_Paint;
_pic.MouseEnter -= PicEdit_MouseEnter;
_pic.MouseLeave -= PicEdit_MouseLeave;
_pic = null;
}
}
else
{
_pic = pic;
_pic.MouseDown += PicEdit_MouseDown;
_pic.MouseMove += PicEdit_MouseMove;
_pic.MouseUp += PicEdit_MouseUp;
_pic.Paint += PicEdit_Paint;
_pic.MouseEnter += PicEdit_MouseEnter;
_pic.MouseLeave += PicEdit_MouseLeave;
}
}
/// <summary>
/// 加载文件
/// </summary>
/// <param name="path"></param>
public void Load(string path)
{
if (!path.EndsWith("\\"))
_path = path + "\\";
LabelIndex = -1; //一定要这个属性,不能是变量
_doc = new XmlDocument();
Common.Label = new List<Model.ClsLabel>();
List<string> file = new List<string>();
string[] files = System.IO.Directory.GetFiles(_path); //searchOption无法完全读取文件,设置*.xml,xmla、xmlb、xmlc都会获取
foreach (string f in files)
{
if (f.ToUpper().EndsWith(".XML"))
file.Add(f);
}
for (int i = 0; i < file.Count; i++)
{
try
{
Model.ClsLabel label = new Model.ClsLabel();
_doc.Load(file[i]);
_root = _doc.LastChild;
label.Path = file[i];
label.Name = _root.Attributes["Name"].Value;
label.SetSize(_root.Attributes["Size"].Value);
label.SetOffset(_root.Attributes["Offset"].Value);
XmlNodeList list = _root.ChildNodes;
for (int j = 0; j < list.Count; j++)
{
Model.ClsLabelField field = new Model.ClsLabelField
{
Type = (Model.LabelFieldType)Convert.ToInt32(list[j].Attributes["Type"].Value),
FormatText = list[j].Attributes["Key"].Value
};
field.SetLocationSize(list[j].Attributes["Rect"].Value);
field.SetFont(list[j].Attributes["Font"].Value);
field.SetBarQRCode(field.FormatText);
label.Field.Add(field);
}
Common.Label.Add(label);
}
catch (Exception ex)
{
}
}
}
/// <summary>
/// 保存文件
/// </summary>
public void Save()
{
if (labelIdx == -1) return;
_doc.Load(Common.Label[labelIdx].Path);
_root = _doc.LastChild;
_root.RemoveAll();
XmlAttribute att;
att = _doc.CreateAttribute("Name");
att.Value = Common.Label[labelIdx].Name;
_root.Attributes.Append(att);
att = _doc.CreateAttribute("Size");
att.Value = Common.Label[labelIdx].GetSize();
_root.Attributes.Append(att);
att = _doc.CreateAttribute("Offset");
att.Value = Common.Label[labelIdx].GetOffset();
_root.Attributes.Append(att);
foreach (Model.ClsLabelField lf in Common.Label[labelIdx].Field)
{
_node = _root.AppendChild(_doc.CreateElement("Field"));
att = _doc.CreateAttribute("Type");
att.Value = ((int)lf.Type).ToString();
_node.Attributes.Append(att);
att = _doc.CreateAttribute("Key");
att.Value = lf.FormatText;
_node.Attributes.Append(att);
att = _doc.CreateAttribute("Rect");
att.Value = lf.GetRectText();
_node.Attributes.Append(att);
att = _doc.CreateAttribute("Font");
att.Value = lf.GetFont();
_node.Attributes.Append(att);
}
_doc.Save(Common.Label[labelIdx].Path);
}
/// <summary>
/// 获取打印标签的名称
/// </summary>
/// <returns></returns>
public string[] GetName()
{
string[] name = new string[Common.Label.Count];
for (int i = 0; i < name.Length; i++)
name[i] = Common.Label[i].Name;
return name;
}
/// <summary>
/// 标签改变大小
/// </summary>
/// <param name="w"></param>
/// <param name="h"></param>
public void SetLabelSize(float w, float h)
{
if (labelIdx == -1) return;
Common.Label[labelIdx].SetSize(w, h);
if (_pic != null) _pic.Refresh();
}
/// <summary>
/// 字段改变大小
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="w"></param>
/// <param name="h"></param>
public void SetFieldSize(float x, float y, float w, float h)
{
if (fieldIdx == -1) return;
Common.Label[labelIdx].Field[fieldIdx].SetLocationSize(x, y, w, h);
if (_pic != null) _pic.Refresh();
}
/// <summary>
/// 设置字段的格式文本
/// </summary>
/// <param name="s"></param>
public void SetFieldFormat(string s)
{
if (fieldIdx == -1) return;
Common.Label[labelIdx].Field[fieldIdx].FormatText = s;
Common.Label[labelIdx].Field[fieldIdx].SetBarQRCode(s);
if (_pic != null) _pic.Refresh();
}
/// <summary>
/// 设置字段的字体
/// </summary>
public void SetFieldFont()
{
if (labelIdx == -1) return;
if (fieldIdx == -1) return;
if (Common.Label[labelIdx].Field[fieldIdx].Type == Model.LabelFieldType.Text)
{
using (FontDialog dlg = new FontDialog { ShowEffects = false, Font = Common.Label[labelIdx].Field[fieldIdx].Font })
{
if (dlg.ShowDialog() != DialogResult.OK) return;
Common.Label[labelIdx].Field[fieldIdx].Font = dlg.Font;
}
_pic.Refresh();
}
}
/// <summary>
/// 设置字段的类型
/// </summary>
/// <param name="n"></param>
public void SetFieldType(int n)
{
if (labelIdx == -1) return;
if (fieldIdx == -1) return;
Common.Label[labelIdx].Field[fieldIdx].Type = (Model.LabelFieldType)n;
Common.Label[labelIdx].Field[fieldIdx].SetBarQRCode();
if (_pic != null) _pic.Refresh();
}
/// <summary>
/// 添加字段
/// </summary>
public void FieldAdd()
{
if (labelIdx == -1) return;
Model.ClsLabelField field = new Model.ClsLabelField
{
Type = Model.LabelFieldType.Text,
FormatText = ""
};
field.SetLocationSize(0, 0, 10, 5);
Common.Label[labelIdx].Field.Add(field);
fieldIdx = Common.Label[labelIdx].Field.Count - 1;
_pic.Refresh();
}
/// <summary>
/// 删除字段
/// </summary>
public void FieldDel()
{
if (labelIdx == -1) return;
if (fieldIdx == -1) return;
Common.Label[labelIdx].Field.RemoveAt(fieldIdx);
fieldIdx = -1;
_pic.Refresh();
LabelSelected?.Invoke(Common.Label[labelIdx].Size_mm);
}
/// <summary>
/// 新建标签
/// </summary>
/// <param name="name"></param>
public void LabelNew(string name)
{
string path = _path + string.Format("{0:yyyyMMddHHmmss}.xml", DateTime.Now);
_doc = new XmlDocument();
_doc.AppendChild(_doc.CreateXmlDeclaration("1.0", System.Text.Encoding.UTF8.BodyName, null));
XmlElement root = _doc.CreateElement("Label");
_doc.AppendChild(root);
root.SetAttribute("Name", name);
root.SetAttribute("Size", Common.LABEL_SIZE);
root.SetAttribute("Offset", "0,0");
_doc.Save(path);
Model.ClsLabel label = new Model.ClsLabel
{
Path = path,
Name = name
};
label.SetSize(Common.LABEL_SIZE);
label.SetOffset("0,0");
Common.Label.Add(label);
}
/// <summary>
/// 删除标签
/// </summary>
public void LabelDel()
{
if (labelIdx == -1) return;
if (System.IO.File.Exists(Common.Label[labelIdx].Path))
System.IO.File.Delete(Common.Label[labelIdx].Path);
Common.Label.RemoveAt(labelIdx);
labelIdx = -1;
}
/// <summary>
/// 重命名标签
/// </summary>
/// <param name="name"></param>
public void LabelRename(string name)
{
if (labelIdx == -1) return;
Common.Label[labelIdx].Name = name;
_doc.Save(Common.Label[labelIdx].Path);
}
/// <summary>
/// 打印测试
/// </summary>
public void PrintTest()
{
if (labelIdx == -1) return;
using (PrintDialog dlg = new PrintDialog())
{
if (dlg.ShowDialog() != DialogResult.OK) return;
System.Drawing.Printing.PrintDocument print = new System.Drawing.Printing.PrintDocument { PrinterSettings = dlg.PrinterSettings };
print.PrintPage += PrintTest_PrintPage;
print.DefaultPageSettings.Landscape = dlg.PrinterSettings.DefaultPageSettings.Landscape;
print.Print();
print.Dispose();
}
}
/// <summary>
/// 打印预览
/// </summary>
/// <param name="text"></param>
/// <param name="codeContent"></param>
/// <returns></returns>
public Bitmap PrintPreview(Dictionary<string, string> text, out string[] codeContent)
{
codeContent = null;
if (labelIdx == -1) return null;
List<string> content = new List<string>();
for (int i = 0; i < Common.Label[labelIdx].Field.Count; i++)
{
Model.ClsLabelField field = Common.Label[labelIdx].Field[i];
field.PrintText = field.FormatText;
string[] keys = StrGetKey(field.FormatText);
for (int j = 0; j < keys.Length; j++)
{
if (text.ContainsKey(keys[j].ToLower()))
field.PrintText = field.PrintText.ReplaceIC("{" + keys[j] + "}", text[keys[j].ToLower()]);
}
if (field.Type != Model.LabelFieldType.Text)
{
field.SetBarQRCode(field.PrintText);
content.Add(field.PrintText);
}
}
codeContent = content.ToArray();
Bitmap bmp = new Bitmap((int)Common.Label[labelIdx].Size_px.Width, (int)Common.Label[labelIdx].Size_px.Height);
Graphics g = Graphics.FromImage(bmp);
g.Clear(Color.White);
for (int i = 0; i < Common.Label[labelIdx].Field.Count; i++)
{
Model.ClsLabelField field = Common.Label[labelIdx].Field[i];
if (field.Type == Model.LabelFieldType.Text)
{
g.DrawString(field.PrintText, field.Font, Brushes.Black, field.GetRectangleF());
}
else
{
if (field.Image != null)
g.DrawImage(field.Image, field.GetRectangleF());
}
}
g.Save();
return bmp;
}
public bool Rotate180 = false;
public Bitmap PrintLast(Dictionary<string, string> text, out string[] codeContent)
{
codeContent = null;
Bitmap bmp = PrintPreview(text, out string[] code);
if (bmp == null) return null;
if (Rotate180)
bmp.RotateFlip(RotateFlipType.Rotate180FlipNone);
codeContent = code;
System.Drawing.Printing.PrintDocument print = new System.Drawing.Printing.PrintDocument();
print.PrinterSettings.PrinterName = PrinterName;
print.DefaultPageSettings.Landscape = PrintLandscape;
print.PrintPage += PrintLast_PrintPage;
print.Print();
//print.Dispose();
return bmp;
}
private string StrRemoveKey(string s)
{
string rtn = "";
bool into = false;
for (int i = 0; i < s.Length; i++)
{
if (s[i] == '{')
into = true;
else if (s[i] == '}')
into = false;
else if (!into)
rtn += s[i];
}
return rtn;
}
/// <summary>
/// 寻找矩形边缘,用于调整大小
/// </summary>
/// <param name="rect"></param>
/// <param name="x"></param>
/// <param name="y"></param>
private void FindRectMargin(RectangleF rect, int x, int y)
{
fieldMargin = Model.FieldMargin.Outside;
if (Math.Abs(rect.X - x) < FIELD_MARGIN)
{
if (Math.Abs(rect.Y - y) < FIELD_MARGIN)
fieldMargin = Model.FieldMargin.LeftTop;
else if (Math.Abs(y - rect.Y - rect.Height) < FIELD_MARGIN)
fieldMargin = Model.FieldMargin.LeftBottom;
else if (y > rect.Y && y < rect.Y + rect.Height)
fieldMargin = Model.FieldMargin.Left;
}
else if (Math.Abs(rect.X + rect.Width - x) < FIELD_MARGIN)
{
if (Math.Abs(rect.Y - y) < FIELD_MARGIN)
fieldMargin = Model.FieldMargin.RightTop;
else if (Math.Abs(y - rect.Y - rect.Height) < FIELD_MARGIN)
fieldMargin = Model.FieldMargin.RightBottom;
else if (y > rect.Y && y < rect.Y + rect.Height)
fieldMargin = Model.FieldMargin.Right;
}
else if (x > rect.X && x < rect.X + rect.Width)
{
if (Math.Abs(rect.Y - y) < FIELD_MARGIN)
fieldMargin = Model.FieldMargin.Top;
else if (Math.Abs(y - rect.Y - rect.Height) < FIELD_MARGIN)
fieldMargin = Model.FieldMargin.Bottom;
else if (y > rect.Y && y < rect.Y + rect.Height)
fieldMargin = Model.FieldMargin.Inside;
}
if (_pic == null) return;
switch (fieldMargin)
{
case Model.FieldMargin.Left: _pic.Cursor = Cursors.SizeWE; break;
case Model.FieldMargin.LeftTop: _pic.Cursor = Cursors.SizeNWSE; break;
case Model.FieldMargin.LeftBottom: _pic.Cursor = Cursors.SizeNESW; break;
case Model.FieldMargin.Right: _pic.Cursor = Cursors.SizeWE; break;
case Model.FieldMargin.RightBottom: _pic.Cursor = Cursors.SizeNWSE; break;
case Model.FieldMargin.RightTop: _pic.Cursor = Cursors.SizeNESW; break;
case Model.FieldMargin.Top: _pic.Cursor = Cursors.SizeNS; break;
case Model.FieldMargin.Bottom: _pic.Cursor = Cursors.SizeNS; break;
case Model.FieldMargin.Inside: _pic.Cursor = Cursors.SizeAll; break;
case Model.FieldMargin.Outside: _pic.Cursor = Cursors.Default; break;
}
}
/// <summary>
/// 改变矩形边缘大小
/// </summary>
/// <param name="rect"></param>
/// <param name="x"></param>
/// <param name="y"></param>
private RectangleF RectMarginChange(RectangleF rect, int x, int y)
{
switch (fieldMargin)
{
case Model.FieldMargin.Left:
rect.X += x;
rect.Width -= x;
break;
case Model.FieldMargin.Top:
rect.Y += y;
rect.Height -= y;
break;
case Model.FieldMargin.Right:
rect.Width += x;
break;
case Model.FieldMargin.Bottom:
rect.Height += y;
break;
case Model.FieldMargin.LeftTop:
rect.X += x;
rect.Width -= x;
rect.Y += y;
rect.Height -= y;
break;
case Model.FieldMargin.RightTop:
rect.Y += y;
rect.Height -= y;
rect.Width += x;
break;
case Model.FieldMargin.LeftBottom:
rect.X += x;
rect.Width -= x;
rect.Height += y;
break;
case Model.FieldMargin.RightBottom:
rect.Width += x;
rect.Height += y;
break;
case Model.FieldMargin.Inside:
rect.X += x;
rect.Y += y;
break;
}
rect.Width = rect.Width < 0.01f ? 0.01f: rect.Width;
rect.Height = rect.Height < 0.01f ? 0.01f: rect.Height;
return rect;
}
private string[] StrGetKey(string s)
{
string tt = "";
List<string> rtn = new List<string>();
bool into = false;
for (int i = 0; i < s.Length; i++)
{
if (s[i] == '{')
{
into = true;
tt = "";
}
else if (s[i] == '}')
{
into = false;
rtn.Add(tt);
}
else if (into)
{
tt += s[i];
}
}
return rtn.ToArray();
}
private void PicEdit_Paint(object sender, PaintEventArgs e)
{
if (LabelIndex == -1)
{
e.Graphics.Clear(_pic.BackColor);
return;
}
Model.ClsLabel label = Common.Label[LabelIndex];
//背景
e.Graphics.FillRectangle(Brushes.White, offset.X, offset.Y, label.Size_px.Width, label.Size_px.Height);
e.Graphics.DrawRectangle(Pens.Black, offset.X, offset.Y, label.Size_px.Width, label.Size_px.Height);
//标签尺寸大小文本
string s = string.Format("{0:0.00}×{1:0.00} (mm)", label.Size_mm.Width, label.Size_mm.Height);
Font font = new Font("宋体", 12f);
SizeF sizeF = e.Graphics.MeasureString(s, font);
labelSizeShow = new RectangleF(offset.X, offset.Y - sizeF.Height, sizeF.Width, sizeF.Height);
e.Graphics.DrawString(s, font, Brushes.Black, labelSizeShow);
//字段
font = new Font("宋体", 10f);
for (int i = 0; i < label.Field.Count; i++)
{
RectangleF rect = new RectangleF(label.Field[i].Location_px.X + offset.X, label.Field[i].Location_px.Y + offset.Y, label.Field[i].Size_px.Width, label.Field[i].Size_px.Height);
//文本
if (label.Field[i].Type == Model.LabelFieldType.Text)
{
if (fieldFormatShow)
e.Graphics.DrawString(label.Field[i].FormatText, label.Field[i].Font, Brushes.Black, rect);
else
e.Graphics.DrawString(StrRemoveKey(label.Field[i].FormatText), label.Field[i].Font, Brushes.Black, rect);
}
else //条形码或二维码
{
if (label.Field[i].Image != null)
e.Graphics.DrawImage(label.Field[i].Image, rect);
}
//选中的字段
if (i == fieldIdx)
{
//选中的字段区域显示红色
e.Graphics.DrawRectangle(Pens.Red, rect.X, rect.Y, rect.Width, rect.Height);
//字段区域的4个角的矩形
e.Graphics.DrawRectangle(Pens.Black, rect.X - FIELD_MARGIN, rect.Y - FIELD_MARGIN, FIELD_MARGIN, FIELD_MARGIN);
e.Graphics.DrawRectangle(Pens.Black, rect.X + rect.Width, rect.Y - FIELD_MARGIN, FIELD_MARGIN, FIELD_MARGIN);
e.Graphics.DrawRectangle(Pens.Black, rect.X - FIELD_MARGIN, rect.Y + rect.Height, FIELD_MARGIN, FIELD_MARGIN);
e.Graphics.DrawRectangle(Pens.Black, rect.X + rect.Width, rect.Y + rect.Height, FIELD_MARGIN, FIELD_MARGIN);
//显示区域的毫米大小
s = string.Format("{0:0.00}×{1:0.00}, {2:0.00}×{3:0.00} (mm)", label.Field[i].Location_mm.X, label.Field[i].Location_mm.Y, label.Field[i].Size_mm.Width, label.Field[i].Size_mm.Height);
sizeF = e.Graphics.MeasureString(s, font);
fieldSizeShow = new RectangleF(rect.X, rect.Y - sizeF.Height, sizeF.Width, sizeF.Height);
e.Graphics.DrawString(s, font, Brushes.Red, fieldSizeShow);
}
else
{
//未选中的字段区域显示灰色
e.Graphics.DrawRectangle(Pens.LightGray, rect.X, rect.Y, rect.Width, rect.Height);
}
}
}
private void PicEdit_MouseUp(object sender, MouseEventArgs e)
{
}
private void PicEdit_MouseMove(object sender, MouseEventArgs e)
{
int x, y;
if (e.Button == MouseButtons.Left)
{
if (labelIdx == -1) return;
x = e.X - oldPoint.X;
y = e.Y - oldPoint.Y;
//x = x < 0 ? 0:x;
//y = y < 0 ? 0:y;
if (fieldIdx == -1)
{
//移动整个标签
offset.X += x;
offset.Y += y;
}
else
{
//移动字段,修改字段的位置大小
Common.Label[labelIdx].Field[fieldIdx].SetLocationSize(RectMarginChange(Common.Label[labelIdx].Field[fieldIdx].GetRectangleF(), x, y));
FieldSelected?.Invoke(Common.Label[labelIdx].Field[fieldIdx].Location_mm, Common.Label[labelIdx].Field[fieldIdx].Size_mm, Common.Label[labelIdx].Field[fieldIdx].Type);
}
oldPoint = e.Location;
if (_pic != null)
_pic.Refresh();
}
else if (e.Button == MouseButtons.None)
{
if (fieldIdx == -1) return;
if (labelIdx == -1) return;
x = e.X - offset.X;
y = e.Y - offset.Y;
FindRectMargin(Common.Label[labelIdx].Field[fieldIdx].GetRectangleF(), x, y);
}
}
private void PicEdit_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left) return;
if (labelIdx == -1) return;
oldPoint = e.Location;
//标签显示大小的位置
//bool rtn = labelRect.Contains(e.Location);
//if (rtn)
//{
// ResizeLabel();
// return;
//}
//查找文本索引
if (fieldMargin != Model.FieldMargin.Outside) return;
float x = e.X - offset.X;
float y = e.Y - offset.Y;
int idx = Common.Label[labelIdx].Field.FindIndex(lf => lf.Contains(x, y));
//if (fieldIdx >= 0 && idx == -1)
//{
// rtn = fieldSizeShow.Contains(e.Location);
// if (rtn)
// {
// FieldResize();
// return;
// }
//}
fieldIdx = idx;
if (fieldIdx == -1)
{
//currField = null;
LabelSelected?.Invoke(Common.Label[labelIdx].Size_mm);
}
else
{
//currField = _label[labelIdx].Field[fieldIdx];
FieldSelected?.Invoke(Common.Label[labelIdx].Field[fieldIdx].Location_mm, Common.Label[labelIdx].Field[fieldIdx].Size_mm, Common.Label[labelIdx].Field[fieldIdx].Type);
FieldFormat?.Invoke(Common.Label[labelIdx].Field[fieldIdx].FormatText);
}
if (_pic != null)
_pic.Refresh();
}
private void PicEdit_MouseLeave(object sender, EventArgs e)
{
}
private void PicEdit_MouseEnter(object sender, EventArgs e)
{
}
private void PrintTest_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
for (int i = 0; i < Common.Label[labelIdx].Field.Count; i++)
{
Model.ClsLabelField field = Common.Label[labelIdx].Field[i];
if (field.Type == Model.LabelFieldType.Text)
{
//文本
e.Graphics.DrawString(field.FormatText, field.Font, Brushes.Black, new RectangleF(field.Location_px, field.Size_px));
}
else
{
//二维码
if (field.Image != null)
e.Graphics.DrawImage(field.Image, new RectangleF(field.Location_px, field.Size_px));
}
//边框
e.Graphics.DrawRectangle(Pens.LightGray, field.Location_px.X, field.Location_px.Y, field.Size_px.Width, field.Size_px.Height);
}
}
private void PrintLast_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
//int n = Common.Label.FindIndex(s => s.Name == Common.Config.DefaultLabel);
for (int i = 0; i < Common.Label[LabelIndex].Field.Count; i++)
{
Model.ClsLabelField field = Common.Label[LabelIndex].Field[i];
if (field.Type == Model.LabelFieldType.Text)
{
//文本
e.Graphics.DrawString(field.PrintText, field.Font, Brushes.Black, field.GetRectangleF());
}
else
{
//二维码
if (field.Image != null)
e.Graphics.DrawImage(field.Image, field.GetRectangleF());
}
}
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Drawing;
using PrintLabel;
using ZXing.PDF417.Internal;
namespace Model
{
/// <summary>
/// 打印的标签
/// </summary>
internal class ClsLabel
{
/// <summary>
/// 文件路径
/// </summary>
public string Path { set; get; }
/// <summary>
/// 标签名称
/// </summary>
public string Name { set; get; }
/// <summary>
/// 标签大小,毫米单位
/// </summary>
public SizeF Size_mm { private set; get; }
/// <summary>
/// 标签大小,像素单位
/// </summary>
public SizeF Size_px { private set; get; }
/// <summary>
/// 打印偏移量
/// </summary>
public Point Offset { get; set; }
/// <summary>
/// 包含的字段
/// </summary>
public List<ClsLabelField> Field { set; get; }
/// <summary>
/// 打印的标签
/// </summary>
public ClsLabel()
{
Field = new List<ClsLabelField>();
}
/// <summary>
/// 设置大小
/// </summary>
/// <param name="s">大小的宽度高度</param>
public void SetSize(string s)
{
string[] tt = s.Split(',');
if (tt.Length != 2) return;
bool rtn = float.TryParse(tt[0], out float width);
if (!rtn) return;
rtn = float.TryParse(tt[1], out float height);
if (!rtn) return;
Size_mm = new SizeF(width, height);
Size_px = new SizeF(Common.MMToPx(width), Common.MMToPx(height));
}
/// <summary>
/// 获取大小(毫米)
/// </summary>
/// <returns></returns>
public string GetSize()
{
return string.Format("{0:0.000},{1:0.000}", Size_mm.Width, Size_mm.Height);
}
/// <summary>
/// 设置大小
/// </summary>
/// <param name="width"></param>
/// <param name="height"></param>
public void SetSize(float width, float height)
{
Size_mm = new SizeF(width, height);
Size_px = new SizeF(Common.MMToPx(width), Common.MMToPx(height));
}
/// <summary>
/// 设置打印偏移量
/// </summary>
/// <param name="s">偏移量的xy</param>
public void SetOffset(string s)
{
string[] tt = s.Split(',');
if (tt.Length != 2) return;
bool rtn = int.TryParse(tt[0], out int x);
if (!rtn) return;
rtn = int.TryParse(tt[1], out int y);
if (!rtn) return;
Offset = new Point(x, y);
}
/// <summary>
/// 获取打印偏移
/// </summary>
/// <returns></returns>
public string GetOffset()
{
return string.Format("{0},{1}", Offset.X, Offset.Y);
}
}
/// <summary>
/// 打印标签字段
/// </summary>
internal class ClsLabelField
{
/// <summary>
/// 左上角坐标,像素单位
/// </summary>
public PointF Location_px { set; get; }
/// <summary>
/// 左上角坐标,毫米单位
/// </summary>
public PointF Location_mm { set; get; }
/// <summary>
/// 大小,像素单位
/// </summary>
public SizeF Size_px { set; get; }
/// <summary>
/// 大小,毫米单位
/// </summary>
public SizeF Size_mm { set; get; }
/// <summary>
/// 字体
/// </summary>
public Font Font { set; get; }
/// <summary>
/// 打印的文本内容
/// </summary>
public string PrintText { set; get; }
/// <summary>
/// 用于格式化的文本
/// </summary>
public string FormatText { set; get; }
/// <summary>
/// 字段类型
/// </summary>
public LabelFieldType Type { set; get; }
/// <summary>
/// 条码或二维码的图片
/// </summary>
public Bitmap Image { set; get; }
/// <summary>
/// 打印标签字段
/// </summary>
public ClsLabelField()
{
Font = new Font("宋体", 9f);
Type = LabelFieldType.Text;
Image = null;
}
/// <summary>
/// 设置位置和大小(毫米)
/// </summary>
/// <param name="rect">毫米尺寸文本</param>
public void SetLocationSize(string rect)
{
string[] tt = rect.Split(',');
if (tt.Length != 4) return;
bool rtn = float.TryParse(tt[0], out float x);
if (!rtn) return;
rtn = float.TryParse(tt[1], out float y);
if (!rtn) return;
rtn = float.TryParse(tt[2], out float width);
if (!rtn) return;
rtn = float.TryParse(tt[3], out float height);
if (!rtn) return;
Location_mm = new PointF(x, y);
Location_px = new PointF(Common.MMToPx(x), Common.MMToPx(y));
Size_mm = new SizeF(width, height);
Size_px = new SizeF(Common.MMToPx(width), Common.MMToPx(height));
}
/// <summary>
/// 设置位置和大小(像素)
/// </summary>
/// <param name="rect">像素位置大小</param>
public void SetLocationSize(RectangleF rect)
{
Location_px = new PointF(rect.X, rect.Y);
Location_mm = new PointF(Common.PxToMM(rect.X), Common.PxToMM(rect.Y));
Size_px = new SizeF(rect.Width, rect.Height);
Size_mm = new SizeF(Common.PxToMM(rect.Width), Common.PxToMM(rect.Height));
}
/// <summary>
/// 设置位置和大小(毫米)
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="w"></param>
/// <param name="h"></param>
public void SetLocationSize(float x, float y, float w, float h)
{
Location_mm = new PointF(x, y);
Location_px = new PointF(Common.MMToPx(x), Common.MMToPx(y));
Size_mm = new SizeF(w, h);
Size_px = new SizeF(Common.MMToPx(w), Common.MMToPx(h));
}
/// <summary>
/// 设置字体
/// </summary>
/// <param name="s">格式:字体,字号,粗体,斜体</param>
/// <returns></returns>
public void SetFont(string s)
{
string[] t = s.Split(',');
float emSize = Convert.ToSingle(t[1]);
FontStyle style = FontStyle.Regular;
if (t[2] == "B") style |= FontStyle.Bold;
if (t[3] == "I") style |= FontStyle.Italic;
Font = new Font(t[0], emSize, style);
}
public string GetFont()
{
string[] s = new string[4];
s[0] = Font.Name;
s[1] = Font.Size.ToString();
if (Font.Bold) s[2] = "B";
if (Font.Italic) s[3] = "I";
return string.Join(",", s);
}
public RectangleF GetRectangleF()
{
return new RectangleF(Location_px, Size_px);
}
public string GetRectText()
{
return string.Format("{0},{1},{2},{3}", Location_mm.X, Location_mm.Y, Size_mm.Width, Size_mm.Height);
}
/// <summary>
/// 设置条码或二维码图片
/// </summary>
/// <param name="content">内容</param>
public void SetBarQRCode(string content)
{
try
{
Image = null;
if (Type == LabelFieldType.Text) return;
ZXing.BarcodeWriter writer = new ZXing.BarcodeWriter();
ZXing.QrCode.QrCodeEncodingOptions qrCodeEncodingOptions = new ZXing.QrCode.QrCodeEncodingOptions()
{
DisableECI = true,
CharacterSet = "UTF-8",
Width = 300,
Height = 300,
Margin = 1,
PureBarcode = true
};
ZXing.PDF417.PDF417EncodingOptions pDF417EncodingOptions = new ZXing.PDF417.PDF417EncodingOptions()
{
AspectRatio = PDF417AspectRatio.AUTO,
Compact = false,
Compaction = Compaction.AUTO,
DisableECI = true,
ErrorCorrection = PDF417ErrorCorrectionLevel.AUTO,
PureBarcode = false,
GS1Format = false,
Width = 100,
CharacterSet = "UTF-8",
//Height = 70,
Margin = 1
};
switch (Type)
{
case LabelFieldType.Code39:
writer.Format = ZXing.BarcodeFormat.CODE_39;
Image = writer.Write(content);
break;
case LabelFieldType.Code93:
writer.Format = ZXing.BarcodeFormat.CODE_93;
Image = writer.Write(content);
break;
case LabelFieldType.Code128:
writer.Format = ZXing.BarcodeFormat.CODE_128;
Image = writer.Write(content);
break;
case LabelFieldType.DataMatrix:
writer.Format = ZXing.BarcodeFormat.DATA_MATRIX;
Image = writer.Write(content);
break;
case LabelFieldType.QRCode:
writer.Options = qrCodeEncodingOptions;
writer.Format = ZXing.BarcodeFormat.QR_CODE;
Image = writer.Write(content);
break;
case LabelFieldType.PDF417:
writer.Options = pDF417EncodingOptions;
writer.Format = ZXing.BarcodeFormat.PDF_417;
Image = writer.Write(content);
break;
}
}
catch (Exception ex)
{
}
}
/// <summary>
/// 设置条码或二维码图片
/// </summary>
public void SetBarQRCode()
{
SetBarQRCode(FormatText);
}
/// <summary>
/// 坐标是否包含在范围内
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
public bool Contains(float x, float y)
{
if (x >= Location_px.X && x <= Location_px.X + Size_px.Width &&
y >= Location_px.Y && y <= Location_px.Y + Size_px.Height)
{
return true;
}
else
{
return false;
}
}
}
/// <summary>
/// 打印标签字段类型
/// </summary>
internal enum LabelFieldType
{
/// <summary>
/// 39一维码
/// </summary>
Code39,
/// <summary>
/// 93一维码
/// </summary>
Code93,
/// <summary>
/// 128一维码
/// </summary>
Code128,
/// <summary>
/// DM二维码
/// </summary>
DataMatrix,
/// <summary>
/// QR二维码
/// </summary>
QRCode,
/// <summary>
/// 文本
/// </summary>
Text,
/// <summary>
/// PDF417
/// </summary>
PDF417
}
internal enum FieldMargin
{
/// <summary>
/// 外面
/// </summary>
Outside,
/// <summary>
/// 左边
/// </summary>
Left,
/// <summary>
/// 上边
/// </summary>
Top,
/// <summary>
/// 右边
/// </summary>
Right,
/// <summary>
/// 下边
/// </summary>
Bottom,
/// <summary>
/// 左上角
/// </summary>
LeftTop,
/// <summary>
/// 右上角
/// </summary>
RightTop,
/// <summary>
/// 左下角
/// </summary>
LeftBottom,
/// <summary>
/// 右下角
/// </summary>
RightBottom,
/// <summary>
/// 内部
/// </summary>
Inside
}
}
\ No newline at end of file
using PrintLabel;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Management;
using System.Printing;
namespace Asa
{
public class PrintLabel
{
public delegate void PrintStatusEvent(PrinterStatus sta, string msg);
public event PrintStatusEvent PrintStatusChanged;
private System.Threading.Thread tRun;
public PrintLabel(string dir)
{
Common.LabelPrint = new BLL.LabelPrint();
Common.LabelPrint.Load(dir);
}
/// <summary>
/// 加载标签
/// </summary>
/// <param name="labelName"></param>
public void LoadLabel(string labelName)
{
Common.LabelPrint.LabelName = labelName;
}
/// <summary>
/// 编辑标签
/// </summary>
public void EditLabel()
{
FrmLabel frm = new FrmLabel();
frm.ShowDialog();
}
public string[] GetLabelName()
{
return Common.LabelPrint.GetName();
}
public string[] GetPrinterName()
{
List<string> list = new List<string>();
foreach (string ss in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
list.Add(ss);
return list.ToArray();
}
/// <summary>
/// 打印机
/// </summary>
/// <param name="name">打印机名字</param>
/// <param name="landscape">打印方向,横向纵向</param>
public void Printer(string name, bool landscape)
{
Common.LabelPrint.PrinterName = name;
Common.LabelPrint.PrintLandscape = landscape;
}
public bool Rotate180 { set => Common.LabelPrint.Rotate180 = value; get => Common.LabelPrint.Rotate180; }
/// <summary>
/// 打印
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public Bitmap Print(Dictionary<string, string> key)
{
Bitmap bmp = Common.LabelPrint.PrintLast(key, out string[] codeContent);
tRun = new System.Threading.Thread(new System.Threading.ThreadStart(GetStatus));
tRun.Start();
return bmp;
}
public Bitmap PrintPreview(Dictionary<string, string> key)
{
Common.LabelPrint.labelIdx = 1;
Bitmap bmp = Common.LabelPrint.PrintPreview(key, out string[] code);
return bmp;
}
/// <summary>
/// 打印机状态
/// </summary>
public enum PrinterStatus
{
/// <summary>
/// 其他
/// </summary>
Other = 1,
/// <summary>
/// 未知
/// </summary>
Unknown,
/// <summary>
/// 空闲
/// </summary>
Idle,
/// <summary>
/// 正在打印中
/// </summary>
Printing,
/// <summary>
/// 预热
/// </summary>
Preheat,
/// <summary>
/// 停止打印
/// </summary>
Stop,
/// <summary>
/// 打印中
/// </summary>
Print,
/// <summary>
/// 离线
/// </summary>
Offline
}
/// <summary>
/// 获取打印机的当前状态
/// </summary>
public void GetStatus()
{
int n = 0;
int timeout = 0;
string msg = "无";
PrinterStatus sta = PrinterStatus.Other;
string path = "win32_printer.DeviceId='" + Common.LabelPrint.PrinterName + "'";
ManagementObject printer = new ManagementObject(path);
while (true)
{
printer.Get();
int ret = Convert.ToInt32(printer.Properties["PrinterStatus"].Value);
sta = (PrinterStatus)ret;
switch(sta)
{
case PrinterStatus.Other:
msg = "其他";
n = 3;
break;
case PrinterStatus.Unknown:
msg = "未知";
n = 3;
break;
case PrinterStatus.Stop:
msg = "停止";
n = 3;
break;
case PrinterStatus.Offline:
msg = "离线";
n = 3;
break;
case PrinterStatus.Preheat:
msg = "预热";
break;
case PrinterStatus.Print:
msg = "打印中";
n = 1;
break;
case PrinterStatus.Printing:
msg = "打印中";
n = 1;
break;
case PrinterStatus.Idle:
if (n == 1)
{
msg += ",空闲";
n = 2;
}
break;
default:
msg = "default";
n = 3;
break;
}
if (n == 3 || n == 2)
break;
timeout += 500;
System.Threading.Thread.Sleep(500);
if (timeout >= 15000)
break;
}
PrintStatusChanged?.Invoke(sta, msg);
}
private void GetPrintStatus()
{
PrintQueue pq = LocalPrintServer.GetDefaultPrintQueue();
switch (pq.QueueStatus)
{
//正常状态
case PrintQueueStatus.None:
Console.WriteLine("正常运行");
break;
//纸未取走
case PrintQueueStatus.OutputBinFull:
Console.WriteLine("未取走");
break;
//缺纸
case PrintQueueStatus.PaperOut:
Console.WriteLine("缺纸");
break;
//打印
case PrintQueueStatus.Printing:
Console.WriteLine("正在打印");
break;
default:
Console.WriteLine(pq.QueueStatus);
break;
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{B8F25ECE-DEE6-41D6-8EF0-8AFBF2577C17}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Asa</RootNamespace>
<AssemblyName>Asa.PrintLabel</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Management" />
<Reference Include="System.Printing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="zxing, Version=0.16.5.0, Culture=neutral, PublicKeyToken=4e88037ac681fe60, processorArchitecture=MSIL">
<HintPath>..\packages\ZXing.Net.0.16.5\lib\net461\zxing.dll</HintPath>
</Reference>
<Reference Include="zxing.presentation, Version=0.16.5.0, Culture=neutral, PublicKeyToken=4e88037ac681fe60, processorArchitecture=MSIL">
<HintPath>..\packages\ZXing.Net.0.16.5\lib\net461\zxing.presentation.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="LabelPrint.cs" />
<Compile Include="ClassExtend.cs" />
<Compile Include="FormTextBox.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="FormTextBox.Designer.cs">
<DependentUpon>FormTextBox.cs</DependentUpon>
</Compile>
<Compile Include="Model.cs" />
<Compile Include="Common.cs" />
<Compile Include="FrmLabel.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="FrmLabel.Designer.cs">
<DependentUpon>FrmLabel.cs</DependentUpon>
</Compile>
<Compile Include="PrintLabel.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="FormTextBox.resx">
<DependentUpon>FormTextBox.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="FrmLabel.resx">
<DependentUpon>FrmLabel.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("PrintLabel")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PrintLabel")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("b8f25ece-dee6-41d6-8ef0-8afbf2577c17")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ZXing.Net" version="0.16.5" targetFramework="net461" />
</packages>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
\ No newline at end of file
namespace PrintLabel_Test
{
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.textBox2 = new System.Windows.Forms.TextBox();
this.button4 = new System.Windows.Forms.Button();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.button5 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(154, 127);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(123, 49);
this.button1.TabIndex = 0;
this.button1.Text = "编辑";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(374, 127);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(162, 21);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "test2";
//
// button2
//
this.button2.Location = new System.Drawing.Point(374, 181);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(100, 23);
this.button2.TabIndex = 2;
this.button2.Text = "加载";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(154, 182);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(123, 49);
this.button3.TabIndex = 3;
this.button3.Text = "打印";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(374, 154);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(162, 21);
this.textBox2.TabIndex = 4;
this.textBox2.Text = "ZDesigner GT800 (EPL)";
//
// button4
//
this.button4.Location = new System.Drawing.Point(374, 276);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(100, 23);
this.button4.TabIndex = 5;
this.button4.Text = "获取状态";
this.button4.UseVisualStyleBackColor = true;
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(502, 224);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(251, 163);
this.pictureBox1.TabIndex = 6;
this.pictureBox1.TabStop = false;
//
// button5
//
this.button5.Location = new System.Drawing.Point(154, 237);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(123, 47);
this.button5.TabIndex = 7;
this.button5.Text = "button5";
this.button5.UseVisualStyleBackColor = true;
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.button5);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.button4);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Button button5;
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PrintLabel_Test
{
public partial class Form1 : Form
{
private Asa.PrintLabel print;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
print = new Asa.PrintLabel(Application.StartupPath + "\\Label");
print.PrintStatusChanged += Print_PrintStatusChanged;
}
private void Print_PrintStatusChanged(Asa.PrintLabel.PrinterStatus sta, string msg)
{
MessageBox.Show(sta.ToString());
}
private void button1_Click(object sender, EventArgs e)
{
print.EditLabel();
}
private void button2_Click(object sender, EventArgs e)
{
print.LoadLabel(textBox1.Text);
print.Printer(textBox2.Text, false);
}
private void button3_Click(object sender, EventArgs e)
{
Dictionary<string, string> text = new Dictionary<string, string>();
text.Add("aa", "123");
text.Add("bb", "yumtrj");
print.Print(text);
}
private void button4_Click(object sender, EventArgs e)
{
print.GetStatus();
}
private void button5_Click(object sender, EventArgs e)
{
Dictionary<string, string> text = new Dictionary<string, string>();
text.Add("ri", "123123123123123");
text.Add("pn", "yumtr3123123j");
pictureBox1.Image = print.PrintPreview(text);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{857ACBBF-F326-4AD0-AD6F-B7F7479AFE2C}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>PrintLabel_Test</RootNamespace>
<AssemblyName>PrintLabel_Test</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PrintLabel\PrintLabel.csproj">
<Project>{b8f25ece-dee6-41d6-8ef0-8afbf2577c17}</Project>
<Name>PrintLabel</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PrintLabel_Test
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的一般信息由以下
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("PrintLabel_Test")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PrintLabel_Test")]
[assembly: AssemblyCopyright("Copyright © 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 会使此程序集中的类型
//对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
//请将此类型的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("857acbbf-f326-4ad0-ad6f-b7f7479afe2c")]
// 程序集的版本信息由下列四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本: 4.0.30319.42000
//
// 对此文件的更改可能导致不正确的行为,如果
// 重新生成代码,则所做更改将丢失。
// </auto-generated>
//------------------------------------------------------------------------------
namespace PrintLabel_Test.Properties
{
/// <summary>
/// 强类型资源类,用于查找本地化字符串等。
/// </summary>
// 此类是由 StronglyTypedResourceBuilder
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或删除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources
{
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources()
{
}
/// <summary>
/// 返回此类使用的缓存 ResourceManager 实例。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager
{
get
{
if ((resourceMan == null))
{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("PrintLabel_Test.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// 覆盖当前线程的 CurrentUICulture 属性
/// 使用此强类型的资源类的资源查找。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace PrintLabel_Test.Properties
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
{
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default
{
get
{
return defaultInstance;
}
}
}
}
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!