473,404 Members | 2,213 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,404 software developers and data experts.

How can I lose focus on a control when I click outside it?

I have a form that contains text boxes and combo boxes. My problem is that when I click on a control, let's say a comboxbox, I can edit inside it but when I click outside, the main form where my controls are contained, my focus is still in the combobox.
Apr 21 '11 #1
3 13069
GaryTexmo
1,501 Expert 1GB
If I'm understanding you correctly, you want your controls to lose focus when you click on the form itself? There might be a better way to do this, but here's what I came up with.

Add a listener to the form's MouseClick event. Inside that method, put the following code...

Expand|Select|Wrap|Line Numbers
  1. this.ActiveControl = null;
This should clear the active control for the form and remove focus from your controls.

If that's not what you meant, can you please clarify?
Apr 21 '11 #2
Sorry if I did not clarify things up. Even I find it hard to explain it further. I have this combobox with AutoCompleteMode set to SuggestAppend.

My problem -> I click on the combobox and choose an item. Then I click the form and use my mouse wheel to scroll the whole form but what I'm scrolling here is not the whole form as to what I intend to do but just the items inside the combobox.

The same goes when I click on a textbox inside a tablelayoutpanel which is inside a groupbox.

I assume you had the idea because your code helped me but now every time I click my main form it scrolls back to where I have my focus. I want my form in a way that I have my form scrolled to where I'm at and just have to click the main form whenever I want to scroll up or down.
Apr 22 '11 #3
GaryTexmo
1,501 Expert 1GB
And that suggestion didn't work? What I was trying to do was take focus away from the control itself and put it on the form. I didn't know you wanted to scroll the form, but it should have the same result.

No go?
Apr 27 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Wai Man Chung | last post by:
Dear all, I have an asp page which upon opening a field will be set to be in focus so that user can type in data without the need to use the mouse to click on the field. However, after I add...
2
by: chris | last post by:
Does anybody know how I can programmatically cause a textbox to lose focus and automatically jump to the next appropriate control. I have a custom textbox usercontrol whereby the requirement is...
4
by: Aung Thu | last post by:
Hi, there! I want to set focus on a control, of which TabIndex is not the first, when a form is loaded. In the form's load event, I have used Control.Focus() but it doesn't not work. The focus...
1
by: Haobing | last post by:
I embeded an flash activex control to a wxPanel inherited class 'MyPanel' using wxPython's MakeActiveXClass method, and 'MyPanel' only has flash control ;But when then dialog init,the focus is not...
4
by: OpticTygre | last post by:
If I create a checkbox dynamically: Dim NewCheckBox as New Checkbox Then, I display that checkbox on a form, how can I cause the checkbox to lose focus after a user clicks on it? TIA, ...
2
by: fniles | last post by:
For IE users, we now encountered a "Click to activate and use this control" when the web page has an ActiveX Control. There is a compatibility patch that changes the default bahavior back to what...
1
by: danyeungw | last post by:
I get the following from the link http://support.microsoft.com/kb/314206. I need to have both work - the page stays where it is and set focus to next control. Does anyone have solution? I have...
2
by: nani | last post by:
Hi friends I am creating one web application in that i take one hyperlink control.when i click hyperlink control.how to split the page in two parts and display the result in that secound part If...
2
by: newUser1234 | last post by:
Hello i have a data validation check upon lost focus for a vb textbox: Private Sub fromText_LostFocus() If IsNull(fromText.Text) = True Then MsgBox StrMsg, vbExclamation End If...
8
by: freeskier | last post by:
I have been using the following code to cycle through a subform and disable all textboxes on a form. If a textbox on the form has the focus when this is run I get error "can't disable a control when...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.