私はそれは固定サイズである必要がありカスタムボタンのテキストとイメージのプロパティを取得するには?
、ボタンclass.Theボタンから継承されたカスタムボタンは、物事を以下含まれるべきで作成しました。(私はそれが正常に動作し、これを完成) コントロールのサイズに基づいてテキストを揃えます画像をコントロールに転送します。 複数のアプリケーションにこのコントロールを使用する必要があります。アプリケーションユーザー に基づいて、ボタンのテキストとイメージの値を指定します。
C#の私は、コンストラクタを呼び出します値に基づいて、ボタンのテキストや画像値を取得できますか
Here, there is four constructor,
public customButton()
{
InitializeComponent();
}
/// <summary>
/// This constructor will call when button contains Text property only.
/// call the base constructor with Image is null.
/// </summary>
/// <param name="text"></param>
public customButton(string text)
{
//customButton(text, null);
InitializeComponent();
}
/// <summary>
/// This constructor will call when button contains Image property only.
/// call the base constructor with text is null.
/// </summary>
/// <param name="icon"></param>
public customButton(Image icon)
{
//customButton(null, icon); //How to call the constructor
InitializeComponent();
}
/// <summary>
/// This constructor will call when button contains both image and text values.
/// </summary>
/// <param name="text"></param>
/// <param name="icon"></param>
public customButton(string text, Image icon)
{
InitializeComponent();
if (icon != null)
{
iconAvailable = true;
this.Image = icon; //Here I Need to get the icon value here, }
if (text != string.Empty || text != null)
{
textAvailable = true;
this.Text = text;// // Here Need to get the text value here, Not completed
}
//align icon and text on booleans
setControlAlignment();
}
。
編集:ボタンはテキストのみが含まれている場合
、テキストボタンは画像のみが含まれている場合、画像は中央の中央にある必要があり、真ん中の中心部に位置する必要があります。だから私はコンストラクタを呼び出す必要があることに基づいて、テキストとイメージの可用性をチェックする必要があります。イメージとテキストの値を取得するには?コンストラクタコール
ありがとう、私はテキストとアイコンの値が必要です。それを得る方法?画像とテキストの値に基づいて、テキストと画像をボタンコントロールに合わせます。 – user8331467
私はあなたが何を意味するのか分かりません。 'customButton'をインスタンス化する際に、これらの値を渡します(' CustomButton'に名前を変更することをお勧めします)。このカスタムビートのように、新しいカスタムボタン(Button Text)、Image.FromFile(@ "C:\ test.png")) ; '。この例では、イメージはファイルからロードされますが、リソースでもプログラムで描画されていても、リモートソースからロードされていてもかまいません。 –