none
Getting X Y Coordinates in design time

    Question

  • Get the X,Y Locations  

    In design time,
    when add a user component to the Form, how to get the location of that user component in the way of X,Y coordinates.


    Wednesday, June 27, 2007 1:04 PM

Answers

  • You can get the location from, drumroll, the Location property.  Works at design-time too.  Here's an example:

    using System;
    using System.Drawing;
    using System.Windows.Forms;

    public class Sample : Panel {
      protected override void OnLocationChanged(EventArgs e) {
        base.OnLocationChanged(e);
        this.Invalidate();
      }
      protected override void OnPaint(PaintEventArgs e) {
        e.Graphics.DrawString(this.Location.ToString(), this.Font, Brushes.Black, 0, 20);
        base.OnPaint(e);
      }
    }
    Wednesday, June 27, 2007 1:31 PM
    Moderator

All replies

  • You can get the location from, drumroll, the Location property.  Works at design-time too.  Here's an example:

    using System;
    using System.Drawing;
    using System.Windows.Forms;

    public class Sample : Panel {
      protected override void OnLocationChanged(EventArgs e) {
        base.OnLocationChanged(e);
        this.Invalidate();
      }
      protected override void OnPaint(PaintEventArgs e) {
        e.Graphics.DrawString(this.Location.ToString(), this.Font, Brushes.Black, 0, 20);
        base.OnPaint(e);
      }
    }
    Wednesday, June 27, 2007 1:31 PM
    Moderator
  • hi;
    thanks for the response..
    can you pls explain it in more detail manner...; where should i write this method and other stuff
    Wednesday, June 27, 2007 3:20 PM