Get Control Bounds with focus

P

Peter

I have the following code where I get Rectangle Bounds of a text box, but I have other controls on my Windows Form like ListBoxes and Combo Boxes, I want to get Rectangle Bounds when I Enter the control regardless which control I Enter. How would I code Form1_Paint method so rect can equal the Bounds of the current control with focus?

private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Rectangle rect = txtFirstName.Bounds; // I want to get Bounds of current control
// with focus not just txtFirstName
}

Thanks
Peter
 
T

The Last Gunslinger

Peter said:
I have the following code where I get Rectangle Bounds of a text box,
but I have other controls on my Windows Form like ListBoxes and Combo
Boxes, I want to get Rectangle Bounds when I Enter the control
regardless which control I Enter. How would I code Form1_Paint method
so rect can equal the Bounds of the current control with focus?
private void Form1_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
Rectangle rect = txtFirstName.Bounds; // I want to get Bounds of
current control
// with focus not just
txtFirstName
}

Thanks
Peter

Rectangle rect = this.ActiveControl.Bounds;

You will have to check to make sure a control is selected.
HTH
JB
 
P

Peter

Thank you, this is what I needed!

The Last Gunslinger said:
Rectangle rect = this.ActiveControl.Bounds;

You will have to check to make sure a control is selected.
HTH
JB
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top