📄 numberpicker.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace WATestPGB
{
/// <summary>
/// This is the main class for the NumberPicker control
/// </summary>
public class NumberPicker : System.Windows.Forms.UserControl
{
private System.Windows.Forms.TextBox textBoxNumber;
private Button button1;
private string Node_SQL;
private string GidView_SQL;
private string Cnn_SQL;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
/// <summary>
/// The default constructor for the NumberPicker control
/// </summary>
public NumberPicker()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
Node_SQL = "";
GidView_SQL = "";
Cnn_SQL = "";
}
/// <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.textBoxNumber = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBoxNumber
//
this.textBoxNumber.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.textBoxNumber.Location = new System.Drawing.Point(0, 0);
this.textBoxNumber.Name = "textBoxNumber";
this.textBoxNumber.Size = new System.Drawing.Size(119, 21);
this.textBoxNumber.TabIndex = 1;
this.textBoxNumber.DoubleClick += new System.EventHandler(this.button1_Click);
//
// button1
//
this.button1.BackColor = System.Drawing.SystemColors.ButtonFace;
this.button1.Dock = System.Windows.Forms.DockStyle.Right;
this.button1.FlatAppearance.BorderColor = System.Drawing.SystemColors.GradientActiveCaption;
this.button1.ForeColor = System.Drawing.SystemColors.ButtonFace;
this.button1.Image = global::WATestPGB.Properties.Resources._063;
this.button1.Location = new System.Drawing.Point(120, 0);
this.button1.Margin = new System.Windows.Forms.Padding(0, 3, 3, 3);
this.button1.MaximumSize = new System.Drawing.Size(30, 21);
this.button1.MinimumSize = new System.Drawing.Size(30, 21);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(30, 21);
this.button1.TabIndex = 2;
this.button1.Text = "...";
this.button1.UseVisualStyleBackColor = false;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// NumberPicker
//
this.Controls.Add(this.button1);
this.Controls.Add(this.textBoxNumber);
this.MaximumSize = new System.Drawing.Size(150, 21);
this.MinimumSize = new System.Drawing.Size(150, 21);
this.Name = "NumberPicker";
this.Size = new System.Drawing.Size(150, 21);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
#region Properties
/// <summary>
/// Gets or sets the value of the control using a string
/// </summary>
public override string Text
{
get
{
return this.textBoxNumber.Text;
}
set
{
this.textBoxNumber.Text = value;
}
}
/// <summary>
/// Gets of sets the value of the control using a double
/// </summary>
public string Value
{
get
{
return this.textBoxNumber.Text;
}
set
{
this.textBoxNumber.Text = value.ToString();
}
}
/// <summary>
/// Gets or Sets the fact that the control has been modified since it was last created or set
/// </summary>
public bool Modified
{
get
{
return this.textBoxNumber.Modified;
}
set
{
this.textBoxNumber.Modified = value;
}
}
/// <summary>
/// Gets or Sets the maximum amount of characters which can be entered into the control
/// </summary>
public int MaxLength
{
get
{
return this.textBoxNumber.MaxLength;
}
set
{
this.textBoxNumber.MaxLength = value;
}
}
[Description("设置默认值"), Browsable(true), Category("N8")]
public string NodeValuesql
{
get
{
return Node_SQL;
}
set
{
this.Node_SQL = value;
}
}
[Description("设置默认值"), Browsable(true), Category("N8")]
public string Gridviewsql
{
get
{
return GidView_SQL;
}
set
{
this.GidView_SQL = value;
}
}
[Description("设置默认值"), Browsable(true), Category("N8")]
public string Connsql
{
get
{
return Cnn_SQL;
}
set
{
this.Cnn_SQL = value;
}
}
#endregion
#region EventHandlers
/// <summary>
/// This method is invoked when the user double clicks the textbox in the control.
/// It displays the calculator window which allows to insert the numbers.
/// </summary>
/// <param name="sender">The original sender object of the event</param>
/// <param name="e">The parameters given.</param>
private void textBoxNumber_DoubleClick(object sender, System.EventArgs e)
{
// Create a new instance of the calculator window
NumberPickerInput input = new NumberPickerInput(this.textBoxNumber);
// Calculate the position of the input form
System.Drawing.Point location = this.PointToScreen(this.textBoxNumber.Location);
int x = location.X + this.textBoxNumber.Width;
int y = location.Y;
// Set the location of the window
input.Location = new System.Drawing.Point(x, y);
// Validate it before showing the numeric pad
CancelEventArgs args = new CancelEventArgs(false);
this.textBoxNumber_Validation(this, args);
if (args.Cancel == false)
{
input.Show();
}
}
private void textBoxNumber_Validation(object sender,CancelEventArgs ce)
{
try
{
if(this.textBoxNumber.Text.Length != 0)
{
double value = Double.Parse(this.textBoxNumber.Text);
}
}
catch(Exception)
{
ce.Cancel=true;
MessageBox.Show("Please Enter Numeric Value");
}
}
#endregion
private void button1_Click(object sender, EventArgs e)
{
// Create a new instance of the calculator window
ReferenceFrm input = new ReferenceFrm(this.textBoxNumber, Node_SQL, GidView_SQL,Cnn_SQL);
// Calculate the position of the input form
System.Drawing.Point location = this.PointToScreen(this.textBoxNumber.Location);
int x = location.X + this.textBoxNumber.Width;
int y = location.Y;
// Set the location of the window
input.Location = new System.Drawing.Point(x, y);
// Validate it before showing the numeric pad
CancelEventArgs args = new CancelEventArgs(false);
//this.textBoxNumber_Validation(this, args);
if (args.Cancel == false)
{
input.ShowDialog();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -