📄 minecountcontrol.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace MineClearance
{
/// <summary>
/// Summary description for MineCountControl1.
/// </summary>
public class MineCountControl : System.Windows.Forms.UserControl
{
private System.ComponentModel.IContainer components;
private System.Windows.Forms.Label label1;
private int MineCount;
public int mineCount
{
get
{
return MineCount;
}
set
{
if(-99 <= MineCount && MineCount <= 99 && MineCount != value)
{
MineCount = value;
ReDraw();
}
}
}
public MineCountControl()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
// TODO: Add any initialization after the InitForm call
this.Size = new Size(48, 24);
MineCount = 0;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Component 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.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right);
this.label1.BackColor = System.Drawing.Color.Gainsboro;
this.label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label1.ForeColor = System.Drawing.Color.Red;
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(48, 24);
this.label1.TabIndex = 0;
this.label1.Text = "000";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// MineCountControl1
//
this.BackColor = System.Drawing.Color.Gainsboro;
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.label1});
this.Name = "MineCountControl1";
this.Size = new System.Drawing.Size(48, 24);
this.ResumeLayout(false);
}
#endregion
public void ReDraw()
{
label1.Text = Math.Abs(MineCount).ToString();
for(int maxi = (MineCount < 0)? 2: 3; label1.Text.Length < maxi; )
{
label1.Text = "0" + label1.Text;
}
if(MineCount < 0)
{
label1.Text = "-" + label1.Text;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -