![]() Private Function FireControlSingleEvent(ByRef mpControl As Control, _ That FireControlSingleEvent is the important part (the name is a bit awkward, suggestions welcome!) - this fires the control's 'unique' event handler, so I can add handling for a specific control. ![]() MpTextBox.BorderColor = RGB(100, 150, 215)įireControlSingleEvent mpTextBox, "GotFocus" Next, let's add the 'master' event handler: Public Function AnyTextBox_GotFocus(ByRef mpTextBox As TextBox) Don't worry about the details of my Hungarian notation either. Not relevant to the question, but BuildControlCollection here turns iTextBox into a collection of all the text boxes on the form. LTextBox.OnGotFocus = "=AnyTextBox_GotFocus(" & lTextBox.Name & ")" Private iTextBoxes As CollectionīuildControlCollection Me, iTextBoxes, eTextBox We can then loop through it and assign all of their event handlers to a single handler programatically. It isn't perfect, but the caveats of this are much smaller than the caveats of the above.įirst off, we want to build a collection of the controls we want to use. Shudder.Īfter a long time rolling it around in my head, I think I have a solution. Unless I whack a massive Switch statement inside the loop or something. ![]() I also lose the ability to grant specific behaviour to an individual control. I'd need to loop through the form's entire control collection every single time this thing fires. ' ? Which text box just fired this? I have no way of knowing! The other option is to set the handler for every text box to a constant expression in the form designer (eg =AnyTextBox_HandleGotFocus()), but doing so makes you lose which text box actually got the focus: Private Sub AnyTextBox_HandleGotFocus() and as a programmer I'm too lazy to do it like this. And it's time-consuming, boring, easy to forget to do. That creates a lot of duplicate code, fast. The brute-force option would be to manually add a handler to every text box, and have them all call a master handler ( ). The code for changing one text box border on focus is easy: Private Sub TextBox0_GotFocus()īut doing this for every single text box causes a problem. For sake of example, let's say we want every text box to change its border color when it gains focus. The two 'easy' methods have glaring issues. How could you have one single event handler to handle every control (or all of a particular type of control) on a form? I've never been able to find a complete solution online either. ![]() This may be the empty string if the browser or device doesn't know the keyboard's locale.Bit of background info first - I've been struggling with a problem for a while now. Returns a string representing a locale string indicating the locale the keyboard is configured for. Returns a string representing the key value of the key represented by the event. Returns a boolean value that is true if the event is fired between after compositionstart and before compositionend. Returns a boolean value that is true if the Ctrl key was active when the key event was generated. If you want to display the correct keystrokes to the user, you can use Keyboard.getLayoutMap(). Warning: This ignores the user's keyboard layout, so that if the user presses the key at the "Y" position in a QWERTY keyboard layout (near the middle of the row above the home row), this will always return "KeyY", even if the user has a QWERTZ keyboard (which would mean the user expects a "Z" and all the other properties would indicate a "Z") or a Dvorak keyboard layout (where the user would expect an "F").
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |