ToolStripItem.Selected プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
項目が選択されているかどうかを示す値を取得します。
public:
virtual property bool Selected { bool get(); };
[System.ComponentModel.Browsable(false)]
public virtual bool Selected { get; }
[<System.ComponentModel.Browsable(false)>]
member this.Selected : bool
Public Overridable ReadOnly Property Selected As Boolean
プロパティ値
ToolStripItem が選択されている場合は true
。それ以外の場合は false
。
- 属性
例
次のコード例では、 プロパティをカスタム レンダリングに使用 Selected する方法を示します。 このコード例は、ToolStripItem クラスのために提供されている大規模な例の一部です。
// This method defines the behavior for rendering the
// background of a ToolStripItem. If the item is a
// RolloverItem, it paints the item's BackgroundImage
// centered in the client area. If the mouse is in the
// item's client area, a border is drawn around it.
// If the item is on a drop-down or if it is on the
// overflow, a gradient is painted in the background.
protected override void OnRenderItemBackground(
ToolStripItemRenderEventArgs e)
{
base.OnRenderItemBackground(e);
RolloverItem item = e.Item as RolloverItem;
// If the ToolSTripItem is of type RolloverItem,
// perform custom rendering for the background.
if (item != null)
{
if (item.Placement == ToolStripItemPlacement.Overflow ||
item.IsOnDropDown)
{
using (LinearGradientBrush b = new LinearGradientBrush(
item.ContentRectangle,
Color.Salmon,
Color.DarkRed,
0f,
false))
{
e.Graphics.FillRectangle(b, item.ContentRectangle);
}
}
// The RolloverItem control only supports
// the ImageLayout.Center setting for the
// BackgroundImage property.
if (item.BackgroundImageLayout == ImageLayout.Center)
{
// Get references to the item's ContentRectangle
// and BackgroundImage, for convenience.
Rectangle cr = item.ContentRectangle;
Image bgi = item.BackgroundImage;
// Compute the center of the item's ContentRectangle.
int centerX = (cr.Width - bgi.Width) / 2;
int centerY = (cr.Height - bgi.Height) / 2;
// If the item is selected, draw the background
// image as usual. Otherwise, draw it as disabled.
if (item.Selected)
{
e.Graphics.DrawImage(bgi, centerX, centerY);
}
else
{
ControlPaint.DrawImageDisabled(
e.Graphics,
bgi,
centerX,
centerY,
item.BackColor);
}
}
// If the item is in the rollover state,
// draw a border around it.
if (item.Rollover)
{
ControlPaint.DrawFocusRectangle(
e.Graphics,
item.ContentRectangle);
}
}
}
' This method defines the behavior for rendering the
' background of a ToolStripItem. If the item is a
' RolloverItem, it paints the item's BackgroundImage
' centered in the client area. If the mouse is in the
' item's client area, a border is drawn around it.
' If the item is on a drop-down or if it is on the
' overflow, a gradient is painted in the background.
Protected Overrides Sub OnRenderItemBackground(ByVal e As ToolStripItemRenderEventArgs)
MyBase.OnRenderItemBackground(e)
Dim item As RolloverItem = CType(e.Item, RolloverItem)
' If the ToolSTripItem is of type RolloverItem,
' perform custom rendering for the background.
If (item IsNot Nothing) Then
If item.Placement = ToolStripItemPlacement.Overflow OrElse item.IsOnDropDown Then
Dim b As New LinearGradientBrush(item.ContentRectangle, Color.Salmon, Color.DarkRed, 0.0F, False)
Try
e.Graphics.FillRectangle(b, item.ContentRectangle)
Finally
b.Dispose()
End Try
End If
' The RolloverItem control only supports
' the ImageLayout.Center setting for the
' BackgroundImage property.
If item.BackgroundImageLayout = ImageLayout.Center Then
' Get references to the item's ContentRectangle
' and BackgroundImage, for convenience.
Dim cr As Rectangle = item.ContentRectangle
Dim bgi As Image = item.BackgroundImage
' Compute the center of the item's ContentRectangle.
Dim centerX As Integer = CInt((cr.Width - bgi.Width) / 2)
Dim centerY As Integer = CInt((cr.Height - bgi.Height) / 2)
' If the item is selected, draw the background
' image as usual. Otherwise, draw it as disabled.
If item.Selected Then
e.Graphics.DrawImage(bgi, centerX, centerY)
Else
ControlPaint.DrawImageDisabled(e.Graphics, bgi, centerX, centerY, item.BackColor)
End If
End If
' If the item is in the rollover state,
' draw a border around it.
If item.Rollover Then
ControlPaint.DrawFocusRectangle(e.Graphics, item.ContentRectangle)
End If
End If
End Sub
適用対象
GitHub で Microsoft と共同作業する
このコンテンツのソースは GitHub にあります。そこで、issue や pull request を作成および確認することもできます。 詳細については、共同作成者ガイドを参照してください。
.NET