この記事は翻訳者によって翻訳されたものです。 記事の文章にポインターを重ねると、原文のテキストが表示されます。
訳文
原文
このトピックはまだ評価されていません - このトピックを評価する

Control.Anchor プロパティ

コントロールがバインドされるコンテナーの端を取得または設定し、親のサイズ変更時に、コントロールのサイズがどのように変化するかを決定します。

名前空間:  System.Windows.Forms
アセンブリ:  System.Windows.Forms (System.Windows.Forms.dll 内)
public virtual AnchorStyles Anchor { get; set; }

プロパティ値

型: System.Windows.Forms.AnchorStyles
AnchorStyles 値のビットごとの組み合わせ。 既定値は Top および Left です。

親コントロールのサイズ変更に合わせてコントロールのサイズを自動的に変更する方法を定義するには、Anchor プロパティを使用します。 コントロールをその親コントロールに固定すると、親コントロールのサイズが変更されても、固定された端の位置を親コントロールの端に対して相対的に同じ位置に保つことができます。

コントロールは、コンテナーの 1 つ以上の端に固定できます。 たとえば、Anchor プロパティ値が Top および Bottom に設定された Button を持つ Form がある場合、ButtonFormHeight が大きくなるにつれて拡大され、Form の上端と下端までの固定距離を維持します。

メモ メモ

Anchor プロパティと Dock プロパティは同時には指定できません。 いずれか一方のみを設定でき、一度に両方のプロパティを設定した場合は、最後に設定された方が優先されます。

継承時の注意

派生クラスで Anchor プロパティをオーバーライドする場合は、基本クラスの Anchor プロパティを使用して、基本の実装を拡張します。 それ以外の場合は、すべての実装を提供する必要があります。 Anchor プロパティの get アクセサーと set アクセサーの両方をオーバーライドする必要はありません。必要に応じて 1 つのアクセサーだけをオーバーライドできます。

フォームに Button を追加し、共通プロパティの一部を設定するコード例を次に示します。 この例では、ボタンをフォームの右下隅に固定することにより、フォームのサイズが変更されても、相対的な位置関係が維持されるようにしています。 次に、BackgroundImage を設定して、ボタンを Image と同じサイズに変更します。 この例では、TabStoptrue に設定し、TabIndex プロパティを設定しています。 最後に、ボタンの Click イベントを処理するイベント ハンドラーを追加します。 この例では、imageList1 という名前の ImageList が存在している必要があります。


// Add a button to a form and set some of its common properties.
private void AddMyButton()
{
   // Create a button and add it to the form.
   Button button1 = new Button();

   // Anchor the button to the bottom right corner of the form
   button1.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);

   // Assign a background image.
   button1.BackgroundImage = imageList1.Images[0];

   // Specify the layout style of the background image. Tile is the default.
   button1.BackgroundImageLayout = ImageLayout.Center;

   // Make the button the same size as the image.
   button1.Size = button1.BackgroundImage.Size;

   // Set the button's TabIndex and TabStop properties.
   button1.TabIndex = 1;
   button1.TabStop = true;

   // Add a delegate to handle the Click event.
   button1.Click += new System.EventHandler(this.button1_Click);

   // Add the button to the form.
   this.Controls.Add(button1);
}


.NET Framework

サポート対象: 4、3.5、3.0、2.0、1.1、1.0

.NET Framework Client Profile

サポート対象: 4、3.5 SP1

Windows 7, Windows Vista SP1 以降, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core はサポート対象外), Windows Server 2008 R2 (SP1 以降で Server Core をサポート), Windows Server 2003 SP2

.NET Framework では、各プラットフォームのすべてのバージョンはサポートしていません。 サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。
この情報は役に立ちましたか。
(残り 1500 文字)
コミュニティ コンテンツ 追加
注釈 FAQ