VB textbox.focus() problem - vb.net

I cant seem to get VB to focus on a textbox correctly at the moment I did
TextBox.focus()
in the load event but still a button keeps grabbing focus anyway. Does anyone know why this would happen?

Try changing the tabindex property.
in webforms, see http://www.w3schools.com/aspnet/prop_webcontrol_standard_tabindex.asp
in winforms View -> Tab Order when the desing view is open
if that doesnt work, try calling the Select() method on your TextBox.

Related

ShapeContainer not Staying In Front of PictureBoxes

I have a GUI in Visual Studio 2010 that has several PictureBoxes, LineShapes/Rectangles, and Labels/TextBoxes. The LineShapes/Rectangles need to be in front of the PictureBoxes, and the Labels/TextBoxes need to be in front of the LineShapes/Rectangles.
For months my GUI was working correctly, when I called the BringToFront() method in the desired order in my form's Load event handler. I first called the ShapeContainer's BringToFront() method, and I then called the BringToFront() method for all of the Labels/TextBoxes.
All of a sudden, my PictureBoxes started to show up in front of my LineShapes/Rectangles. Comparing my latest code to my last working tag shows that nothing changed with respect to these objects. I tried calling the SendToBack() method for the PictureBoxes in my form's Load event handler, but it had no effect.
Can someone explain why this behavior spontaneously changed on me, and what I should be doing to ensure the correct display of my PictureBoxes, LineShapes/Rectangles, and Labels/TextBoxes?
If I call all of my PictureBoxes SendToBack methods in my Form's Paint event handler, I seem to get my desired behavior again.
Oddly, I can't call the BringToFront methods for all of my other objects there, or my LineShapes/Rectangles all disappear :/
For now this solved my problem, but I hope that the behavior doesn't change again.

AutomationPeer - how to show data of elements not on the control?

I want to write an AutomationPeer for my custom control in WPF.
Now, I want to show textBlocks \ TextBoxex that are not actually visible on my control.
I know how to override the method GetChildrenCore().
My problem is that when i run the playback (coded ui record) - it's trying to find a control not vissible on the window. Have you got any ideas?
You can set the SearchConfiguration VisibleOnly on the Coded UI control. Also, the UITestControl.FindMatchingControls method can let you know if the search properties are too ambiguous. Coded UI stops looking for a control after the first instance of a matching control is found.
inspect.exe can shed light on a form and how Coded UI may be seeing the control.
Try opening the Designer.cs and see the hierarchy and what Coded UI is trying to find.

How to we make the PopUpMenu to stop after showing in VB.NET?

I have a problem while showing the PopMenu control in VB.NET. Where as in VB6 after showing PopUpMenu control holds on the screeen event after we have code after that also. But when we convert that to VB.NET we get ContextMenu.Show() the control is not holding on the screen and executing the next statements. This statements has to execute after clicking on the menu item in VB6. This is not happening.
Can you help me regarding this?
ShowDialog() would block the code but unfortunately ContextMenu Doesn't have that method. You need to use a Form to get this functionality.

CTRL+ TAB when webbrowser is in focus

I have a windows application with a tabcontrol. One of the tab of the tabcontrol has a webbrowser control.Now the issue that I am facing is when the focus is inside the webbrowser control, the normal Ctrl+Tab functionality of the tabcontrol is not working.I want the Ctrl+Tab to change the selected tab of tabcontrol even when the focus is inside webbrowser control in selected tab.How to achieve this ?
I have already tries overriding ProcessCmdKey.but it does not get hit when focus is inside webbrowser control.
I also tried registerhotkey method ,it works but it locks the Ctrl+Tab hotkey within my application & system doesn't respond to any other Ctrl+Tab presses outside my application when application is running, which is expected behaviour of registerhotkey.
Here is the code you need:
If WB.ContainsFocus Then
MsgBox("We have focus, disappearing...")
WB.Document.Body.RemoveFocus()
End If
Now, the question is, when to run that code. If you put it in the WebBrowser1_GotFocus event, you'll need to turn it on and off. Turn the code off if the user is interacting with the WB Control, and turn it back on when they are not and when you expect to be experiencing the problem you've mentioned.
Of course, you could add another line to ensure a particular control/tab/panel etc gets focus after you remove focus from the body. Also, here are 3 other SO questions that have answers which may help you, but these will take you in directions different to the direction I've provided, probably due to the fact that the questions are not identical to yours, but are similar enough to be useful (not listed in order of preference).
Prevent WebBrowser control from stealing focus?
Webbrowser steals focus
Focusing WebBrowser control in a C# application
UPDATE:
I just wanted to add, instead of the .Body.RemoveFocus() you could do this:
WB.Document.Body.Parent.RemoveFocus()
Which I prefer, since the .Document object didn't have an explicit .RemoveFocus method on the intellisense I was gettign in VS2012 RC. This is probably referring to the HTML tag (and not the .Document object) and since the html tag is the only parent to the body tag, it makes sense, and there is no "HTML" object directly available in the intellisense under object, since you can get it via other means, so it's just more convenient doing it this way.
Cheers, and let me know if you need more info on anything.

Silverlight 4: DataForm, currentItem and AutoCommit

I have a DataGrid and a DataForm. I'm assigning data to the DataForm with the currently selected Item in the datagrid individually as DataForm.CurrentItem. This means that I do not have any Next/Previous button on the DataForm and the user can switch to any row in the DataGrid.
My problem is that although I have set the property AutoCommit="True" on the DataForm, if the user edits something and clicks on another record in the DataGrid, it crashes.
How can I force it to save the DataForm when the user moves away from the form?
I got this working but I'm not sure whether this is correct. On SelectionChanged event of datagrid I added the following:
DataForm.CommitEdit();
and it stopped crashing and giving me the error. If anyone else has a better solution please do let me know.