Dieser Artikel wurde maschinell übersetzt. Wenn Sie die englische Version des Artikels anzeigen möchten, aktivieren Sie das Kontrollkästchen Englisch. Sie können den englischen Text auch in einem Popupfenster anzeigen, indem Sie den Mauszeiger über den Text bewegen.
Übersetzung
Englisch

Control.ClientSize-Eigenschaft

 

Veröffentlicht: Oktober 2016

Ruft die Höhe und Breite des Clientbereichs des Steuerelements ab oder legt diese fest.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

[BrowsableAttribute(false)]
public Size ClientSize { get; set; }

Eigenschaftswert

Type: System.Drawing.Size

Ein Size, das die Abmessungen des Clientbereichs des Steuerelements darstellt.

The client area of a control is the bounds of the control, minus the nonclient elements such as scroll bars, borders, title bars, and menus. The M:System.Windows.Forms.Control.SetClientSizeCore(System.Int32,System.Int32) method is called to set the P:System.Windows.Forms.Control.ClientSizeproperty. The P:System.Windows.Forms.Control.ClientSize property is not always changed through its set method so you should override the M:System.Windows.Forms.Control.SetClientSizeCore(System.Int32,System.Int32) method to ensure that your code is executed when the P:System.Windows.Forms.Control.ClientSize property is set.

The P:System.Drawing.Size.Width and P:System.Drawing.Size.Height properties represent the width and height of the client area of the control. You can use this property to obtain the size of the client area of the control for tasks such as drawing on the surface of the control.

For more information about drawing on controls, see Rendering a Windows Forms Control.

System_CAPS_noteHinweis

You cannot bind application settings to this property. For more information on application settings, see Application Settings Overview.

The following code example resizes the specified control so the control will accommodate its formatted text. The formatted text is the P:System.Windows.Forms.Control.Text property with the control's assigned P:System.Windows.Forms.Control.Font applied to the text. The AutoSizeControl method in this example also has a textPadding parameter that represents the padding to apply to all edges of the control. To make the padding appear equal, align the text with the F:System.Drawing.ContentAlignment.MiddleCenter value, if your control supports it.

private void AutoSizeControl(Control control, int textPadding)
{
   // Create a Graphics object for the Control.
   Graphics g = control.CreateGraphics();

   // Get the Size needed to accommodate the formatted Text.
   Size preferredSize = g.MeasureString(
      control.Text, control.Font).ToSize();

   // Pad the text and resize the control.
   control.ClientSize = new Size(
      preferredSize.Width + (textPadding * 2), 
      preferredSize.Height+(textPadding * 2) );

   // Clean up the Graphics object.
   g.Dispose();
}

.NET Framework
Verfügbar seit 1.1
Zurück zum Anfang
Anzeigen: