C# Windows Forms LocationChangedEvent Examples

Let us look at a simple C# Windows Forms LocationChangedEvent example.

Example 1: LocationChangedEvent

This example will comprise the following files:

  • LocationChangedEvent.cs

Step 1: Create Project

  1. The first step is to create a C# Project.
  2. Go to FILE-->New-->Project to create a new project.

Step 2: Write Code

Write Code as follows:

*(a). LocationChangedEvent.cs

Create a file named LocationChangedEvent.cs

Here is the full code

using System;
using System.Windows.Forms;

namespace Examples {
  class MainForm : Form {
    public static void Main() {
      Application.EnableVisualStyles();
      Application.Run(new MainForm());
    }

    public MainForm() {
      this.InitializeComponent();
    }

    private void InitializeComponent() {
      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.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.");
    }

    private StatusStrip statusStrip1 = new StatusStrip();
  }
}

Run

Simply copy the source code into your C# Project,Build and Run. Alternatively download the code using the links provided below, then open the .csproj project, build and run.

Reference

Download the code using the below links:

Number Link
1. Download Example
2. Follow code author

Related Posts