WebBrowser Control - Caret does not appear until click - c#

I'm having an issue with the WPF WebBrowser control. It seems to have the logical focus (at least, when I press a key, my keyUp/keyDown events are fired), but the caret is not displayed on the control.
In fact, although the keyUp events are fired, nothing is written in the webbrowser since the caret is not displayed.
Focusable property is set to True not only on the Usercontrol, but also on the WebBrowser control until I click on the box.
I tried setting the focus on the webBrowser:
this.webBrowser.Focus();
Keyboard.Focus(this.webBrowser);
But also on the mshtml element (webBrowser.Document)
this.webBrowser.Document.Focus();
The property Keyboard.FocusedElement returns webBrowser.
This post sounds very similar to my problem, and the solutions posted there are not working in my case. I'm not sure if there's any solution:
WebBrowser control keyboard and focus behavior
Any hint? Thanks in advance.

Related

How to apply focus visual style for a button without actually focusing it?

Trying to get a similar effect as the Windows Run dialog. The input box is focused and taking input, and the "OK" button also gets the focused border(but not actually focused). I can't find a way to set button's visual style properly...
C# Winform, .net 4.5(higher version is also OK).
.
The property you're looking for is AcceptButton on the form it self.
Select the okButton on the form AcceptButton property to make it the default action on Enter keypress.
You also have a similar action for the CancelButton that triggers on Escape keypress.

How do I prevent TextBox or RichEditBox from losing focus after clicking on a disabled button?

The title says it all: "How do I prevent TextBox or RichEditBox from losing focus after clicking on a disabled button?"
I tried setting AllowFocusOnInteraction to false, but that only works when the button is enabled. That property works well if, say, I have a button for setting text to bold or italic. The editor will not lose focus and everything works superb. But if I were to disable that button and then click on it, the editor loses focus. This causes several new issues for me. Would love some help with this. Thanks.
Also note that I have a UWP app. Not sure if it matters, though.
Okay, so I figured out the CORRECT way to fix the issue.
So the bold, italic, and underline format buttons are all within my custom toolbar. What I had to remember is that most xaml elements can be clicked on and therefore trigger a PointerPressed event so long as the element (a Grid element for example) has a background for the click to intercept. If the background is transparent the PointerPressed event will not fire.
Sooo, I made sure my toolbar had a solid background set and then I set a PointerPressed event on it. So whenever you click on the toolbar that event will fire and I simply set the e.Handled property to true;
So now because the button within the toolbar is disabled the pointer click will go to the next clickable element within the visual tree that is underneath the button that you clicked, which is my toolbar (which now has a background). When the toolbar is reached, the e.Handled event being set to true within the event handler will tell the system to do nothing further and so the RichEditBox retains its focus.
I know my writing here is very sloppy but I am sort of in a rush right now and so I will most likely come back and clean my answer up. Hope this helps someone.
wrap the disabled button in a Border or a Grid.
<Grid Tapped="DisabledButtonTapped">
<Button IsEnabled="false"/>
</Grid>
now with help of tapped method on this grid you can set focus back to your RichEditBox.
private void DisabledButtonTapped(object sender, object args)
{
MyRichEditBox.Focus(FocusState.Programmatic);.//use the x:Name of your richeditbox in place of "MyRichEditBox".
}

Want to do some stuff when ultracomboeditor got focused

I am using UltraComboEditior of Infragistics Conrtrols in C# winform application, I want to show a messageBox when UltroComboEditior got focues by MouseClick or KeyBoard Tab button, how can I do it? Any suggestions ? I tried BeforeDropDown but it is called only when we click on arrow button to show drop down list but I am using only drop down with auto complete option set to be true.
UltraComboEditor control has "Enter" event which fires when the control becomes the active control of the form, and this event will fire in both situations - when the control got focus by using your Tab key, and when you are using your mouse.
I hope that this will help you to achieve your goal.
Doesn't it inherit the OnGotFocus event which you can subscribe to?

How to repaint a WinFormsHost when it becomes visible?

I've a winforms control within a WindowsFormsHost on a WPF control. The WPF control is only visible some of the time, and when it becomes visible the contents of the winforms control have usually changed.
When the ViewModel for the WPF control changes I change the contents of the winforms control and the WPF control becomes visible.
Unfortunately, the previous contents of the winforms control is repainted, as if from a visual cache. I've run it through the debugger and I know that the winforms control is having its data updated, but it won't repaint until I re-size the program window (when a repaint is clearly triggered).
I've tried Invalidate() on the winforms control and InvalidateVisual(), InvalidateArrange() and InvalidateMeasure() on the WPF control inside the DataContextChanged event handler for the WPF control, but it seems that because the WPF control is not visible at this point (it's just about to become visible) these method calls are swallowed.
Anyone got any clever ideas on how to force a repaint of a WinFormsHost-ed winforms control immediately after the hosting WPF control becomes visible?
Did you try to invalidate the WinForms control in the IsVisibleChanged event handler ?
You should be able to call Refresh() on the hosted Control as soon as you make it visible. Refresh(), as per the documentation:
Forces the control to invalidate its client area and immediately redraw itself and any child controls.
This turned out to be due to the underlying data-structure failing to notify that it had changed - nothing to do with the paint methods at all! :( Thanks for your help guys.

AcceptsReturn equivalent for WebBrowser .NET control

I have a Windows .NET application and one of the forms has a WebBrowser control, an OK button and a Cancel button.
The WebBrowser control hosts a TextArea html element, so I can write inside.
If the OK button is the form's AcceptButton (form.AcceptButton = btnOk) then when I press Enter the event is captured by the form, and no new line is added in my TextArea.
TextBox has a property AcceptsReturn that does exactly what I would need, but there is no similar property for WebBrowser control.
Any ideas on how to retain the Enter event for the TextArea if the form which hosts the WebBrowser has an AcceptButton?
Thanks.
I think you'd have to turn off the AcceptButton on your form while the TextArea has the focus in order for this to work. Your form has no way of "knowing" that it's not supposed to respond to the Enter key while something in particular is going on inside the WebBrowser control.

Categories

Resources