ToolBarButton.Tag プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > ToolBarButton.Tag プロパティの意味・解説 

ToolBarButton.Tag プロパティ

ツール バー ボタンに関するデータ格納しているオブジェクト取得または設定します

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

<LocalizableAttribute(False)> _
<BindableAttribute(True)> _
Public Property Tag As Object
Dim instance As ToolBarButton
Dim value As Object

value = instance.Tag

instance.Tag = value
[LocalizableAttribute(false)] 
[BindableAttribute(true)] 
public Object Tag { get; set;
 }
[LocalizableAttribute(false)] 
[BindableAttribute(true)] 
public:
property Object^ Tag {
    Object^ get ();
    void set (Object^ value);
}
/** @property */
public Object get_Tag ()

/** @property */
public void set_Tag (Object value)

プロパティ
ツール バー ボタンに関するデータ格納する Object既定値null 参照 (Visual Basic では Nothing) です。

解説解説
使用例使用例

Pushed プロパティ、PartialPush プロパティ、および Tag プロパティ使用する方法次のコード例示します。この例を実行するには、RichTextBox1 という名前の RichTextBox コントロール配置されているフォームに、次のコード貼り付けます。そして、フォームコンストラクタまたは Load メソッドInitializeToolBar メソッド呼び出します。

' Declare ToolBar1.
Friend WithEvents ToolBar1 As
 System.Windows.Forms.ToolBar

' Initialize ToolBar1 with Bold(B), Italic(I), and Underline(U) buttons.
Private Sub InitializeToolBar()
    ToolBar1 = New ToolBar

    ' Set the appearance to Flat.
    ToolBar1.Appearance = ToolBarAppearance.Flat

    ' Set the toolbar to dock at the bottom of the form.
    ToolBar1.Dock = DockStyle.Bottom

    ' Set the toolbar font to 14 points and bold.
    ToolBar1.Font = New System.Drawing.Font _
        (FontFamily.GenericSansSerif, 14, FontStyle.Bold)

    ' Declare fontstyle array with the three font styles.
    Dim fonts() As FontStyle = New
 FontStyle() _
        {FontStyle.Bold, FontStyle.Italic, FontStyle.Underline}
    Dim count As Integer

    ' Create a button for each value in the array, setting its text
 to the
    ' first letter of the style and its button's tag property.
    For count = 0 To fonts.Length - 1
        Dim fontButton As New
 ToolBarButton(fonts(count). _
            ToString.Substring(0, 1))
        fontButton.Style = ToolBarButtonStyle.ToggleButton
        fontButton.Tag = fonts(count)
        ToolBar1.Buttons.Add(fontButton)
    Next
    Me.Controls.Add(Me.ToolBar1)
End Sub


' Declare FontStyle object, which defaults to the Regular FontStyle.
Dim style As New FontStyle

Private Sub ToolBar1_ButtonClick(ByVal
 sender As Object, _
    ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs)
 _
    Handles ToolBar1.ButtonClick

    ' If a button is pushed, use a bitwise Or combination 
    ' of the style variable and the button tag, to set style to 
    ' the correct FontStyle. Set the button's PartialPush property to
    ' true for a Windows XP-like appearance.
    If (e.Button.Pushed) Then
        e.Button.PartialPush = True
        style = style Or e.Button.Tag

    Else
        ' If the button was not pushed, use a bitwise XOR 
        ' combination to turn off that style 
        ' and set the PartialPush property to False.
        e.Button.PartialPush = False
        style = style Xor e.Button.Tag
    End If

    ' Set the font using the existing RichTextBox font and the new
    ' style.
    RichTextBox1.Font = New Font(RichTextBox1.Font, style)
End Sub
// Declare ToolBar1.
internal System.Windows.Forms.ToolBar ToolBar1;

// Initialize ToolBar1 with Bold(B), Italic(I), and 
// Underline(U) buttons.
private void InitializeToolBar()
{
    ToolBar1 = new ToolBar();

    // Set the appearance to Flat.
    ToolBar1.Appearance = ToolBarAppearance.Flat;

    // Set the toolbar to dock at the bottom of the form.
    ToolBar1.Dock = DockStyle.Bottom;

    // Set the toolbar font to 14 points and bold.
    ToolBar1.Font = new Font(FontFamily.GenericSansSerif,
        14, FontStyle.Bold);

    // Declare fontstyle array with the three font styles.
    FontStyle[] fonts = new FontStyle[]{FontStyle.Bold, 
        FontStyle.Italic, FontStyle.Underline};
    
    int count;

    // Create a button for each value in the array, setting its 
    // text to the first letter of the style and its 
    // button's tag property.
    for(count=0; count<fonts.Length; count++)
    {
        ToolBarButton fontButton = 
            new ToolBarButton(fonts[count].ToString().Substring(0,
 1));
        fontButton.Style = ToolBarButtonStyle.ToggleButton;
        fontButton.Tag = fonts[count];
        ToolBar1.Buttons.Add(fontButton);
    }
    this.ToolBar1.ButtonClick += 
        new ToolBarButtonClickEventHandler(ToolBar1_ButtonClick);
    this.Controls.Add(this.ToolBar1);
}


// Declare FontStyle object, which defaults to the Regular
// FontStyle.
FontStyle style = new FontStyle();

private void ToolBar1_ButtonClick(object sender,
 
    System.Windows.Forms.ToolBarButtonClickEventArgs e)
{

    // If a button is pushed, use a bitwise Or combination 
    // of the style variable and the button tag, to set style to 
    // the correct FontStyle. Set the button's PartialPush 
    // property to true for a Windows XP-like appearance.
    if (e.Button.Pushed)
    {
        e.Button.PartialPush = true;
        style = style |(FontStyle) e.Button.Tag;

    }
    else
    {
        // If the button was not pushed, use a bitwise XOR 
        // combination to turn off that style 
        // and set the PartialPush property to false.
        e.Button.PartialPush = false;
        style = style ^ (FontStyle) e.Button.Tag;
    }

    // Set the font using the existing RichTextBox font and the new
    // style.
    RichTextBox1.Font = new Font(RichTextBox1.Font, style);

}
   // Declare ToolBar1.
internal:
   System::Windows::Forms::ToolBar^ ToolBar1;

private:

   // Initialize ToolBar1 with Bold(B), Italic(I), and 
   // Underline(U) buttons.
   void InitializeToolBar()
   {
      ToolBar1 = gcnew ToolBar;
      
      // Set the appearance to Flat.
      ToolBar1->Appearance = ToolBarAppearance::Flat;
      
      // Set the toolbar to dock at the bottom of the form.
      ToolBar1->Dock = DockStyle::Bottom;
      
      // Set the toolbar font to 14 points and bold.
      ToolBar1->Font = gcnew System::Drawing::Font( FontFamily::GenericSansSerif,14,FontStyle::Bold
 );
      
      // Declare fontstyle array with the three font styles.
      array<FontStyle>^ fonts = {FontStyle::Bold,FontStyle::Italic,FontStyle::Underline};
      int count;
      
      // Create a button for each value in the array, setting its 
      // text to the first letter of the style and its 
      // button's tag property.
      for ( count = 0; count < fonts->Length; count++ )
      {
         ToolBarButton^ fontButton = gcnew ToolBarButton( fonts[ count ].ToString()->Substring(
 0, 1 ) );
         fontButton->Style = ToolBarButtonStyle::ToggleButton;
         fontButton->Tag = fonts[ count ];
         ToolBar1->Buttons->Add( fontButton );

      }
      this->ToolBar1->ButtonClick += gcnew ToolBarButtonClickEventHandler(
 this, &Form1::ToolBar1_ButtonClick );
      this->Controls->Add( this->ToolBar1
 );
   }

   // Declare FontStyle object, which defaults to the Regular
   // FontStyle.
   FontStyle style;
   void ToolBar1_ButtonClick( Object^ /*sender*/, System::Windows::Forms::ToolBarButtonClickEventArgs^
 e )
   {
      // If a button is pushed, use a bitwise Or combination 
      // of the style variable and the button tag, to set style to 
      // the correct FontStyle. Set the button's PartialPush 
      // property to true for a Windows XP-like appearance.
      if ( e->Button->Pushed )
      {
         e->Button->PartialPush = true;
         style = (FontStyle)(style | safe_cast<FontStyle>(e->Button->Tag));
      }
      else
      {
         // If the button was not pushed, use a bitwise XOR 
         // combination to turn off that style 
         // and set the PartialPush property to false.
         e->Button->PartialPush = false;
         style = (FontStyle)(style ^ safe_cast<FontStyle>(e->Button->Tag));
      }

      // Set the font using the existing RichTextBox font and the new
      // style.
      RichTextBox1->Font = gcnew System::Drawing::Font( RichTextBox1->Font,style
 );
   }
// Declare ToolBar1.
System.Windows.Forms.ToolBar toolBar1;

// Initialize ToolBar1 with Bold(B), Italic(I), and 
// Underline(U) buttons.
private void InitializeToolBar()
{
    toolBar1 = new ToolBar();
    // Set the appearance to Flat.
    toolBar1.set_Appearance(ToolBarAppearance.Flat);
    // Set the toolbar to dock at the bottom of the form.
    toolBar1.set_Dock(DockStyle.Bottom);
    // Set the toolbar font to 14 points and bold.
    toolBar1.set_Font(new Font(FontFamily.get_GenericSansSerif(),
 14,
        FontStyle.Bold));
    // Declare fontstyle array with the three font styles.
    FontStyle fonts[] = new FontStyle[] { FontStyle.Bold, FontStyle.Italic
,
        FontStyle.Underline };

    int count;
    // Create a button for each value in the array, setting its 
    // text to the first letter of the style and its 
    // button's tag property.
    for (count = 0; count < fonts.length; count++) {
        ToolBarButton fontButton = new ToolBarButton(fonts.get_Item(count).
            ToString().Substring(0, 1));
        fontButton.set_Style(ToolBarButtonStyle.ToggleButton);
        fontButton.set_Tag(fonts.get_Item(count));
        toolBar1.get_Buttons().Add(fontButton);
    }
    this.toolBar1.add_ButtonClick(new ToolBarButtonClickEventHandler(
        toolBar1_ButtonClick));
    this.get_Controls().Add(this.toolBar1);
} //InitializeToolBar

// Declare FontStyle object, which defaults to the Regular
// FontStyle.
private FontStyle style;

private void toolBar1_ButtonClick(Object sender
,
    System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
    // If a button is pushed, use a bitwise Or combination 
    // of the style variable and the button tag, to set style to 
    // the correct FontStyle. Set the button's PartialPush 
    // property to true for a Windows XP-like appearance.
    if (e.get_Button().get_Pushed()) {
        e.get_Button().set_PartialPush(true);
        style = style | ( FontStyle)e.get_Button().get_Tag();
    }
    else {
        // If the button was not pushed, use a bitwise XOR 
        // combination to turn off that style 
        // and set the PartialPush property to false.
        e.get_Button().set_PartialPush(false);
        style = style ^ (FontStyle)e.get_Button().get_Tag();
    }
    // Set the font using the existing RichTextBox font and the new
    // style.
    richTextBox1.set_Font(new Font(richTextBox1.get_Font(), style));
} //toolBar1_ButtonClick 
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からToolBarButton.Tag プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からToolBarButton.Tag プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からToolBarButton.Tag プロパティ を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

ToolBarButton.Tag プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ToolBarButton.Tag プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS