ugp


I have created a normal Windows From.(Form1.cs)

There i have created(draw) 2 lines. like this;

Code Snippet

private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Pen pen = new Pen(Color.DarkGray, 2);

g.DrawLine(pen, 10, 20, 10, 700);
g.DrawLine(pen, 210, 20, 210, 700);

}


Thats fine.

what i want to do is;
if i drag and drop a Button to the from, it should detect its location and give a message box.

Say;
If the button is in between 2 lines, it should display a MessageBox.
MessageBox.Show("button is between lines");

if the button is outside the 2 lines, no need of a MessageBox.

How can i do this !
need help


Code Snippet

namespace WindowsAppTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
/* foreach (Control c in Controls)
{
if (c is Button)
{
MessageBox.Show("button is between lines");
}
}*/
}

private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Pen pen = new Pen(Color.DarkGray, 2);

g.DrawLine(pen, 10, 20, 10, 700);
g.DrawLine(pen, 210, 20, 210, 700);

}



}
}



Re: Visual C# General Identifying Controls in a Form