Freigeben über


Control.Location-Eigenschaft

Ruft die Koordinaten der linken oberen Ecke des Steuerelements relativ zur linken oberen Ecke des Containers ab oder legt diese fest.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Syntax

'Declaration
<LocalizableAttribute(True)> _
Public Property Location As Point
'Usage
Dim instance As Control
Dim value As Point

value = instance.Location

instance.Location = value
[LocalizableAttribute(true)] 
public Point Location { get; set; }
[LocalizableAttribute(true)] 
public:
property Point Location {
    Point get ();
    void set (Point value);
}
/** @property */
public Point get_Location ()

/** @property */
public void set_Location (Point value)
public function get Location () : Point

public function set Location (value : Point)

Eigenschaftenwert

Der Point, der die linke obere Ecke des Steuerelements relativ zur linken oberen Ecke des Containers darstellt.

Hinweise

Da die Point-Klasse ein Werttyp ist (Structure in Visual Basic, struct in Visual C#), erfolgt die Rückgabe als Wert, sodass beim Zugreifen auf die Eigenschaft eine Kopie des linken oberen Punkts des Steuerelements zurückgegeben wird. Das Anpassen der X-Eigenschaft oder der Y-Eigenschaft des von dieser Eigenschaft zurückgegebenen Point wirkt sich daher nicht auf die Eigenschaftenwerte von Left, Right, Top oder Bottom des Steuerelements aus. Zum Anpassen dieser Eigenschaften legen Sie jeden Eigenschaftenwert einzeln fest, oder legen Sie die Location-Eigenschaft mit einem neuen Point fest.

Wenn es sich bei dem Control um ein Form handelt, stellt der Location-Eigenschaftenwert die linke obere Ecke des Form in Bildschirmkoordinaten dar.

Beispiel

Im folgenden Codebeispiel wird eine GroupBox erstellt, und einige ihrer allgemeinen Eigenschaften werden festgelegt. Im Beispiel wird eine TextBox erstellt. Außerdem wird ihre Location innerhalb des Gruppenfelds festgelegt. Anschließend wird die Text-Eigenschaft des Gruppenfelds festgelegt und das Gruppenfeld oben am Formular angedockt. Abschließend wird das Gruppenfeld durch Festlegen der Enabled-Eigenschaft auf false deaktiviert, wodurch alle im Gruppenfeld enthaltenen Steuerelemente deaktiviert werden.

' Add a GroupBox to a form and set some of its common properties.
Private Sub AddMyGroupBox()
   ' Create a GroupBox and add a TextBox to it.
   Dim groupBox1 As New GroupBox()
   Dim textBox1 As New TextBox()
   textBox1.Location = New Point(15, 15)
   groupBox1.Controls.Add(textBox1)
   
   ' Set the Text and Dock properties of the GroupBox.
   groupBox1.Text = "MyGroupBox"
   groupBox1.Dock = DockStyle.Top
   
   ' Disable the GroupBox (which disables all its child controls)
   groupBox1.Enabled = False
   
   ' Add the Groupbox to the form.
   Me.Controls.Add(groupBox1)
End Sub
// Add a GroupBox to a form and set some of its common properties.
private void AddMyGroupBox()
{
   // Create a GroupBox and add a TextBox to it.
   GroupBox groupBox1 = new GroupBox();
   TextBox textBox1 = new TextBox();
   textBox1.Location = new Point(15, 15);
   groupBox1.Controls.Add(textBox1);

   // Set the Text and Dock properties of the GroupBox.
   groupBox1.Text = "MyGroupBox";
   groupBox1.Dock = DockStyle.Top;

   // Disable the GroupBox (which disables all its child controls)
   groupBox1.Enabled = false;

   // Add the Groupbox to the form.
   this.Controls.Add(groupBox1);
}
   // Add a GroupBox to a form and set some of its common properties.
private:
   void AddMyGroupBox()
   {
      // Create a GroupBox and add a TextBox to it.
      GroupBox^ groupBox1 = gcnew GroupBox;
      TextBox^ textBox1 = gcnew TextBox;
      textBox1->Location = Point(15,15);
      groupBox1->Controls->Add( textBox1 );

      // Set the Text and Dock properties of the GroupBox.
      groupBox1->Text = "MyGroupBox";
      groupBox1->Dock = DockStyle::Top;

      // Disable the GroupBox (which disables all its child controls)
      groupBox1->Enabled = false;

      // Add the Groupbox to the form.
      this->Controls->Add( groupBox1 );
   }
// Add a GroupBox to a form and set some of its common properties.
private void AddMyGroupBox()
{
    // Create a GroupBox and add a TextBox to it.
    GroupBox groupBox1 = new GroupBox();
    TextBox textBox1 = new TextBox();
    textBox1.set_Location(new Point(15, 15));
    groupBox1.get_Controls().Add(textBox1);
    // Set the Text and Dock properties of the GroupBox.
    groupBox1.set_Text("MyGroupBox");
    groupBox1.set_Dock(DockStyle.Top);
    // Disable the GroupBox (which disables all its child controls)
    groupBox1.set_Enabled(false);
    // Add the Groupbox to the form.
    this.get_Controls().Add(groupBox1);
} //AddMyGroupBox

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

Control-Klasse
Control-Member
System.Windows.Forms-Namespace
Form
ContainerControl-Klasse

Weitere Ressourcen

Windows Forms-Koordinaten