473,698 Members | 2,186 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(obj ect sender, System.Windows. Forms.PaintEven tArgs e)
{
Rectangle rect = txtFirstName.Bo unds; // I want to get Bounds of current control
// with focus not just txtFirstName
}

Thanks
Peter
Nov 16 '05 #1
2 5956
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(obj ect sender,
System.Windows. Forms.PaintEven tArgs e)
{
Rectangle rect = txtFirstName.Bo unds; // I want to get Bounds of
current control
// with focus not just
txtFirstName
}

Thanks
Peter


Rectangle rect = this.ActiveCont rol.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(obj ect sender,
System.Windows. Forms.PaintEven tArgs e)
{
Rectangle rect = txtFirstName.Bo unds; // I want to get Bounds of
current control
// with focus not just
txtFirstName
}

Thanks
Peter


Rectangle rect = this.ActiveCont rol.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
2032
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 control. I can then select a date which displays in the cell. When I leave the cell however I get the following error:
0
1183
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 would be like in word are when you drag an oval onto the screen, the drawing resizes as the control does. The problem I am running into is actually drawing the rectangle. I am attempting to use this code here: Rect = new Rectangle(this.Bounds.X...
0
1923
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.. Chris. code :
13
3895
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 not have access to that particular tab? > > I tried setting the enabled = false for the given tab, but > it only seems to work in the form assembly section (that > is, if I do it after the form is loaded through a > function, it doesn't seem...
3
2290
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 how to adding an event handler to a column of datagrid that raise when this key is pressed. Please help m Private Sub AddCustomDataTableStyle( Dim ts1 As New DataGridTableStyle( ts1.MappingName = "Customers ' Add textbox column style so we can...
8
2783
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) Debug.WriteLine(Me.Bounds.Contains(e.X, e.Y)) End Sub
1
5135
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 the two steps, TextBox1.Text ="foo"; and TextBox2.Text = "bar";
4
4301
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 have is that sometimes I seem to loose the original "holder" of focus and when the user hits tab while using "temporary" focus(while the mouse is over a control) it will change focus to the next control but not update it. So I have several issues....
125
6559
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 problem. http://www.jilp.org/vol9/v9paper10.pdf Specifically, they measured the overhead of a bounds
0
8674
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8604
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9028
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7728
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4369
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.