8,832
社区成员
发帖
与我相关
我的任务
分享using System;
using System.Windows.Forms;
using System.ComponentModel;
namespace Lib
{
public class PasteAllButton : Button
{
public PasteAllButton()
: base()
{
InitializeComponent();
}
public TextBox PasteTextBox { get; set; }
private void InitializeComponent()
{
this.SuspendLayout();
//
// PasteAllButton
//
this.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.Text = "粘贴全部";
this.Click += new System.EventHandler(this.PasteAllButton_Click);
this.ResumeLayout(false);
}
private void PasteAllButton_Click(object sender, EventArgs e)
{
string text = Clipboard.GetText();
if (string.IsNullOrEmpty(text))
{
MessageBox.Show("剪贴板没有数据。");
return;
}
PasteTextBox.Text = text;
}
}
}
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.Collections;
namespace Lib
{
[Designer(typeof(PasteAllButtonDesigner))]
public class PasteAllButton : Button
{
public PasteAllButton()
: base()
{
InitializeComponent();
}
public TextBox PasteTextBox { get; set; }
private void InitializeComponent()
{
this.SuspendLayout();
//
// PasteAllButton
//
this.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.Click += new System.EventHandler(this.PasteAllButton_Click);
this.ResumeLayout(false);
}
private void PasteAllButton_Click(object sender, EventArgs e)
{
string text = Clipboard.GetText();
if (string.IsNullOrEmpty(text))
{
MessageBox.Show("剪贴板没有数据。");
return;
}
PasteTextBox.Text = text;
}
class PasteAllButtonDesigner : ControlDesigner
{
PasteAllButton _button;
public override void Initialize(IComponent component)
{
base.Initialize(component);
_button = component as PasteAllButton;
}
public override void InitializeNewComponent(IDictionary defaultValues)
{
base.InitializeNewComponent(defaultValues);
_button.Text = "粘贴全部";
}
DesignerActionListCollection _lists;
public override DesignerActionListCollection ActionLists
{
get
{
if (_lists == null)
{
_lists = new DesignerActionListCollection();
_lists.Add(new MyDesignerActionList(Component));
}
return _lists;
}
}
class MyDesignerActionList : DesignerActionList
{
PasteAllButton _button;
public MyDesignerActionList(IComponent component)
: base(component)
{
_button = component as PasteAllButton;
}
public TextBox PasteTextBox
{
get
{
return _button.PasteTextBox;
}
set
{
PropertyDescriptor descriptor = TypeDescriptor.GetProperties(_button)["PasteTextBox"];
descriptor.SetValue(_button, value);
}
}
public string Text
{
get
{
return _button.Text;
}
set
{
PropertyDescriptor descriptor = TypeDescriptor.GetProperties(_button)["Text"];
descriptor.SetValue(_button, value);
}
}
}
}
}
}