Form.SetDesktopLocation(Int32, Int32) Form.SetDesktopLocation(Int32, Int32) Form.SetDesktopLocation(Int32, Int32) Form.SetDesktopLocation(Int32, Int32) Method

Definición

Establece la ubicación del formulario en coordenadas del escritorio.Sets the location of the form in desktop coordinates.

public:
 void SetDesktopLocation(int x, int y);
public void SetDesktopLocation (int x, int y);
member this.SetDesktopLocation : int * int -> unit
Public Sub SetDesktopLocation (x As Integer, y As Integer)

Parámetros

x
Int32 Int32 Int32 Int32

Coordenada X de la ubicación del formulario.The x-coordinate of the form's location.

y
Int32 Int32 Int32 Int32

Coordenada Y de la ubicación del formulario.The y-coordinate of the form's location.

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar el SetDesktopLocation, Load y Activate miembros.The following code example demonstrates how to use the SetDesktopLocation, Load and Activate members. Para ejecutar el ejemplo, pegue el código siguiente en un formulario denominado Form1 que contenga un botón denominado Button1 y dos Label controles denominados Label1 y Label2.To run the example, paste the following code in a form called Form1 containing a button called Button1 and two Label controls called Label1 and Label2.

static int x = 200;
static int y = 200;
void Button1_Click( System::Object^ sender, System::EventArgs^ e )
{
   
   // Create a new Form1 and set its Visible property to true.
   Form1^ form2 = gcnew Form1;
   form2->Visible = true;
   
   // Set the new form's desktop location so it  
   // appears below and to the right of the current form.
   form2->SetDesktopLocation( x, y );
   x += 30;
   y += 30;
   
   // Keep the current form active by calling the Activate
   // method.
   this->Activate();
   this->Button1->Enabled = false;
}


// Updates the label text to reflect the current values of x 
// and y, which was were incremented in the Button1 control's 
// click event.
void Form1_Activated( Object^ sender, System::EventArgs^ e )
{
   Label1->Text = String::Format( "x: {0} y: {1}", x, y );
   Label2->Text = String::Format( "Number of forms currently open: {0}", count );
}

static int count = 0;
void Form1_Closed( Object^ sender, System::EventArgs^ e )
{
   count -= 1;
}

void Form1_Load( Object^ sender, System::EventArgs^ e )
{
   count += 1;
}
static int x = 200;
static int y = 200;

private void Button1_Click(System.Object sender, 
	System.EventArgs e)
{
	// Create a new Form1 and set its Visible property to true.
	Form1 form2 = new Form1();
	form2.Visible = true;

	// Set the new form's desktop location so it  
	// appears below and to the right of the current form.
	form2.SetDesktopLocation(x, y);
	x += 30;
	y += 30;

	// Keep the current form active by calling the Activate
	// method.
	this.Activate();
	this.Button1.Enabled = false;
}



// Updates the label text to reflect the current values of x 
// and y, which was were incremented in the Button1 control's 
// click event.
private void Form1_Activated(object sender, System.EventArgs e)
{
	Label1.Text = "x: "+x+" y: "+y;
	Label2.Text = "Number of forms currently open: "+count;
}

static int count = 0;

private void Form1_Closed(object sender, System.EventArgs e)
{
	count -= 1;
}

private void Form1_Load(object sender, System.EventArgs e)
{
	count += 1;
}
Shared x As Integer = 200
Shared y As Integer = 200

Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click

    ' Create a new Form1 and set its Visible property to true.
    Dim form2 As New Form1
    form2.Visible = True

    ' Set the new form's desktop location so it appears below and 
    ' to the right of the current form.
    form2.SetDesktopLocation(x, y)
    x += 30
    y += 30

    ' Keep the current form active by calling the Activate method.
    Me.Activate()
    Me.Button1.Enabled = False
End Sub



' Updates the label text to reflect the current values of x and y, 
' which was were incremented in the Button1 control's click event.
Private Sub Form1_Activated(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles MyBase.Activated
    Label1.Text = "x: " & x & " y: " & y
    Label2.Text = "Number of forms currently open: " & count
End Sub

Shared count As Integer = 0

Private Sub Form1_Closed(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles MyBase.Closed
    count -= 1
End Sub

Private Sub Form1_Load(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load
    count += 1
End Sub

Comentarios

Las coordenadas del escritorio se basan en el área de trabajo de la pantalla, que excluye la barra de tareas.Desktop coordinates are based on the working area of the screen, which excludes the taskbar. Puede usar este método para colocar el formulario en el escritorio.You can use this method to position your form on the desktop. Dado que las coordenadas del escritorio se basan en el área de trabajo del formulario, puede usar este método para asegurarse de que el formulario es completamente visible en el escritorio.Since desktop coordinates are based on the working area of the form, you can use this method to ensure that your form is completely visible on the desktop. Este método está pensado para su uso principalmente en los formularios de nivel superior; Utilice el LayoutMdi método para colocar formularios secundarios de interfaz de múltiples documentos (MDI).This method is intended to be used primarily for top-level forms; use the LayoutMdi method to position multiple-document interface (MDI) child forms.

Se aplica a

Consulte también: