ScrollableControl.AutoScrollMargin プロパティ
自動スクロールのマージンのサイズを取得または設定します。
名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文
'宣言
<LocalizableAttribute(True)> _
Public Property AutoScrollMargin As Size
'使用
Dim instance As ScrollableControl
Dim value As Size
value = instance.AutoScrollMargin
instance.AutoScrollMargin = value
[LocalizableAttribute(true)]
public Size AutoScrollMargin { get; set; }
[LocalizableAttribute(true)]
public:
property Size AutoScrollMargin {
Size get ();
void set (Size value);
}
/** @property */
public Size get_AutoScrollMargin ()
/** @property */
public void set_AutoScrollMargin (Size value)
public function get AutoScrollMargin () : Size
public function set AutoScrollMargin (value : Size)
プロパティ値
自動スクロールのマージンの高さと幅をピクセル単位で表す Size。
例外
例外の種類 | 条件 |
---|---|
解説
自動スクロールのマージンは、子コントロールからスクロール可能な親コントロールの端までの距離です。AutoScrollMargin サイズは、スクロール バーが必要かどうかを判断するスクロール可能なコントロールに格納された、すべての子コントロールのサイズに追加されます。AutoScrollMargin プロパティは、スクロール可能な親コントロールがサイズ変更されるか、または個別の子コントロールがビューに表示されたときに評価され、スクロール バーを表示する必要の有無を判断するために使用されます。ドッキングされたコントロールは、スクロール バーを表示する必要の有無を判断する計算から除外されます。
注意
ドッキングされたコントロールの Dock プロパティが DockStyle.Fill に設定されている場合は、コントロールにスクロール可能な親コントロールが表示され、スクロール バーが必要かどうかを判断する AutoScrollMargin を使用した場合は、ドッキングされたコントロールは無視されます。
子コントロールの端からスクロール可能な親コントロールまでの距離が AutoScrollMargin プロパティに割り当てられた値未満であり、AutoScroll プロパティが true に設定されている場合、該当するスクロール バーが表示されます。
注意
スクロール可能なコントロール内にコントロールをドッキングする場合は、Panel などのスクロール可能な子コントロールを追加して、スクロールが必要となる可能性のある他のコントロールを格納することをお勧めします。Panel コントロールをスクロール可能なコントロールに子として追加し、その Dock プロパティを DockStyle.Fill、AutoScroll プロパティを true に設定します。スクロール可能な親コントロールの AutoScroll プロパティは false に設定する必要があります。
使用例
派生クラス Panel を使用するコード例を次に示します。この例では、テキスト ボックスの位置を評価し、その親コンテナであるパネル コントロールの外観と動作を変更します。この例では、Panel コントロール、TextBox、および Button のインスタンスが作成されている必要があります。テキスト ボックスをパネルに配置する場合は、少なくとも 1 つのパネルの端と重なるようにします。ボタンがクリックされたときにこの関数を呼び出して、パネルの動作と外観の違いを確認します。
Private Sub SetAutoScrollMargins()
' If the text box is outside the panel's bounds,
' turn on auto-scrolling and set the margin.
If (text1.Location.X > panel1.Location.X) Or _
(text1.Location.Y > panel1.Location.Y) Then
panel1.AutoScroll = True
' If the AutoScrollMargin is set to less
' than (5,5), set it to 5,5.
If (panel1.AutoScrollMargin.Width < 5) Or _
(panel1.AutoScrollMargin.Height < 5) Then
panel1.SetAutoScrollMargin(5, 5)
End If
End If
End Sub
private void SetAutoScrollMargins()
{
/* If the text box is outside the panel's bounds,
turn on auto-scrolling and set the margin. */
if (text1.Location.X > panel1.Location.X ||
text1.Location.Y > panel1.Location.Y)
{
panel1.AutoScroll = true;
/* If the AutoScrollMargin is set to less
than (5,5), set it to 5,5. */
if( panel1.AutoScrollMargin.Width < 5 ||
panel1.AutoScrollMargin.Height < 5)
{
panel1.SetAutoScrollMargin(5, 5);
}
}
}
void SetAutoScrollMargins()
{
/* If the text box is outside the panel's bounds,
turn on auto-scrolling and set the margin. */
if ( text1->Location.X > panel1->Location.X || text1->Location.Y > panel1->Location.Y )
{
panel1->AutoScroll = true;
/* If the AutoScrollMargin is set to less
than (5,5), set it to 5,5. */
if ( panel1->AutoScrollMargin.Width < 5 || panel1->AutoScrollMargin.Height < 5 )
{
panel1->SetAutoScrollMargin( 5, 5 );
}
}
}
private void SetAutoScrollMargins()
{
/* If the text box is outside the panel's bounds,
turn on auto-scrolling and set the margin. */
if (text1.get_Location().get_X() > panel1.get_Location().get_X()
|| text1.get_Location().get_Y() > panel1.get_Location().get_Y()) {
panel1.set_AutoScroll(true);
/* If the AutoScrollMargin is set to less
than (5,5), set it to 5,5. */
if (panel1.get_AutoScrollMargin().get_Width() < 5
|| panel1.get_AutoScrollMargin().get_Height() < 5) {
panel1.SetAutoScrollMargin(5, 5);
}
}
} //SetAutoScrollMargins
プラットフォーム
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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
.NET Framework
サポート対象 : 2.0、1.1、1.0
.NET Compact Framework
サポート対象 : 2.0
参照
関連項目
ScrollableControl クラス
ScrollableControl メンバ
System.Windows.Forms 名前空間
ScrollableControl.AutoScroll プロパティ
SetAutoScrollMargin
AutoScrollPosition
AutoScrollMinSize
DisplayRectangle