用JS var _input = document.createElement("INPUT"); _input.style.width=40; _input.value="";
仅供参考 不完善,你自己调试改改吧。 using System; using System.ComponentModel; using System.Drawing; using System.Windows.Forms;namespace wintest.Controls { /// <summary> /// Description of LabelButton. /// </summary> public class LabelButton : System.Windows.Forms.UserControl { private Label label; private Button button; private TextBox textBox;
private String _text;
private bool _modified;
public LabelButton() { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent();
// // TODO: Add constructor code after the InitializeComponent() call. // }
#region Windows Forms Designer generated code /// <summary> /// This method is required for Windows Forms designer support. /// Do not change the method contents inside the source code editor. The Forms designer might /// not be able to load this method if it was changed manually. /// </summary> private void InitializeComponent() { // // LabelButton // this.BackColor = System.Drawing.SystemColors.Control; this.Name = "LabelButton"; this.Size = new System.Drawing.Size(100, 23);
this.textBox.Leave += new System.EventHandler(this.TextBoxLeave); this.textBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.TextBoxKeyDown);
this.Controls.Add(this.textBox);
// this._modified = false;
} #endregion
public String TextValue { get { return this._text; } set { this.label.Text = value; this.button.Text = value; this.textBox.Text = value; this._text = value; } }
var _input = document.createElement("INPUT");
_input.style.width=40;
_input.value="";
不完善,你自己调试改改吧。
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;namespace wintest.Controls
{
/// <summary>
/// Description of LabelButton.
/// </summary>
public class LabelButton : System.Windows.Forms.UserControl
{
private Label label;
private Button button;
private TextBox textBox;
private String _text;
private bool _modified;
public LabelButton()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
#region Windows Forms Designer generated code
/// <summary>
/// This method is required for Windows Forms designer support.
/// Do not change the method contents inside the source code editor. The Forms designer might
/// not be able to load this method if it was changed manually.
/// </summary>
private void InitializeComponent() {
//
// LabelButton
//
this.BackColor = System.Drawing.SystemColors.Control;
this.Name = "LabelButton";
this.Size = new System.Drawing.Size(100, 23);
// Institance Controls
this.label = new Label();
this.label.Size = this.Size;
this.label.TextAlign = ContentAlignment.MiddleLeft;
this.label.Dock = DockStyle.Fill;
this.label.MouseEnter += new System.EventHandler(this.LabelMouseEnter);
this.Controls.Add(this.label);
//
this.button = new Button();
this.button.Size = this.Size;
this.button.TextAlign = ContentAlignment.MiddleLeft;
this.button.Dock = DockStyle.Fill;
this.button.MouseLeave += new System.EventHandler(this.ButtonLeaveEnter);
this.button.Click += new System.EventHandler(this.ButtonClick);
this.Controls.Add(this.button);
//
this.textBox = new TextBox();
this.textBox.Size = this.Size;
this.textBox.Dock = DockStyle.Fill;
this.textBox.Leave += new System.EventHandler(this.TextBoxLeave);
this.textBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.TextBoxKeyDown);
this.Controls.Add(this.textBox);
//
this._modified = false;
}
#endregion
public String TextValue
{
get {
return this._text;
}
set {
this.label.Text = value;
this.button.Text = value;
this.textBox.Text = value;
this._text = value;
}
}
//Event Handle
void LabelMouseEnter(object sender, System.EventArgs e)
{
this.label.Visible = false;
this.button.Visible = true;
this.textBox.Visible = false;
}
void ButtonLeaveEnter(object sender, System.EventArgs e)
{
if(!_modified) {
this.label.Visible = true;
this.button.Visible = false;
this.textBox.Visible = false;
}
}
void ButtonClick(object sender, System.EventArgs e)
{
this._modified = true;
this.label.Visible = false;
this.button.Visible = false;
this.textBox.Visible = true;
this.textBox.Focus();
}
void TextBoxLeave(object sender, System.EventArgs e)
{
this._modified = false;
this.label.Visible = true;
this.button.Visible = false;
this.textBox.Visible = false;
this.TextValue = this.textBox.Text;
}
void TextBoxKeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyCode == Keys.Enter || e.KeyCode == Keys.Escape) {
TextBoxLeave(sender,null);
e.Handled = false;
}
}
}
}