我有一个继承按钮,我在使用工具提示控件的Winform应用程序中使用。使用工具提示一切都很好,但看起来基类按钮显示工具提示和父级。我想禁用基类按钮来显示它的工具提示,同时保留父级的工具提示。我想发布显示双工具提示的图片,但是这里有一个新手。
using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace GUI
{
public partial class ToggleButton : Button
{
private Button button;
[Category("Behavior")]
[Description("Gets or sets the botton state")]
[DefaultValue(true)]
public bool State { get; set; }
[Category("Behavior")]
[Description("Gets or sets the TRUE state text")]
public string TrueText { get; set; }
[Category("Behavior")]
[Description("Gets or sets the FALSE state text")]
public string FalseText { get; set; }
public ToggleButton() : base(){}
private void InitializeComponent()
{
this.button = new System.Windows.Forms.Button();
this.SuspendLayout();
this.button.Location = new System.Drawing.Point(0, 0);
this.button.Name = "button";
this.button.Size = new System.Drawing.Size(75, 23);
this.button.TabIndex = 0;
this.button.Text = "button";
this.button.UseVisualStyleBackColor = true;
this.button.Click += new System.EventHandler(this.button2_Click);
this.ResumeLayout(false);
}
private void button2_Click(object sender, EventArgs e)
{
Button clickedButton = (Button)sender;
State = !State;
clickedButton.Text = State ? TrueText : FalseText;
}
}
}