ToolStripItem.Owner プロパティ
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
![構文](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
/** @property */ public ToolStrip get_Owner () /** @property */ public void set_Owner (ToolStrip value)
ToolStripItem を所有しているか、これから所有する ToolStrip。
![解説](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
Owner プロパティを使用して、すべての ToolStripItem に共通し、ToolStrip 自体で定義されている ImageList などのオブジェクトを検索します。
項目が ToolStripOverflow に該当しても、Owner は同じままです。DisplayedItems コレクション内の特定の要素に対しては、Owner を null 参照 (Visual Basic では Nothing) に設定できますが、Items コレクションの場合は設定できません。
![使用例](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
Owner プロパティを使ったカスタム レンダリングの方法を、次のコード例に示します。このコード例は、ToolStripItem クラスのトピックで取り上げているコード例の一部分です。
' This method defines the painting behavior of the control. ' It performs the following operations: ' ' Computes the layout of the item's image and text. ' Draws the item's background image. ' Draws the item's image. ' Draws the item's text. ' ' Drawing operations are implemented in the ' RolloverItemRenderer class. Protected Overrides Sub OnPaint(e As PaintEventArgs) MyBase.OnPaint(e) If Not (Me.Owner Is Nothing) Then ' Find the dimensions of the image and the text ' areas of the item. Me.ComputeImageAndTextLayout() ' Draw the background. This includes drawing a highlighted ' border when the mouse is in the client area. Dim ea As New ToolStripItemRenderEventArgs(e.Graphics, Me) Me.Owner.Renderer.DrawItemBackground(ea) ' Draw the item's image. Dim irea As New ToolStripItemImageRenderEventArgs(e.Graphics, Me, imageRect) Me.Owner.Renderer.DrawItemImage(irea) ' If the item is on a drop-down, give its ' text a different highlighted color. Dim highlightColor As Color = IIf(Me.IsOnDropDown, Color.Salmon, SystemColors.ControlLightLight) ' Draw the text, and highlight it if the ' the rollover state is true. Dim rea As New ToolStripItemTextRenderEventArgs(e.Graphics, Me, MyBase.Text, textRect, IIf(Me.rolloverValue, highlightColor, MyBase.ForeColor), MyBase.Font, MyBase.TextAlign) Me.Owner.Renderer.DrawItemText(rea) End If End Sub
// This method defines the painting behavior of the control. // It performs the following operations: // // Computes the layout of the item's image and text. // Draws the item's background image. // Draws the item's image. // Draws the item's text. // // Drawing operations are implemented in the // RolloverItemRenderer class. protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (this.Owner != null) { // Find the dimensions of the image and the text // areas of the item. this.ComputeImageAndTextLayout(); // Draw the background. This includes drawing a highlighted // border when the mouse is in the client area. ToolStripItemRenderEventArgs ea = new ToolStripItemRenderEventArgs( e.Graphics, this); this.Owner.Renderer.DrawItemBackground(ea); // Draw the item's image. ToolStripItemImageRenderEventArgs irea = new ToolStripItemImageRenderEventArgs( e.Graphics, this, imageRect ); this.Owner.Renderer.DrawItemImage(irea); // If the item is on a drop-down, give its // text a different highlighted color. Color highlightColor = this.IsOnDropDown ? Color.Salmon : SystemColors.ControlLightLight; // Draw the text, and highlight it if the // the rollover state is true. ToolStripItemTextRenderEventArgs rea = new ToolStripItemTextRenderEventArgs( e.Graphics, this, base.Text, textRect, this.rolloverValue ? highlightColor : base.ForeColor , base.Font, base.TextAlign); this.Owner.Renderer.DrawItemText(rea); } }
![プラットフォーム](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
![バージョン情報](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
![参照](http://weblio.hs.llnwd.net/e7/img/dict/msdnc/minus.gif)
- ToolStripItem.Owner プロパティのページへのリンク