ToolStripControlHost クラスとは? わかりやすく解説

ToolStripControlHost クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

カスタム コントロールまたは Windows フォーム コントロールホストます。

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

Public Class ToolStripControlHost
    Inherits ToolStripItem
Dim instance As ToolStripControlHost
public class ToolStripControlHost : ToolStripItem
public ref class ToolStripControlHost : public
 ToolStripItem
public class ToolStripControlHost extends ToolStripItem
public class ToolStripControlHost extends
 ToolStripItem
解説解説

ToolStripControlHost クラス使用すると、カスタマイズしたコントロール、またはその他の Windows フォーム コントロールホストできます

ToolStripItem をカスタマイズするには、ToolStripControlHost からクラス派生させて、カスタム実装作成します。OnSubscribeControlEvents などのメソッドオーバーライドすることにより、ホストされるコントロール発生させるイベントを処理できますまた、カスタム機能プロパティ追加することにより、ホストされるコントロール拡張できます

使用例使用例

MonthCalendar コントロールを持つ ToolStripControlHost構築しOnSubscribeControlEvents使用してイベント処理しメンバ一部ToolStripControlHost公開するコード例次に示します

'Declare a class that inherits from ToolStripControlHost.

Public Class ToolStripMonthCalendar
    Inherits ToolStripControlHost
    
    ' Call the base constructor passing in a MonthCalendar instance.
    Public Sub New() 
        MyBase.New(New MonthCalendar())
    
    End Sub

    Public ReadOnly Property
 MonthCalendarControl() As MonthCalendar 
        Get
            Return CType(Control, MonthCalendar)
        End Get
    End Property

    ' Expose the MonthCalendar.FirstDayOfWeek as a property.
    Public Property FirstDayOfWeek() As
 Day 
        Get
            Return MonthCalendarControl.FirstDayOfWeek
        End Get
        Set
            value = MonthCalendarControl.FirstDayOfWeek
        End Set
    End Property
     
    ' Expose the AddBoldedDate method.
    Public Sub AddBoldedDate(ByVal
 dateToBold As DateTime) 
        MonthCalendarControl.AddBoldedDate(dateToBold)
    
    End Sub

    ' Subscribe and unsubscribe the control events you wish to expose.
    Protected Overrides Sub
 OnSubscribeControlEvents(ByVal c As Control)
 

        ' Call the base so the base events are connected.
        MyBase.OnSubscribeControlEvents(c)
        
        ' Cast the control to a MonthCalendar control.
        Dim monthCalendarControl As MonthCalendar
 = _
            CType(c, MonthCalendar)

        ' Add the event.
        AddHandler monthCalendarControl.DateChanged, _
            AddressOf HandleDateChanged
    
    End Sub

    Protected Overrides Sub
 OnUnsubscribeControlEvents(ByVal c As Control)
        ' Call the base method so the basic events are unsubscribed.
        MyBase.OnUnsubscribeControlEvents(c)

        ' Cast the control to a MonthCalendar control.
        Dim monthCalendarControl As MonthCalendar
 = _
            CType(c, MonthCalendar)

        ' Remove the event.
        RemoveHandler monthCalendarControl.DateChanged, _
            AddressOf HandleDateChanged

    End Sub

    ' Declare the DateChanged event.
    Public Event DateChanged As
 DateRangeEventHandler

    ' Raise the DateChanged event.
    Private Sub HandleDateChanged(ByVal
 sender As Object, _
        ByVal e As DateRangeEventArgs)

        RaiseEvent DateChanged(Me, e)
    End Sub
End Class
//Declare a class that inherits from ToolStripControlHost.
public class ToolStripMonthCalendar : ToolStripControlHost
{
    // Call the base constructor passing in a MonthCalendar instance.
    public ToolStripMonthCalendar() : base
 (new MonthCalendar()) { }

    public MonthCalendar MonthCalendarControl
    {
        get
        {
            return Control as MonthCalendar;
        }
    }

    // Expose the MonthCalendar.FirstDayOfWeek as a property.
    public Day FirstDayOfWeek
    {
        get
        {
            return MonthCalendarControl.FirstDayOfWeek;
        }
        set { value = MonthCalendarControl.FirstDayOfWeek; }
    }

    // Expose the AddBoldedDate method.
    public void AddBoldedDate(DateTime dateToBold)
    {
        MonthCalendarControl.AddBoldedDate(dateToBold);
    }

    // Subscribe and unsubscribe the control events you wish to expose.
    protected override void OnSubscribeControlEvents(Control
 c)
    {
        // Call the base so the base events are connected.
        base.OnSubscribeControlEvents(c);

        // Cast the control to a MonthCalendar control.
        MonthCalendar monthCalendarControl = (MonthCalendar) c;

        // Add the event.
        monthCalendarControl.DateChanged +=
            new DateRangeEventHandler(OnDateChanged);
    }

    protected override void OnUnsubscribeControlEvents(Control
 c)
    {
        // Call the base method so the basic events are unsubscribed.
        base.OnUnsubscribeControlEvents(c);

        // Cast the control to a MonthCalendar control.
        MonthCalendar monthCalendarControl = (MonthCalendar) c;

        // Remove the event.
        monthCalendarControl.DateChanged -=
            new DateRangeEventHandler(OnDateChanged);
    }

    // Declare the DateChanged event.
    public event DateRangeEventHandler DateChanged;

    // Raise the DateChanged event.
    private void OnDateChanged(object sender,
 DateRangeEventArgs e)
    {
        if (DateChanged != null)
        {
            DateChanged(this, e);
        }
    }
}
継承階層継承階層
System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Windows.Forms.ToolStripItem
        System.Windows.Forms.ToolStripControlHost
           System.Windows.Forms.ToolStripComboBox
           System.Windows.Forms.ToolStripProgressBar
           System.Windows.Forms.ToolStripTextBox
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



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

辞書ショートカット

すべての辞書の索引

「ToolStripControlHost クラス」の関連用語

ToolStripControlHost クラスのお隣キーワード
検索ランキング

   

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



ToolStripControlHost クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS