C#标签设计打印软件开发

1、新建自定义C#控件项目Custom

using System;
using System.Collections.Generic;
using System.Text;namespace CustomControls
{public class CommonSettings{/// <summary>/// 把像素换算成毫米/// </summary>/// <param name="Pixel">多少像素</param>/// <returns>多少毫米</returns>public static float PixelConvertMillimeter(float Pixel){return Pixel / 96 * 25.4f;}/// <summary>/// 把毫米换算成像素/// </summary>/// <param name="Millimeter">多少毫米</param>/// <returns>多少像素</returns>public static int MillimeterConvertPixel(float Millimeter){return ((int)(Millimeter / 25.4 * 96)+1);}}
}

GraphicsTools 

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing.Drawing2D;
using System.Drawing;namespace CustomControls
{internal static class GraphicsTools{/// <summary>/// Creates a rounded rectangle from the specified rectangle and radius/// </summary>/// <param name="rectangle">Base rectangle</param>/// <param name="radius">Radius of the corners</param>/// <returns>Rounded rectangle as a GraphicsPath</returns>public static GraphicsPath CreateRoundRectangle(Rectangle rectangle, int radius){GraphicsPath path = new GraphicsPath();int l = rectangle.Left;int t = rectangle.Top;int w = rectangle.Width;int h = rectangle.Height;int d = radius << 1;path.AddArc(l, t, d, d, 180, 90); // topleftpath.AddLine(l + radius, t, l + w - radius, t); // toppath.AddArc(l + w - d, t, d, d, 270, 90); // toprightpath.AddLine(l + w, t + radius, l + w, t + h - radius); // rightpath.AddArc(l + w - d, t + h - d, d, d, 0, 90); // bottomrightpath.AddLine(l + w - radius, t + h, l + radius, t + h); // bottompath.AddArc(l, t + h - d, d, d, 90, 90); // bottomleftpath.AddLine(l, t + h - radius, l, t + radius); // leftpath.CloseFigure();return path;}/// <summary>/// Creates a rectangle rounded on the top/// </summary>/// <param name="rectangle">Base rectangle</param>/// <param name="radius">Radius of the top corners</param>/// <returns>Rounded rectangle (on top) as a GraphicsPath object</returns>public static GraphicsPath CreateTopRoundRectangle(Rectangle rectangle, int radius){GraphicsPath path = new GraphicsPath();int l = rectangle.Left;int t = rectangle.Top;int w = rectangle.Width;int h = rectangle.Height;int d = radius << 1;path.AddArc(l, t, d, d, 180, 90); // topleftpath.AddLine(l + radius, t, l + w - radius, t); // toppath.AddArc(l + w - d, t, d, d, 270, 90); // toprightpath.AddLine(l + w, t + radius, l + w, t + h); // rightpath.AddLine(l + w, t + h, l, t + h); // bottompath.AddLine(l, t + h, l, t + radius); // leftpath.CloseFigure();return path;}/// <summary>/// Creates a rectangle rounded on the bottom/// </summary>/// <param name="rectangle">Base rectangle</param>/// <param name="radius">Radius of the bottom corners</param>/// <returns>Rounded rectangle (on bottom) as a GraphicsPath object</returns>public static GraphicsPath CreateBottomRoundRectangle(Rectangle rectangle, int radius){GraphicsPath path = new GraphicsPath();int l = rectangle.Left;int t = rectangle.Top;int w = rectangle.Width;int h = rectangle.Height;int d = radius << 1;path.AddLine(l + radius, t, l + w - radius, t); // toppath.AddLine(l + w, t + radius, l + w, t + h - radius); // rightpath.AddArc(l + w - d, t + h - d, d, d, 0, 90); // bottomrightpath.AddLine(l + w - radius, t + h, l + radius, t + h); // bottompath.AddArc(l, t + h - d, d, d, 90, 90); // bottomleftpath.AddLine(l, t + h - radius, l, t + radius); // leftpath.CloseFigure();return path;}}
}

2、打印机设置界面

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing.Printing;
using System.Text;
using System.Windows.Forms;
using  CustomControls.IO;namespace CustomControls.Control
{public partial class frmSetting : Form{public frmSetting(PrintConfig confg){InitializeComponent();pconfig = confg;}private PrintConfig pconfig;private void frmSetting_Load(object sender, EventArgs e){for (int i=0; i < PrinterSettings.InstalledPrinters.Count; i++){cbPrintName.Items.Add(PrinterSettings.InstalledPrinters[i]);}if (cbPrintName.Items.Count > 0){cbPrintName.SelectedItem = pconfig.PrintName;}numX.Value = pconfig.XOFFSET;numY.Value = pconfig.YOFFSET;numZoom.Value = (decimal)pconfig.ZOOM;numCopies.Value = pconfig.Copies;}private void btnClose_Click(object sender, EventArgs e){this.Close();}private void btnOk_Click(object sender, EventArgs e){pconfig.XOFFSET = (int)numX.Value;pconfig.YOFFSET = (int)numY.Value;pconfig.PrintName = cbPrintName.SelectedItem.ToString();pconfig.ZOOM = (float)numZoom.Value;pconfig.Copies = (int)numCopies.Value;this.Close();}}
}

 3、条形码39码\93码实现

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace CustomControls.BarCode
{[Serializable]internal class Code39 : IBarcode{public Code39(){EncodeBarcodeValue();}#region Variable/// <summary>/// 是否显示条码的值/// </summary>private bool bShowText = true;/// <summary>/// 是否在条码上方显示字符/// </summary>private bool bShowTextOnTop = false;/// <summary>/// 条码值的对值的对齐方式/// </summary>private BarcodeTextAlign align = BarcodeTextAlign.Left;/// <summary>/// 条码的做图区域/// </summary>private Rectangle barcodeRect;/// <summary>/// 条码的值/// </summary>private String code = "0123456";/// <summary>/// 条码的高度/// </summary>private int height = 30;/// <summary>/// 条码的大小/// </summary>private BarCodeWeight weight = BarCodeWeight.Small;/// <summary>/// 旋转/// </summary>private BarcodeRotation Rotation = BarcodeRotation.Rotation90;/// <summary>/// 条码的字体/// </summary>private Font textFont = new Font("Courier", 8);/// <summary>/// 将条码数据编码/// </summary>private String encodedString = "";/// <summary>/// 条码值的长度/// </summary>private int strLength = 0;/// <summary>/// 条码的比率/// </summary>private int wideToNarrowRatio = 2;#endregion#region Base String ValueString alphabet39 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%*";String[] coded39Char = {/* 0 */ "000110100", /* 1 */ "100100001", /* 2 */ "001100001", /* 3 */ "101100000",/* 4 */ "000110001", /* 5 */ "100110000", /* 6 */ "001110000", /* 7 */ "000100101",/* 8 */ "100100100", /* 9 */ "001100100", /* A */ "100001001", /* B */ "001001001",/* C */ "101001000", /* D */ "000011001", /* E */ "100011000", /* F */ "001011000",/* G */ "000001101", /* H */ "100001100", /* I */ "001001100", /* J */ "000011100",/* K */ "100000011", /* L */ "001000011", /* M */ "101000010", /* N */ "000010011",/* O */ "100010010", /* P */ "001010010", /* Q */ "000000111", /* R */ "100000110",/* S */ "001000110", /* T */ "000010110", /* U */ "110000001", /* V */ "011000001",/* W */ "111000000", /* X */ "010010001", /* Y */ "110010000", /* Z */ "011010000",/* - */ "010000101", /* . */ "110000100", /*' '*/ "011000100",/* $ */ "010101000",/* / */ "010100010", /* + */ "010001010", /* % */ "000101010", /* * */ "010010100" };#endregion#region Barcode attribute/// <summary>/// get or set Barcode Height/// </summary>public int BarcodeHeight{get { return height; }set { height = value; }}/// <summary>/// Get or Set Barcode Value/// </summary>public String BarcodeValue{get { return code; }set{code = value.ToUpper();EncodeBarcodeValue();}}/// <summary>/// get or set baroce weight/// </summary>public BarCodeWeight BarcodeWeight{get { return weight; }set { weight = value; }}/// <summary>/// get or set barocde draw range/// </summary>public Rectangle BarcodeRect{get { return barcodeRect; }set { barcodeRect = value; }}/// <summary>/// get or set show value text/// </summary>public bool ShowText{get { return bShowText; }set { bShowText = value; }}/// <summary>/// get or set show value text on barcode top/// </summary>public bool ShowTextOnTop{get { return bShowTextOnTop; }set { bShowTextOnTop = value; }}/// <summary>/// get or set value text font/// </summary>public Font ValueTextFont{get { return textFont; }set { textFont = value; }}/// <summary>/// get or set value text align/// </summary>public BarcodeTextAlign barcodeTextAlign{get { return align; }set { align = value; }}/// <summary>/// get or set barcode rotation/// </summary>public BarcodeRotation barcodeRotation{get { return Rotation; }set { Rotation = value; }}#endregion#region Encode barcode string/// <summary>/// 对条码的值进行编码/// </summary>private void EncodeBarcodeValue(){try{String intercharacterGap = "0";String str = '*' + code.ToUpper() + '*';strLength = str.Length;encodedString = "";for (int i = 0; i < strLength; i++){if (i > 0)encodedString += intercharacterGap;encodedString += coded39Char[alphabet39.IndexOf(str[i])];}}catch{throw new Exception("无法编码!");}}#endregion#region Create Barcodepublic void CreateBarcode(Graphics g){//g.DrawString("Code 39", new Font("Vendana", 9), Brushes.Blue, barcodeRect);// g.SetClip(barcodeRect);GraphicsState state = g.Save();Matrix RotationTransform = new Matrix(1, 0, 0, 1, 1, 1); //rotation matrixPointF TheRotationPoint;switch (Rotation){case BarcodeRotation.Rotation90:TheRotationPoint = new PointF(barcodeRect.X, barcodeRect.Y);RotationTransform.RotateAt(90, TheRotationPoint);g.Transform = RotationTransform;g.TranslateTransform(0, -barcodeRect.Width);break;case BarcodeRotation.Rotation270:TheRotationPoint = new PointF(barcodeRect.X, barcodeRect.Y + barcodeRect.Height);RotationTransform.RotateAt(270, TheRotationPoint);g.Transform = RotationTransform;g.TranslateTransform(0, barcodeRect.Height);break;}bool bchkValueText = false;for (int i = 0; i < code.Length; i++){if (alphabet39.IndexOf(code[i]) == -1 || code[i] == '*'){g.DrawString("条码文本无效!", textFont, Brushes.Red, barcodeRect.X, barcodeRect.Y);bchkValueText = true;break;}}if (!bchkValueText){int encodedStringLength = encodedString.Length;float x = barcodeRect.X;float wid = 0;int yTop = (int)barcodeRect.Y;if (bShowText){using (StringFormat sf = new StringFormat()){   switch (align){case BarcodeTextAlign.Left:sf.Alignment = StringAlignment.Near;break;case BarcodeTextAlign.Center:sf.Alignment = StringAlignment.Center;sf.FormatFlags = StringFormatFlags.FitBlackBox;break;case BarcodeTextAlign.Right:sf.Alignment = StringAlignment.Far;break;}if (bShowTextOnTop){//yTop += height;if (Rotation == BarcodeRotation.Rotation0){g.DrawString(code, textFont, Brushes.Black, new RectangleF(barcodeRect.X, yTop, barcodeRect.Width, g.MeasureString("s", textFont).Height), sf);}else{g.DrawString(code, textFont, Brushes.Black, new RectangleF(barcodeRect.X, yTop, barcodeRect.Height, g.MeasureString("s", textFont).Height), sf);}yTop += Convert.ToInt32(g.MeasureString("s", textFont).Height);}else{yTop += height;if (Rotation == BarcodeRotation.Rotation0){g.DrawString(code, textFont, Brushes.Black, new RectangleF(barcodeRect.X, yTop, barcodeRect.Width, barcodeRect.Height - height), sf);}else{g.DrawString(code, textFont, Brushes.Black, new RectangleF(barcodeRect.X, yTop, barcodeRect.Height, barcodeRect.Width), sf);}yTop -= height;}}}for (int i = 0; i < encodedStringLength; i++){if (encodedString[i] == '1')wid = (wideToNarrowRatio * (int)weight);elsewid = (int)weight;g.FillRectangle(i % 2 == 0 ? Brushes.Black : Brushes.White, x, yTop, wid, height);x += wid;}}g.Restore(state);//g.ResetClip();}#endregion#region Barcode draw rectanglepublic Rectangle GetBarcodeRectangle(){int wid = 0, RectW = 0, RectH = 0;//for (int i = 0; i < code.Length; i++)//{//    if (alphabet39.IndexOf(code[i]) == -1 || code[i] == '*')//    {                    //        return new RectangleF(0, 0, 100, 100);//    }//}      for (int i = 0; i < encodedString.Length; i++){if (encodedString[i] == '1')wid = wideToNarrowRatio * (int)weight;elsewid = (int)weight;RectW += wid;}if (bShowText){using (Graphics g = Graphics.FromImage(new Bitmap(10, 10))){RectH = (int)g.MeasureString("S", textFont).Height + height;}}else{RectH = height;}switch (Rotation){case BarcodeRotation.Rotation90:case BarcodeRotation.Rotation270:return new Rectangle(barcodeRect.X, barcodeRect.Y, RectH, RectW);// break;}return new Rectangle(barcodeRect.X, barcodeRect.Y, RectW, RectH);}#endregion}
}

4、设计项目存档代码实现

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Xml;
using System.Drawing.Printing;
using CustomControls.IO;
using CustomControls.DrawItem;
using CustomControls.ToolBox;namespace CustomControls.Control
{public partial class DocumentSpace : UserControl{public DocumentSpace(){SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint, true);InitializeComponent();//绑定工具切换事件drawToolBox1.ToolChanged += new EventHandler(drawToolBox1_ToolChanged);//通过属性显示框,显示出所选对像的属性designer1.OnShowProperityInfo += new ShowProperityInfo(designer1_OnShowProperityInfo);//工具变换事件designer1.OnActiveToolChange += new ActiveToolChange(designer1_OnActiveToolChange);//添加或删除item事件designer1.OnItemChange += new ItemChange(designer1_OnItemChange);//添加工具栏按钮drawToolBox1.AddButton();numHeight.Value = (int)CommonSettings.PixelConvertMillimeter(designer1.Height);numWidth.Value = (int)CommonSettings.PixelConvertMillimeter(designer1.Width);}/// <summary>/// 获取design的宽和高/// </summary>private float design_width, design_height;/// <summary>/// 标尺数字的字体/// </summary>private Font scaleLabel = new Font("Verdana", 7);//private Point mouseLocationXs, mouseLocationXe, mouseLocationYs, mouseLocationYe;/// <summary>/// 通过此能数检测是打开还是新建的设计/// 在保存的时候是否可以直接保存/// </summary>private string openFileName = "";/// <summary>/// 画标尺刻度/// </summary>/// <param name="g"></param>private void DrawScale(Graphics g){design_width = designer1.Width;design_height = designer1.Height;int width_mm = (int)CommonSettings.PixelConvertMillimeter(design_width);int heigth_mm = (int)CommonSettings.PixelConvertMillimeter(design_height);float percent = design_width / width_mm;PointF ps, pe;int scale;for (int i = 0; i < width_mm; i++){if (i % 10 == 0){string x = (i / 10).ToString();SizeF fontSize = g.MeasureString(x, scaleLabel);scale = 15;PointF pf = new PointF(designer1.Location.X + i * percent - fontSize.Width / 2, designer1.Location.Y - scale - fontSize.Height);g.DrawString(x, scaleLabel, Brushes.Blue, pf);pf = new PointF(designer1.Location.X + i * percent - fontSize.Width / 2, designer1.Location.Y + scale + designer1.Height);g.DrawString(x, scaleLabel, Brushes.Blue, pf);}else if (i % 5 == 0){scale = 10;}else{scale = 5;}ps = new PointF(designer1.Location.X + i * percent, designer1.Location.Y);pe = new PointF(designer1.Location.X + i * percent, designer1.Location.Y - scale);g.DrawLine(Pens.Blue, ps, pe);ps = new PointF(designer1.Location.X + i * percent, designer1.Location.Y + designer1.Height);pe = new PointF(designer1.Location.X + i * percent, designer1.Location.Y + designer1.Height + scale);g.DrawLine(Pens.Blue, ps, pe);}for (int j = 0; j < heigth_mm; j++){if (j % 10 == 0){string x = (j / 10).ToString();scale = 15;SizeF fontSize = g.MeasureString(x, scaleLabel);g.DrawString(x, scaleLabel, Brushes.Blue, designer1.Location.X - fontSize.Width - scale, designer1.Location.Y + j * percent - fontSize.Height / 2);g.DrawString(x, scaleLabel, Brushes.Blue, designer1.Location.X + designer1.Width + scale, designer1.Location.Y + j * percent - fontSize.Height / 2);}else if (j % 5 == 0){scale = 10;}else{scale = 5;}ps = new PointF(designer1.Location.X, designer1.Location.Y + j * percent);pe = new PointF(designer1.Location.X - scale, designer1.Location.Y + j * percent);g.DrawLine(Pens.Blue, ps, pe);ps = new PointF(designer1.Location.X, designer1.Location.Y + j * percent);pe = new PointF(designer1.Location.X + designer1.Width + scale, designer1.Location.Y + j * percent);g.DrawLine(Pens.Blue, ps, pe);}//if (mouseLocationXs != null)//{//    g.DrawLine(Pens.Blue, mouseLocationXs, mouseLocationXe);//}}/// <summary>/// 当工具更换后,通知ToolBox更换工具/// </summary>/// <param name="tool"></param>protected void designer1_OnActiveToolChange(ToolBase tool){drawToolBox1.SelectTool = tool;}/// <summary>/// 设计器是对像删除事件/// </summary>protected void designer1_OnItemChange(){itemList1.DrawItems = designer1.Items;designer1_OnShowProperityInfo(designer1.Items.GetSelectItem(0));}/// <summary>/// 将对像的属性显示出来/// </summary>/// <param name="sender"></param>protected void designer1_OnShowProperityInfo(DrawItemBase sender){propertyGrid1.SelectedObject = sender;}/// <summary>/// 设置设计器当前的工具是?/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void drawToolBox1_ToolChanged(object sender, EventArgs e){designer1.ActiveTool = drawToolBox1.SelectTool;}/// <summary>/// 画出设计器的标尺/// </summary>/// <param name="sender"></param>/// <param name="e"></param>//private void panel1_Paint(object sender, PaintEventArgs e)//{//    DrawScale(e.Graphics);//}/// <summary>/// 当在属性列表中更新数据后及时更新设计器内容,让更改的内容显示出来/// </summary>/// <param name="s"></param>/// <param name="e"></param>private void propertyGrid1_PropertyValueChanged(object s, PropertyValueChangedEventArgs e){//如果所选的对像为DrawText修改值的时候要设置编辑输入框为不可见if (propertyGrid1.SelectedObject.GetType().Name == "DrawText"){designer1.textBox.Visible = false;designer1.textBox.Enabled = false;}designer1.Refresh();}#region 新建,打开,保存,删除,打印........../// <summary>/// 新建设计/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void tsNew_Click(object sender, EventArgs e){//先检查设计器里对像有没有修改,有则提示保存if (designer1.ChangeFlage){DialogResult dr = MessageBox.Show("是否保存设计?", "提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);if (dr == DialogResult.Yes){FileDialog fd = new SaveFileDialog();fd.Filter = "CraxyMouse file (*.CraxyMouse)|*.CraxyMouse";fd.InitialDirectory = Application.StartupPath;if (fd.ShowDialog() == DialogResult.OK){openFileName = fd.FileName;InOutPut.SaveFile(designer1, fd.FileName);}}else if (dr == DialogResult.Cancel){return;}//将状态设为没有修改过的designer1.ChangeFlage = false;}//清空对像designer1.Items.Clear();designer1.Refresh();openFileName = "";}/// <summary>/// 打开设计器中的对像/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void tsOpen_Click(object sender, EventArgs e){if (designer1.ChangeFlage){DialogResult dr = MessageBox.Show("是否保存更改?", "提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);if (dr == DialogResult.Yes){//如果有没有保存文件//则先保存文件if (string.IsNullOrEmpty(openFileName)){//检查当前的文件是否是保存过的//如没有保存则重新保存FileDialog fd = new SaveFileDialog();fd.Filter = "CraxyMouse file (*.CraxyMouse)|*.CraxyMouse";fd.InitialDirectory = Application.StartupPath;if (fd.ShowDialog() == DialogResult.OK){openFileName = fd.FileName;designer1.ChangeFlage = false;InOutPut.SaveFile(designer1, fd.FileName);designer1.Items.Clear();designer1.Refresh();}}else{//保存过的直接保存InOutPut.SaveFile(designer1, openFileName);}}else if (dr == DialogResult.Cancel){//如果用户取消了则什么也不做return;}designer1.ChangeFlage = false;}FileDialog fod = new OpenFileDialog();fod.Filter = "CraxyMouse file (*.CraxyMouse)|*.CraxyMouse";fod.InitialDirectory = Application.StartupPath;if (fod.ShowDialog() == DialogResult.OK){openFileName = fod.FileName;bool open = InOutPut.OpenFile(designer1, openFileName);//打开文件是否成功//如果打开成功是重新绘标尺if (open){panel1.Refresh();designer1_OnItemChange();numHeight.Value = (int)CommonSettings.PixelConvertMillimeter(designer1.Height);numWidth.Value = (int)CommonSettings.PixelConvertMillimeter(designer1.Width);if (designer1.RowHeight > 0){numRowHeight.Value = (int)CommonSettings.PixelConvertMillimeter(designer1.RowHeight);}if (designer1.PageRows > 0){numRows.Value = designer1.PageRows;}}}}/// <summary>/// 保存设计器中的对像/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void tsSave_Click(object sender, EventArgs e){if (string.IsNullOrEmpty(openFileName)){FileDialog fd = new SaveFileDialog();fd.Filter = "CraxyMouse file (*.CraxyMouse)|*.CraxyMouse";fd.InitialDirectory = Application.StartupPath;if (fd.ShowDialog() == DialogResult.OK){openFileName = fd.FileName;designer1.RowHeight = (int)CommonSettings.MillimeterConvertPixel((float)numRowHeight.Value);designer1.PageRows = (int)numRows.Value;InOutPut.SaveFile(designer1, fd.FileName);MessageBox.Show("保存文件成功!\n\r保存路径为:" + fd.FileName, "", MessageBoxButtons.OK, MessageBoxIcon.Information);//designer1.Items.Clear();designer1.Refresh();}}else{InOutPut.SaveFile(designer1, openFileName);}designer1.ChangeFlage = false;}/// <summary>/// 删除设计器中选中的对像/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void tsDelete_Click(object sender, EventArgs e){designer1.DeleteSelectedItem();}/// <summary>/// 置顶/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void tsTop_Click(object sender, EventArgs e){designer1.Items.SendFront();designer1.Refresh();designer1_OnItemChange();}/// <summary>/// 置底/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void tsBottom_Click(object sender, EventArgs e){designer1.Items.SendBlow();designer1.Refresh();designer1_OnItemChange();}/// <summary>/// 退出/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void tsExit_Click(object sender, EventArgs e){if (designer1.ChangeFlage && (MessageBox.Show("退出程序之前要保存设计吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)){tsSave_Click(sender, e);}if (MessageBox.Show("你确定要退出吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK){Application.Exit();}}/// <summary>/// 如果用户在对像列表中选择了对像,则更新到设计器中/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void itemList1_SelectedIndexChanged(object sender, EventArgs e){designer1.Items.UnSelectAll();designer1.Items[itemList1.SelectedIndex].Selected = true;propertyGrid1.SelectedObject = designer1.Items[itemList1.SelectedIndex];designer1.Refresh();}/// <summary>/// 打印预览/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void tsView_Click(object sender, EventArgs e){designer1.PrintView();}/// <summary>/// 关于/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void tsInfo_Click(object sender, EventArgs e){}/// <summary>/// 打印/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void tsPrint_Click(object sender, EventArgs e){DataTable dt = new DataTable();dt.Columns.Add("Pay");dt.Columns.Add("Receive");dt.Columns.Add("TaxNum");dt.Columns.Add("Item");dt.Columns.Add("Amount");dt.Columns.Add("Desc");DataRow dr = dt.NewRow();dr[0] = "徐春晓";dr[1] = "徐春晓";dr[2] = "9658258";dr[3] = "电脑-001";dr[4] = "10000";dr[5] = "已发货";dt.Rows.Add(dr);dr = dt.NewRow();dr[0] = "徐春晓1";dr[1] = "徐春晓1";dr[2] = "96582581";dr[3] = "电脑-002";dr[4] = "10000";dr[5] = "已发货1";dt.Rows.Add(dr);dr = dt.NewRow();dr[0] = "徐春晓2";dr[1] = "徐春晓2";dr[2] = "9658258";dr[3] = "电脑-002";dr[4] = "100002";dr[5] = "已发货2";dt.Rows.Add(dr);dr = dt.NewRow();dr[0] = "徐春晓3";dr[1] = "徐春晓3";dr[2] = "96582583";dr[3] = "电脑-003";dr[4] = "100003";dr[5] = "已发货3";dt.Rows.Add(dr);dr = dt.NewRow();dr[0] = "徐春晓4";dr[1] = "徐春晓4";dr[2] = "96582585";dr[3] = "电脑-0014";dr[4] = "100003";dr[5] = "已发货4";dt.Rows.Add(dr);designer1.DataSource = dt;designer1.PrintPage(1);}#endregion/// <summary>/// 改变设计的宽度/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void numWidth_ValueChanged(object sender, EventArgs e){//改变设计器的尺寸并重绘标尺designer1.Width = CommonSettings.MillimeterConvertPixel((float)numWidth.Value);panel1.Refresh();}private void numHeight_ValueChanged(object sender, EventArgs e){//改变设计器的尺寸并重绘标尺designer1.Height = CommonSettings.MillimeterConvertPixel((float)numHeight.Value);panel1.Refresh();}/// <summary>/// 设计每页有多少行/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void numRows_ValueChanged(object sender, EventArgs e){designer1.PageRows = (int)numRows.Value;}/// <summary>/// 设置行高/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void numRowHeight_ValueChanged(object sender, EventArgs e){designer1.RowHeight = CommonSettings.MillimeterConvertPixel((float)numRowHeight.Value);}/// <summary>/// 打印设置 /// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void tsSet_Click(object sender, EventArgs e){frmSetting fs = new frmSetting(designer1.PrinterConfig);fs.ShowDialog();}/// <summary>/// 对像列表按键事件/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void itemList1_KeyDown(object sender, KeyEventArgs e){if (e.KeyCode == Keys.Delete){designer1.DeleteSelectedItem();designer1.Refresh();}}private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e){}/// <summary>/// 滚动条拖动时更新机标尺/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void panel3_Scroll(object sender, ScrollEventArgs e){if (e.ScrollOrientation == ScrollOrientation.HorizontalScroll)//水平尺{ruler1.StartValue = (int)CommonSettings.PixelConvertMillimeter(GetScrollValue(e.NewValue, e.OldValue));}else//垂直尺{ruler2.StartValue = (int)CommonSettings.PixelConvertMillimeter(GetScrollValue(e.NewValue, e.OldValue));}}/// <summary>/// 获取拖动的最小值做为标尺的起动值/// </summary>/// <param name="newvalue"></param>/// <param name="oldvalue"></param>/// <returns></returns>private int GetScrollValue(int newvalue, int oldvalue){if (newvalue > oldvalue){return oldvalue;}return newvalue;}/// <summary>/// 显示标尺/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void tsGrid_Click(object sender, EventArgs e){designer1.ShowGrid = !designer1.ShowGrid;if (designer1.ShowGrid){tsGrid.CheckState = CheckState.Indeterminate;}else{tsGrid.CheckState = CheckState.Unchecked;}}}
}

5、打印设计软件运行界面及效果

项目资源获取

https://download.csdn.net/download/xdpcxq/89274784

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/7955.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Springboot 集成 Consul 实现服务注册中心-05

因为后续很多模块都要用到注册中心&#xff0c;所以此处先实现此模块。 Consul简介 Consul是一个开源的服务发现和配置管理工具&#xff0c;具有跨平台、运行高效等特点。它由HashiCorp公司开发&#xff0c;并使用Go语言编写。Consul主要用于实现分布式系统中的服务发现、健康…

解决Node.js mysql客户端不支持认证协议引发的“ER_NOT_SUPPORTED_AUTH_MODE”问题

这是一个版本问题 我用koa2和mysql2链接就没有问题 不知道这个老项目运行为啥有这个问题 解决方案 打开mysql运行这个两个命令&#xff1a; ALTER USER rootlocalhost IDENTIFIED WITH mysql_native_password BY 123321; FLUSH PRIVILEGES; 须知(给小白看的&#xff01;) …

优立科技:从数字孪生到元宇宙

2021年10月&#xff0c;Facebook致力于发展元宇宙&#xff0c;并更名为Meta。加上此前Roblox上市的消息&#xff0c;让「元宇宙」一词迅速在2021年爆火&#xff0c;刺激了VR、游戏等相关产业的发展&#xff0c;甚至有人宣称2021年为「元宇宙『元年』」。然而&#xff0c;「元年…

YOLOv8的训练、验证、预测及导出[目标检测实践篇]

这一部分内容主要介绍如何使用YOLOv8训练自己的数据集&#xff0c;并进行验证、预测及导出&#xff0c;采用代码和指令的两种方式&#xff0c;参考自官方文档&#xff1a;Detect - Ultralytics YOLOv8 Docs。实践篇不需要关注原理&#xff0c;只需要把流程跑通就行&#xff0c;…

信号产生的五种方式

文章目录 正文前的知识准备kill 命令查看信号man手册查看信号信号的处理方法 认识信号产生的5种方式1. 工具2. 键盘3. 系统调用kill 向任意进程发送任意信号raise 给调用方发送任意信号abort 给调用方发送SIGABRT信号 4. 软件条件5. 异常 正文前的知识准备 kill 命令查看信号 …

构建 WebRTC 一对一信令服务器

构建 WebRTC 一对一信令服务器 构建 WebRTC 一对一信令服务器前言为什么选择 Nodejs&#xff1f;Nodejs 的基本原理浏览器使用 Nodejs安装 Nodejs 和 NPMsocket.io信令服务器搭建信令服务器客户端服务端启动服务器并测试 总结参考 构建 WebRTC 一对一信令服务器 前言 我们在学…

Jmeter页面汉化和字体显示过小调整

在频繁解压使用Jmeter的时候&#xff0c;经常会遇到需要将页面的英文调整为中文&#xff0c;页面文字和编辑区域内容文字显示较小的问题&#xff0c;记录一下方便以后查阅。 1.页面汉化 Jmeter在解压启动之后页面显示是英文&#xff0c;如果需要修改为中文&#xff0c;可以修改…

uniapp的app端软件更新弹框

1&#xff1a;使用html PLUS实现&#xff1a;地址HTML5 API Reference (html5plus.org)&#xff0c;效果图 2&#xff1a;在app.vue的onLaunch生命周期中&#xff0c;代码如下&#xff1a; onLaunch: function() {let a 0let view new plus.nativeObj.View(maskView, {backg…

YOLOv5改进 | 主干篇 | 2024.5全新的移动端网络MobileNetV4改进YOLOv5(含MobileNetV4全部版本改进)

一、本文介绍 本文给大家带来的改进机制是MobileNetV4&#xff0c;其发布时间是2024.5月。MobileNetV4是一种高度优化的神经网络架构&#xff0c;专为移动设备设计。它最新的改动总结主要有两点&#xff0c;采用了通用反向瓶颈&#xff08;UIB&#xff09;和针对移动加速器优化…

AI烟雾监测识别摄像机:智能化安全防范的新利器

随着现代社会的不断发展&#xff0c;人们对于安全问题的关注日益增加&#xff0c;尤其是在日常生活和工作中&#xff0c;对火灾等意外事件的预防成为了一项重要任务。为了更好地应对火灾风险&#xff0c;近年来&#xff0c;AI烟雾监测识别摄像机应运而生&#xff0c;成为智能化…

【深度学习】实验1 波士顿房价预测

波士顿房价预测 代码 import numpy as np import matplotlib.pyplot as pltdef load_data():# 1.从文件导入数据datafile D:\Python\PythonProject\sklearn\housing.datadata np.fromfile(datafile, sep )# 每条数据包括14项&#xff0c;其中前面13项是影响因素&#xff0c…

微软正在自主构建一个名为 MAI-1 的大型语言模型(不依赖 OpenAI)

每周跟踪AI热点新闻动向和震撼发展 想要探索生成式人工智能的前沿进展吗&#xff1f;订阅我们的简报&#xff0c;深入解析最新的技术突破、实际应用案例和未来的趋势。与全球数同行一同&#xff0c;从行业内部的深度分析和实用指南中受益。不要错过这个机会&#xff0c;成为AI领…

所向披靡のmakefile

在VS里敲代码&#xff0c;只需要FnF5就可以直接运行勒&#xff0c;在Linux下敲代码却要即敲命令还要用编辑器还要用编译器&#xff0c;那在Linux下有没有能帮我们进行自动化组建的工具呢&#xff1f; 当然有&#xff0c;超级巨星&#xff1a;makefile&#xff01;&#xff01;…

Dropout作为贝叶斯近似: 表示深度学习中的模型不确定性

摘要 深度学习工具在应用机器学习领域受到了极大的关注。然而&#xff0c;这些用于回归和分类的工具并没有捕捉到模型的不确定性。相比之下&#xff0c;贝叶斯模型提供了一个基于数学的框架来推理模型的不确定性&#xff0c;但通常会带来令人望而却步的计算成本。本文提出了一…

面试中算法(删去n个数字后的最小值)

有一个整数&#xff0c;从该整数中去掉n个数字&#xff0c;要求剩下的数字形成的新整数尽可能小。 分析&#xff1a;使用栈的特性&#xff0c;在遍历原整数的数字时&#xff0c;让所有数字一个一个入栈&#xff0c;当某个数字需要被删除时&#xff0c;&#xff08;即栈顶数字&g…

【记录】Python3| 将 PDF 转换成 HTML/XML(✅⭐PyMuPDF+tqdm)

本文将会被汇总至 【记录】Python3&#xff5c;2024年 PDF 转 XML 或 HTML 的第三方库的使用方式、测评过程以及对比结果&#xff08;汇总&#xff09;&#xff0c;更多其他工具请访问该文章查看。 文章目录 PyMuPDF 使用体验与评估1 安装指南2 测试代码3 测试结果3.1 转 HTML …

Git与GitHub交互

注册 https://github.com/ 本地库与远程库交互方式 创建本地库并提交文件 创建远程库 在本地库创建远程库地址别名 查看现有远程库地址的别名 git remote -v 创建远程库地址别名 git remote add [别名] [远程地址] 远程路地址位置 示例 成员1推送 git push [别名] [分支…

文心一言 VS 讯飞星火 VS chatgpt (254)-- 算法导论18.2 7题

七、假设磁盘硬件允许我们任意选择磁盘页面的大小&#xff0c;但读取磁盘页面的时间是 abt 其中 a 和 b 为规定的常数&#xff0c;t 为确定磁盘页大小后的 B 树的最小度数。请描述如何选择 t 以(近似地)最小化 B 树的查找时间。对 a5ms 和 b10ms &#xff0c;请给出 t 的一个最…

使用图网络和视频嵌入预测物理场

文章目录 一、说明二、为什么要预测&#xff1f;三、流体动力学模拟的可视化四、DeepMind神经网络建模五、图形编码六、图形处理器七、图形解码器八、具有不同弹簧常数的轨迹可视化九、预测的物理编码和推出轨迹 一、说明 这是一篇国外流体力学专家在可视化流体物理属性的设计…

阿里云CentOS 7.9 64位 Liunx 安装redis

具体的步骤如下&#xff1a; 添加 EPEL 仓库&#xff0c;因为 Redis 在标准的 CentOS 仓库中不可用&#xff1a; sudo yum install epel-release安装 Redis&#xff1a; sudo yum install redis启动 Redis 服务&#xff1a; sudo systemctl start redis如果你想让 Redis 在…