Control.LocationChanged Event

Definition

Occurs when the Location property value has changed.

C#
public event EventHandler LocationChanged;
C#
public event EventHandler? LocationChanged;

Event Type

Examples

The following code example raises the LocationChanged event on a StatusStrip when the form is resized.

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

public class Form1 : Form
{
    private StatusStrip statusStrip1;

    public Form1()
    {
        InitializeComponent();
    }
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }

    private void InitializeComponent()
    {
        this.statusStrip1 = new System.Windows.Forms.StatusStrip();
        this.SuspendLayout();
        // 
        // statusStrip1
        // 
        this.statusStrip1.Location = new System.Drawing.Point(0, 251);
        this.statusStrip1.Name = "statusStrip1";
        this.statusStrip1.Size = new System.Drawing.Size(292, 22);
        this.statusStrip1.TabIndex = 0;
        this.statusStrip1.Text = "statusStrip1";
        this.statusStrip1.LocationChanged += new System.EventHandler(this.statusStrip1_LocationChanged);
        // 
        // Form1
        // 
        this.ClientSize = new System.Drawing.Size(292, 273);
        this.Controls.Add(this.statusStrip1);
        this.Name = "Form1";
        this.ResumeLayout(false);
        this.PerformLayout();
    }

    private void statusStrip1_LocationChanged(object sender, EventArgs e)
    {
        MessageBox.Show("The form has been resized.");
    }
}

Remarks

This event is raised if the Location property is changed by either a programmatic modification or through interaction.

For more information about handling events, see Handling and Raising Events.

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

See also