Get Control Bounds with focus

  • Thread starter Thread starter Peter
  • Start date Start date
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
 
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
 
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
 
Back
Top