473,387 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Get Control Bounds with focus

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
Nov 16 '05 #1
2 5940
Peter wrote:
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
Nov 16 '05 #2
Thank you, this is what I needed!

"The Last Gunslinger" <jb******@yahoo.com> wrote in message
news:pT******************@news-server.bigpond.net.au...
Peter wrote:
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

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Billy Jacobs | last post by:
I have created a DataGridColumnDatePicker Component so that I can put a datetimepicker control in my datagrid. It almost works. When I put my mouse in the cell it changes to a datetimepicker...
0
by: Mike Starkey | last post by:
I have created a transparent control and I am using to to create drawing objects Inside the transparent objects I have created I am trying to using the draw shapes oval, rectangle etc. An example...
0
by: Chris Millar | last post by:
I have a user control that i wish to extend to change the date when the user selects the numeric up down button. The code explains itself, hope someone can help. any ideas appreaciated.. ...
13
by: KMiller | last post by:
I would like to control entry into one or more of the tabs > I have set up on my Tab control based on set rules. Does > anyone know how to grey-out the text so that a user will > see that they do...
3
by: Carmen de Lara | last post by:
hello to all, I found in Internet the following code that is very usefull to me. The code detects any character that is entered to datagrid, I am interested in the control key F2 but I don't know...
8
by: Tom | last post by:
Hi I am having problems working out if the mouse pointer is within the control bounds within the OnMouseMove method: Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs) ...
1
by: clickon | last post by:
For testing purposes i have got a 2 step WizardControl. Eqach step contains a text box, TextBox1 and TextBox2 respectively. If i put the following code in the respective activate event handlers for...
4
by: Jon Slaughter | last post by:
I've created some custom controls and forms that allow the feature to temporarily transfer focus to a control that has been entered by the mouse. Everything seems to work fine but the problem I...
125
by: jacob navia | last post by:
We hear very often in this discussion group that bounds checking, or safety tests are too expensive to be used in C. Several researchers of UCSD have published an interesting paper about this...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.