Browse Source

重构 UButton 和 weightControl

master
yibo 7 years ago
parent
commit
d8f66d1a82
11 changed files with 563 additions and 85 deletions
  1. +70
    -53
      Test/Form1.Designer.cs
  2. +6
    -6
      Test/Form1.resx
  3. +96
    -0
      Test/Form2.Designer.cs
  4. +52
    -0
      Test/Form2.cs
  5. +120
    -0
      Test/Form2.resx
  6. +71
    -3
      Test/Program.cs
  7. +58
    -0
      Test/TBtn.cs
  8. +15
    -0
      Test/Test.csproj
  9. +36
    -1
      WinFormControl/UButton.cs
  10. +27
    -18
      WinFormControl/UWeightControl.Designer.cs
  11. +12
    -4
      WinFormControl/UWeightControl.resx

+ 70
- 53
Test/Form1.Designer.cs View File

@ -28,18 +28,19 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.comboBox1 = new System.Windows.Forms.ComboBox(); this.comboBox1 = new System.Windows.Forms.ComboBox();
this.uButton1 = new WinFormControl.UButton();
this.uScanPanel1 = new WinFormControl.UScanPanel();
this.uTimerLabel1 = new WinFormControl.UTimerLabel();
this.uWeightControl1 = new WinFormControl.UWeightControl();
this.uDataGridView1 = new WinFormControl.UDataGridView(); this.uDataGridView1 = new WinFormControl.UDataGridView();
this.RID = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.RID = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.RName = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.RName = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.uWeightControl1 = new WinFormControl.UWeightControl();
this.uTimerLabel1 = new WinFormControl.UTimerLabel();
this.uButton1 = new WinFormControl.UButton();
this.uScanPanel1 = new WinFormControl.UScanPanel();
this.tBtn1 = new Test.TBtn();
((System.ComponentModel.ISupportInitialize)(this.uDataGridView1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.uDataGridView1)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
@ -52,54 +53,6 @@
this.comboBox1.Size = new System.Drawing.Size(121, 28); this.comboBox1.Size = new System.Drawing.Size(121, 28);
this.comboBox1.TabIndex = 3; this.comboBox1.TabIndex = 3;
// //
// uButton1
//
this.uButton1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("uButton1.BackgroundImage")));
this.uButton1.FlatAppearance.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(45)))), ((int)(((byte)(155)))), ((int)(((byte)(214)))));
this.uButton1.FlatAppearance.BorderSize = 0;
this.uButton1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.uButton1.ForeColor = System.Drawing.Color.Black;
this.uButton1.Location = new System.Drawing.Point(254, 239);
this.uButton1.Name = "uButton1";
this.uButton1.PlaySound = true;
this.uButton1.Size = new System.Drawing.Size(130, 47);
this.uButton1.SoundType = WinFormControl.SoundType.Di;
this.uButton1.TabIndex = 2;
this.uButton1.Text = "uButton1";
this.uButton1.UseVisualStyleBackColor = true;
this.uButton1.Click += new System.EventHandler(this.uButton1_Click);
//
// uScanPanel1
//
this.uScanPanel1.BackColor = System.Drawing.Color.Transparent;
this.uScanPanel1.Location = new System.Drawing.Point(101, 182);
this.uScanPanel1.Name = "uScanPanel1";
this.uScanPanel1.Size = new System.Drawing.Size(303, 32);
this.uScanPanel1.TabIndex = 1;
this.uScanPanel1.BeforeScan += new System.Action(this.uScanPanel1_BeforeScan);
this.uScanPanel1.AfterScan += new System.Action(this.uScanPanel1_AfterScan);
//
// uTimerLabel1
//
this.uTimerLabel1.AutoSize = true;
this.uTimerLabel1.BackColor = System.Drawing.Color.Transparent;
this.uTimerLabel1.Font = new System.Drawing.Font("宋体", 15F);
this.uTimerLabel1.Format = "M月d日 H:m:s";
this.uTimerLabel1.Location = new System.Drawing.Point(315, 124);
this.uTimerLabel1.Name = "uTimerLabel1";
this.uTimerLabel1.Size = new System.Drawing.Size(159, 20);
this.uTimerLabel1.TabIndex = 4;
this.uTimerLabel1.Text = "3月30日 11:37:0";
//
// uWeightControl1
//
this.uWeightControl1.BackColor = System.Drawing.Color.Transparent;
this.uWeightControl1.Location = new System.Drawing.Point(12, 12);
this.uWeightControl1.Name = "uWeightControl1";
this.uWeightControl1.Size = new System.Drawing.Size(349, 78);
this.uWeightControl1.TabIndex = 5;
this.uWeightControl1.WeightFalg = null;
//
// uDataGridView1 // uDataGridView1
// //
this.uDataGridView1.AllowUserToAddRows = false; this.uDataGridView1.AllowUserToAddRows = false;
@ -148,12 +101,75 @@
this.RName.Name = "RName"; this.RName.Name = "RName";
this.RName.ReadOnly = true; this.RName.ReadOnly = true;
// //
// uWeightControl1
//
this.uWeightControl1.BackColor = System.Drawing.Color.Transparent;
this.uWeightControl1.Location = new System.Drawing.Point(12, 12);
this.uWeightControl1.Name = "uWeightControl1";
this.uWeightControl1.Size = new System.Drawing.Size(349, 78);
this.uWeightControl1.TabIndex = 5;
this.uWeightControl1.WeightFalg = null;
//
// uTimerLabel1
//
this.uTimerLabel1.AutoSize = true;
this.uTimerLabel1.BackColor = System.Drawing.Color.Transparent;
this.uTimerLabel1.Font = new System.Drawing.Font("宋体", 15F);
this.uTimerLabel1.Format = "M月d日 H:m:s";
this.uTimerLabel1.Location = new System.Drawing.Point(315, 124);
this.uTimerLabel1.Name = "uTimerLabel1";
this.uTimerLabel1.Size = new System.Drawing.Size(139, 20);
this.uTimerLabel1.TabIndex = 4;
this.uTimerLabel1.Text = "4月3日 9:37:9";
//
// uButton1
//
this.uButton1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("uButton1.BackgroundImage")));
this.uButton1.FlatAppearance.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(45)))), ((int)(((byte)(155)))), ((int)(((byte)(214)))));
this.uButton1.FlatAppearance.BorderSize = 0;
this.uButton1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.uButton1.ForeColor = System.Drawing.Color.Black;
this.uButton1.Location = new System.Drawing.Point(254, 239);
this.uButton1.Name = "uButton1";
this.uButton1.PlaySound = true;
this.uButton1.Size = new System.Drawing.Size(130, 47);
this.uButton1.SoundType = WinFormControl.SoundType.Di;
this.uButton1.TabIndex = 2;
this.uButton1.Text = "uButton1";
this.uButton1.UseVisualStyleBackColor = true;
this.uButton1.Click += new System.EventHandler(this.uButton1_Click);
//
// uScanPanel1
//
this.uScanPanel1.BackColor = System.Drawing.Color.Transparent;
this.uScanPanel1.Location = new System.Drawing.Point(101, 182);
this.uScanPanel1.Name = "uScanPanel1";
this.uScanPanel1.Size = new System.Drawing.Size(303, 32);
this.uScanPanel1.TabIndex = 1;
this.uScanPanel1.BeforeScan += new System.Action(this.uScanPanel1_BeforeScan);
this.uScanPanel1.AfterScan += new System.Action(this.uScanPanel1_AfterScan);
//
// tBtn1
//
this.tBtn1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(51)))), ((int)(((byte)(133)))), ((int)(((byte)(255)))));
this.tBtn1.FlatAppearance.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(45)))), ((int)(((byte)(204)))), ((int)(((byte)(112)))));
this.tBtn1.FlatAppearance.BorderSize = 0;
this.tBtn1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.tBtn1.ForeColor = System.Drawing.Color.White;
this.tBtn1.Location = new System.Drawing.Point(372, 310);
this.tBtn1.Name = "tBtn1";
this.tBtn1.Size = new System.Drawing.Size(181, 69);
this.tBtn1.TabIndex = 7;
this.tBtn1.Text = "tBtn1";
this.tBtn1.UseVisualStyleBackColor = false;
//
// Form1 // Form1
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.White; this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(922, 453); this.ClientSize = new System.Drawing.Size(922, 453);
this.Controls.Add(this.tBtn1);
this.Controls.Add(this.uDataGridView1); this.Controls.Add(this.uDataGridView1);
this.Controls.Add(this.uWeightControl1); this.Controls.Add(this.uWeightControl1);
this.Controls.Add(this.uTimerLabel1); this.Controls.Add(this.uTimerLabel1);
@ -179,5 +195,6 @@
private WinFormControl.UDataGridView uDataGridView1; private WinFormControl.UDataGridView uDataGridView1;
private System.Windows.Forms.DataGridViewTextBoxColumn RID; private System.Windows.Forms.DataGridViewTextBoxColumn RID;
private System.Windows.Forms.DataGridViewTextBoxColumn RName; private System.Windows.Forms.DataGridViewTextBoxColumn RName;
private TBtn tBtn1;
} }
} }

+ 6
- 6
Test/Form1.resx View File

@ -117,6 +117,12 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="RID.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="RName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> <assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="uButton1.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> <data name="uButton1.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value> <value>
@ -126,10 +132,4 @@
KAgKgoKg1ZsPvpCB0hBohjQAAAAASUVORK5CYII= KAgKgoKg1ZsPvpCB0hBohjQAAAAASUVORK5CYII=
</value> </value>
</data> </data>
<metadata name="RID.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="RName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root> </root>

+ 96
- 0
Test/Form2.Designer.cs View File

@ -0,0 +1,96 @@
namespace Test
{
partial class Form2
{
/// <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.panel1 = new System.Windows.Forms.Panel();
this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
this.panel2 = new System.Windows.Forms.Panel();
this.flowLayoutPanel2 = new System.Windows.Forms.FlowLayoutPanel();
this.panel1.SuspendLayout();
this.panel2.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panel1.Controls.Add(this.flowLayoutPanel1);
this.panel1.Location = new System.Drawing.Point(44, 35);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(265, 424);
this.panel1.TabIndex = 0;
//
// flowLayoutPanel1
//
this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.flowLayoutPanel1.Location = new System.Drawing.Point(0, 0);
this.flowLayoutPanel1.Name = "flowLayoutPanel1";
this.flowLayoutPanel1.Size = new System.Drawing.Size(263, 422);
this.flowLayoutPanel1.TabIndex = 0;
//
// panel2
//
this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panel2.Controls.Add(this.flowLayoutPanel2);
this.panel2.Location = new System.Drawing.Point(374, 36);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(265, 424);
this.panel2.TabIndex = 1;
//
// flowLayoutPanel2
//
this.flowLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Fill;
this.flowLayoutPanel2.Location = new System.Drawing.Point(0, 0);
this.flowLayoutPanel2.Name = "flowLayoutPanel2";
this.flowLayoutPanel2.Size = new System.Drawing.Size(263, 422);
this.flowLayoutPanel2.TabIndex = 0;
//
// Form2
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(679, 501);
this.Controls.Add(this.panel2);
this.Controls.Add(this.panel1);
this.Name = "Form2";
this.Text = "Form2";
this.panel1.ResumeLayout(false);
this.panel2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel2;
}
}

+ 52
- 0
Test/Form2.cs View File

@ -0,0 +1,52 @@
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;
using WinFormControl;
namespace Test
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
for (var i = 0; i < 10; i++)
{
var btn = new TBtn() { Text = "鲜品白条一级", Width = 90, Height = 55, Margin = new Padding(8, 14, 8, 0), };
flowLayoutPanel1.Controls.Add(btn);
}
for (var i = 0; i < 10; i++)
{
var btn = new UButton() { Text = "鲜品白条一级", Width = 90, Height = 55, Margin = new Padding(8, 14, 8, 0), WithStataHode = true };
if (i % 3 == 0)
btn.AsClicked = true;
if (i == 5)
{
btn.WithStataHode = true;
btn.Click += delegate
{
System.Threading.Thread.Sleep(2000);
};
}
if (i == 8)
{
btn.WithStataHode = true;
btn.Click += delegate
{
throw new Exception("error");
};
}
flowLayoutPanel2.Controls.Add(btn);
}
}
}
}

+ 120
- 0
Test/Form2.resx View File

@ -0,0 +1,120 @@
<?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>

+ 71
- 3
Test/Program.cs View File

@ -1,8 +1,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using WinFormControl;
namespace Test namespace Test
{ {
@ -14,9 +17,74 @@ namespace Test
[STAThread] [STAThread]
static void Main() static void Main()
{ {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
try
{
//处理未捕获的异常
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
//处理UI线程异常
Application.ThreadException += Application_ThreadException;
//处理非UI线程异常
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
var aProcessName = Process.GetCurrentProcess().ProcessName;
if ((Process.GetProcessesByName(aProcessName)).GetUpperBound(0) > 0)
{
SoundPalyUtil.PlaySound(SoundType.Error);
UMessageBox.Show(@"系统已经在运行中,如果要重新启动,请从进程中关闭...", @"系统警告");
}
else
{
// Mapper.Initialize(cfg => {
// cfg.AddProfile<AppProfile>();
// cfg.CreateMap<Source, Dest>();
// });
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form2());
}
}
catch (Exception e)
{
// LogUtil.WriteError(e);
SoundPalyUtil.PlaySound(SoundType.Error);
UMessageBox.Show("错误:" + e.Message + " \n详细信息:" + e.StackTrace);
//UMessageBox.Show("错误:" + e.Message );
}
}
///<summary>
/// 在发生未处理异常时处理的方法
///</summary>
///<param name="sender"> </param>
///<param name="e"> </param>
private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{
var ex = e.Exception;
var err = String.Empty;
if (ex != null)
{
//LogUtil.WriteError(ex);
err = ex.Message;
}
SoundPalyUtil.PlaySound(SoundType.Error);
UMessageBox.Show("错误:" + ex.Message + " \n详细信息:" + ex.StackTrace);
// UMessageBox.Show("错误:" + err);
}
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
var err = String.Empty;
var ex = e.ExceptionObject as Exception;
if (ex != null)
{
//LogUtil.WriteError(ex);
err = ex.Message;
}
SoundPalyUtil.PlaySound(SoundType.Error);
UMessageBox.Show("错误:" + ex.Message + " \n详细信息:" + ex.StackTrace);
//UMessageBox.Show("错误:" + err);
} }
} }
} }

+ 58
- 0
Test/TBtn.cs View File

@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Test
{
class TBtn : Button
{
public TBtn()
{
//this.UseVisualStyleBackColor = true;
this.BackColor = Color.FromArgb(51, 133, 255);
this.ForeColor = Color.White;
this.FlatStyle = FlatStyle.Flat;
this.FlatAppearance.BorderSize = 0;
this.FlatAppearance.BorderColor = Color.FromArgb(45, 204, 112);
}
protected override void OnMouseDown(MouseEventArgs mevent)
{
if (mevent.Button == MouseButtons.Left)
{
this.BackColor = Color.Red;
}
base.OnMouseDown(mevent);
}
protected override void OnClick(EventArgs e)
{
try
{
this.Enabled = false;
base.OnClick(e);
}
finally
{
this.Enabled = true;
}
}
protected override void OnEnabledChanged(EventArgs e)
{
base.OnEnabledChanged(e);
if (Enabled)
{
this.BackColor = Color.FromArgb(51, 133, 255);
}
else
{
this.BackColor = Color.FromArgb(209, 213, 216);
}
}
}
}

+ 15
- 0
Test/Test.csproj View File

@ -43,6 +43,9 @@
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="Test">
<HintPath>obj\Debug\Test.exe</HintPath>
</Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Form1.cs"> <Compile Include="Form1.cs">
@ -51,11 +54,23 @@
<Compile Include="Form1.Designer.cs"> <Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon> <DependentUpon>Form1.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Form2.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form2.Designer.cs">
<DependentUpon>Form2.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TBtn.cs">
<SubType>Component</SubType>
</Compile>
<EmbeddedResource Include="Form1.resx"> <EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon> <DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="Form2.resx">
<DependentUpon>Form2.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx"> <EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator> <Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput> <LastGenOutput>Resources.Designer.cs</LastGenOutput>


+ 36
- 1
WinFormControl/UButton.cs View File

@ -27,6 +27,38 @@ namespace WinFormControl
[Browsable(true), Category("Sound"), Description("声音类型")] [Browsable(true), Category("Sound"), Description("声音类型")]
public SoundType SoundType { get; set; } public SoundType SoundType { get; set; }
[Browsable(true), Description("状态保持")]
public bool WithStataHode { get; set; }
private bool clicked;
public bool AsClicked
{
get { return clicked; }
set
{
if (clicked == value)
return;
clicked = value;
AsClickedChanged();
}
}
void AsClickedChanged()
{
if (!WithStataHode)
return;
if (clicked)
{
this.BackgroundImage = Resources.onclickBtn;
this.ForeColor = Color.White;
}
else
{
this.BackgroundImage = Resources.simpleBtn;
this.ForeColor = Color.Black;
}
}
protected override void OnMouseDown(MouseEventArgs mevent) protected override void OnMouseDown(MouseEventArgs mevent)
{ {
if (mevent.Button == MouseButtons.Left) if (mevent.Button == MouseButtons.Left)
@ -45,10 +77,13 @@ namespace WinFormControl
if (PlaySound) if (PlaySound)
SoundPalyUtil.PlaySound(SoundType); SoundPalyUtil.PlaySound(SoundType);
base.OnClick(e); base.OnClick(e);
this.Enabled = true;
AsClicked = !clicked;
} }
finally
catch
{ {
this.Enabled = true; this.Enabled = true;
throw;
} }
} }


+ 27
- 18
WinFormControl/UWeightControl.Designer.cs View File

@ -29,28 +29,13 @@
private void InitializeComponent() private void InitializeComponent()
{ {
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(UWeightControl)); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(UWeightControl));
this.weightSwitch = new System.Windows.Forms.Button();
this.panel2 = new System.Windows.Forms.Panel(); this.panel2 = new System.Windows.Forms.Panel();
this.lblChengZhong = new System.Windows.Forms.Label(); this.lblChengZhong = new System.Windows.Forms.Label();
this.weightSwitch = new WinFormControl.UButton();
this.settingBtn = new WinFormControl.UButton(); this.settingBtn = new WinFormControl.UButton();
this.panel2.SuspendLayout(); this.panel2.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// weightSwitch
//
this.weightSwitch.BackColor = System.Drawing.Color.Transparent;
this.weightSwitch.BackgroundImage = global::WinFormControl.Properties.Resources.simpleBtn;
this.weightSwitch.FlatAppearance.BorderSize = 0;
this.weightSwitch.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.weightSwitch.Font = new System.Drawing.Font("宋体", 15F);
this.weightSwitch.Location = new System.Drawing.Point(231, 43);
this.weightSwitch.Name = "weightSwitch";
this.weightSwitch.Size = new System.Drawing.Size(111, 34);
this.weightSwitch.TabIndex = 2;
this.weightSwitch.Text = "启用称重";
this.weightSwitch.UseVisualStyleBackColor = false;
this.weightSwitch.Click += new System.EventHandler(this.weightSwitch_Click);
//
// panel2 // panel2
// //
this.panel2.BackColor = System.Drawing.Color.Black; this.panel2.BackColor = System.Drawing.Color.Black;
@ -71,8 +56,29 @@
this.lblChengZhong.TabIndex = 0; this.lblChengZhong.TabIndex = 0;
this.lblChengZhong.Text = "0.00"; this.lblChengZhong.Text = "0.00";
// //
// weightSwitch
//
this.weightSwitch.AsClicked = false;
this.weightSwitch.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("weightSwitch.BackgroundImage")));
this.weightSwitch.FlatAppearance.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(45)))), ((int)(((byte)(155)))), ((int)(((byte)(214)))));
this.weightSwitch.FlatAppearance.BorderSize = 0;
this.weightSwitch.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.weightSwitch.Font = new System.Drawing.Font("宋体", 15F);
this.weightSwitch.ForeColor = System.Drawing.Color.Black;
this.weightSwitch.Location = new System.Drawing.Point(231, 43);
this.weightSwitch.Name = "weightSwitch";
this.weightSwitch.PlaySound = false;
this.weightSwitch.Size = new System.Drawing.Size(111, 34);
this.weightSwitch.SoundType = WinFormControl.SoundType.Click;
this.weightSwitch.TabIndex = 2;
this.weightSwitch.Text = "启用称重";
this.weightSwitch.UseVisualStyleBackColor = true;
this.weightSwitch.WithStataHode = true;
this.weightSwitch.Click += new System.EventHandler(this.weightSwitch_Click);
//
// settingBtn // settingBtn
// //
this.settingBtn.AsClicked = false;
this.settingBtn.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("settingBtn.BackgroundImage"))); this.settingBtn.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("settingBtn.BackgroundImage")));
this.settingBtn.FlatAppearance.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(45)))), ((int)(((byte)(155)))), ((int)(((byte)(214))))); this.settingBtn.FlatAppearance.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(45)))), ((int)(((byte)(155)))), ((int)(((byte)(214)))));
this.settingBtn.FlatAppearance.BorderSize = 0; this.settingBtn.FlatAppearance.BorderSize = 0;
@ -81,10 +87,13 @@
this.settingBtn.ForeColor = System.Drawing.Color.Black; this.settingBtn.ForeColor = System.Drawing.Color.Black;
this.settingBtn.Location = new System.Drawing.Point(231, 0); this.settingBtn.Location = new System.Drawing.Point(231, 0);
this.settingBtn.Name = "settingBtn"; this.settingBtn.Name = "settingBtn";
this.settingBtn.PlaySound = false;
this.settingBtn.Size = new System.Drawing.Size(111, 34); this.settingBtn.Size = new System.Drawing.Size(111, 34);
this.settingBtn.SoundType = WinFormControl.SoundType.Click;
this.settingBtn.TabIndex = 41; this.settingBtn.TabIndex = 41;
this.settingBtn.Text = "称 设 置"; this.settingBtn.Text = "称 设 置";
this.settingBtn.UseVisualStyleBackColor = true; this.settingBtn.UseVisualStyleBackColor = true;
this.settingBtn.WithStataHode = false;
this.settingBtn.Click += new System.EventHandler(this.settingBtn_Click); this.settingBtn.Click += new System.EventHandler(this.settingBtn_Click);
// //
// UWeightControl // UWeightControl
@ -92,9 +101,9 @@
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.Transparent; this.BackColor = System.Drawing.Color.Transparent;
this.Controls.Add(this.weightSwitch);
this.Controls.Add(this.settingBtn); this.Controls.Add(this.settingBtn);
this.Controls.Add(this.panel2); this.Controls.Add(this.panel2);
this.Controls.Add(this.weightSwitch);
this.Name = "UWeightControl"; this.Name = "UWeightControl";
this.Size = new System.Drawing.Size(349, 78); this.Size = new System.Drawing.Size(349, 78);
this.panel2.ResumeLayout(false); this.panel2.ResumeLayout(false);
@ -105,9 +114,9 @@
#endregion #endregion
private System.Windows.Forms.Button weightSwitch;
private System.Windows.Forms.Panel panel2; private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.Label lblChengZhong; private System.Windows.Forms.Label lblChengZhong;
private UButton settingBtn; private UButton settingBtn;
private UButton weightSwitch;
} }
} }

+ 12
- 4
WinFormControl/UWeightControl.resx View File

@ -117,19 +117,27 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="weightSwitch.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="panel2.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="panel2.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value> <value>True</value>
</metadata> </metadata>
<metadata name="lblChengZhong.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="lblChengZhong.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value> <value>True</value>
</metadata> </metadata>
<metadata name="settingBtn.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<metadata name="weightSwitch.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value> <value>True</value>
</metadata> </metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> <assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="weightSwitch.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>
iVBORw0KGgoAAAANSUhEUgAAAGAAAAAwCAIAAABhdOiYAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO
wwAADsMBx2+oZAAAAHNJREFUaEPt0AENACAMwDAkowVB14aDz0CTKui5b1gICoKCoCAoCAqCgqAgKAgK
goKgICgICoKCoCAoCAqCgqAgKAgKgoKgICgICoKCoCAoCAqCgqAgKAgKgoKgICgICoKCoCAoCAqCgqAg
KAgKgoKg1ZsPvpCB0hBohjQAAAAASUVORK5CYII=
</value>
</data>
<metadata name="settingBtn.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<data name="settingBtn.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> <data name="settingBtn.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value> <value>
iVBORw0KGgoAAAANSUhEUgAAAGAAAAAwCAIAAABhdOiYAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO iVBORw0KGgoAAAANSUhEUgAAAGAAAAAwCAIAAABhdOiYAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO


Loading…
Cancel
Save