AcceptsReturn equivalent for WebBrowser .NET control - c#

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.

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.

WebBrowser Control - Caret does not appear until click

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.

How can I give focus to any Control after a Tab has been selected

I have a problem .. I have an error list form (works as validation summary screen) that displays validation of controls that require to save data but have no values.
This form opened when validation occurs on controls in another form that has tab control contains all controls that have validation.
The problem is when I double click on Error List form, I need cursor focus on tab control that have this control and focus on the control itself
The result : focus happened on tab control only .. but I need to focus on the control also
Use Control.Focus() in your tab selected event handler.
Call Focus() to focus on the next control.
Step 1 : You need to handle the Enter event of the TabPage Control to perform the operations when TabPage gains the focus.
Step 2: You can call Select() function on Required control to gain the Focus.
Try This: if you want to gain the Focus of TextBox control in TabPage2 use this code
tabPage2.Enter += new System.EventHandler(this.tabPage2_Enter);
private void tabPage2_Enter(object sender, EventArgs e)
{
textBox1.Select();
}
I think the trick is to set socus on the tab page first, then set focus on the actual control you want to focus on.
What I was seeing is if the tab page was already selected setting focus to the control works fine. However, if the tab was programmatically activated then setting focus on the control alone does not work.
So this works for me reliably:
// first select and focus the tab
TabsResult.SelectedTab = tabRequest;
TabsResult.SelectedTab.Focus();
// then focus the control
txtRequestUrl.Focus();

Acessing the click event for a customized control

I made a customized control that is a picturebox and a button. When the user clicks on the button, i want to show a form that will capture the webcam image and put on the picturebox of the customized control. But i can access outside the control, the button click. I can access the control click but not only the button click...anyone can help me?
thanks!
Rafael
In your control's constructor after the InitializeComponent() (if you have it), write
this.myButtonName.Click += (press Tab twice)
and the handler will automatically be created for you.

c# application with on-screen keyboard

I'm making a Windows form application in c# and im creating on-screen keyboard for this application and i have some problems with that, because I don't know how to do few things.
What i have
Form1 with few textboxes and few richtextboxes.
panel1 with richtextbox and 5 buttons (A, B, C, DEL, ENTER).
What I want?
Everytime I click on any textbox or any richtextbox I want panel1 to show up.
I want the text from the textbox i have clicked to be displayed in a richtextbox on panel1.
When I click "ENTER" button on panel1 I want the text from richtextbox on panel1 to be transferred to textbox i have clicked before. (and ofcourse panel1 would hide after that).
I already made panel1 to show up when I click on textbox or richtextbox (I've used "Enter" event) and panel1 will hide when I click "ENTER" button on it. Is there maybe any other way to show panel1 everytime I click on textbox or richtextbox without coding "Enter" event for each one?
Now the hardest part is transferring text from form to panel and vice versa. To transfer text from the clicked textbox I've simply added a line of code to "Enter" event:
textBox1.Text = richTextBox1.Text;
Transferring text from richtextbox1 back to textbox is my main problem... I have solution for that but im looking for a correct and simple one... my solution is too noobish and complicated...
Will explain here what im looking for:
For example if int can remember number and string can remember text. I want something which can remember which textbox i've last clicked. I hope u can understand what I mean.
My english is not my main language so please reply if u cant understand anything and i will try my best to explain.
Thanks everyone for your time.
I would do these:
Create a base user control that derives from Textbox (if you'll be using only textboxes) or from a Control if there will be more than the textboxes used.
Handle the "Enter" event just as you do now in that base class.
Create the class that will derive from the EventArgs class and that will store a value of yout control. Let's call it "TextboxArgs" for now.
In the base user control, create an event and raise it in the "Enter" handler that you have and use a "TextboxArgs" class form step 3 to pass the text as the event argument.
Subscribe to this event in your panel so it will react properly.
Now, just use this base user control that you have for each textbox and it will raise an event and pass it's value as an argument. Panel will respond to it. If you do it that way then you won't need any additional coding no matter how many textboxes you add.

Categories

Resources