tate Posted March 7, 2004 Posted March 7, 2004 As part of a little windows app I have created there is a label, tabindex = 1 combo box1, tabindex = 2 combo box2, tabindex = 3 combo box3, tabindex = 4 text box, tabindex = 5 rich text box, tabindex = 6 My problem is that the combo box1 has focus after the form has loaded. Therefore, it is highlighted (blue). I would like the form to load such that no control has focus. Even assigning focus to the text box after frmMain_Load doesn't change this. Any idea how I can resolve this? Thanks for the help. Quote
*Experts* DiverDan Posted March 7, 2004 *Experts* Posted March 7, 2004 Did you try: Me.ActiveControl = Me.TextBox1 Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
kas Posted March 7, 2004 Posted March 7, 2004 (edited) I would like the form to load such that no control has focus. To avoid the ComboBox's blue highlight being replaced by the same highlight in a TextBox, the only workaround I know of is this: 1. You need a button on the form. (I know you don't mention one, but maybe you could manufacture an acceptable reason for your users to have one on there). 2. Leave the TabIndex settings as you list them in your post. 3. But put this code in the Form Load or Form Resize event: Button1.TabIndex = 0 4. Run the application. 5. When your form loads, your blue highlight doesn't appear in any of the comboboxes or the textbox. (The button is in fact focused, but this isn't immediately obvious). 6. Press the Tab key, as you normally would in order to move to a combobox. Your first combobox will now be highlighted and ready for action. I know it seems cumbersome and there may well be better ways. The problem lies with the various controls and Focus - for example, although your label is first in line, that particular control cannot hold Focus so is no use for this exercise. Essentially, controls which are configured to accept text input from users will give you this problem. Those that are not configured for direct user text input, such as buttons and listboxes, for example, won't produce this highlight effect. It would be neat if you could fool it by passing the initial focus to a hidden control (if you really don't want a button), but I don't think that's an option either. Hope this helps you some kas Edited March 7, 2004 by kas Quote
Uncle Gizmo Posted March 7, 2004 Posted March 7, 2004 Put a textbox somewhere on your form and make it as small as possible and the same color as the background. Now set this as the first item to receive focus in your tab order. Quote
AlexCode Posted March 7, 2004 Posted March 7, 2004 Put a textbox somewhere on your form and make it as small as possible and the same color as the background. Now set this as the first item to receive focus in your tab order. I teally don't have time to work out other way out of this for you but if you pick this Uncle Gizmo's idea you don't have to do all that stuff to the textbox... just put it behind another control... Althow this is really a "stupid" way of doing it... it works... :) Alex :p Quote Software bugs are impossible to detect by anybody except the end user.
Leaders dynamic_sysop Posted March 7, 2004 Leaders Posted March 7, 2004 i knocked this example up just for you , hope it helps ... in a Class , or below the End Class statement of your Form ... [color=Green]'/// in a Class , or below the End Class statement of your Form ...[/color] [color=Blue]Public Class[/color] SubClass [color=Blue]Inherits[/color] System.Windows.Forms.NativeWindow [color=Blue]Private Const[/color] WM_SETFOCUS [color=Blue]As Integer[/color] = &H7 [color=Blue]Private[/color] IsSubclassed [color=Blue]As Boolean[/color] = [color=Blue]False[/color] [color=Blue]Sub New[/color]([color=Blue]ByVal[/color] Handle [color=Blue]As[/color] IntPtr) [color=Blue]MyBase[/color].AssignHandle(Handle) [color=Blue]End Sub[/color] [color=Blue]Protected Overrides Sub[/color] WndProc([color=Blue]ByRef[/color] m [color=Blue]As[/color] System.Windows.Forms.Message) [color=Blue]If[/color] m.Msg = WM_SETFOCUS [color=Blue]AndAlso[/color] IsSubclassed = [color=Blue]False Then[/color] IsSubclassed = [color=Blue]True[/color] [color=Green]'/// only allow the WM_SETFOCUS message to be bypassed on Form_Load[/color] [color=Blue]Else[/color] [color=Blue]MyBase[/color].WndProc(m) [color=Blue]End If[/color] [color=Blue]End Sub[/color] [color=Blue]End Class[/color] in your Form ( using the _Load function ) ... [color=Blue]Private[/color] sbclss [color=Blue]As[/color] SubClass [color=Blue]Private Sub[/color] Form1_Load([color=Blue]ByVal [/color] sender [color=Blue]As[/color] System.Object, [color=Blue]ByVal[/color] e [color=Blue]As[/color] System.EventArgs) [color=Blue]Handles[/color] [color=Blue]MyBase[/color].Load sbclss = [color=Blue]New[/color] SubClass(ComboBox1.Handle) [color=Blue]End Sub[/color] Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.