I have tabControl in the form. In one of the tabItems I have textbox(myTextBox). Let's call it tabItem1. When I write something into the this text box placed in the tabItem1 I want to focus textbox(searchTextBox) in the tabItem2. I placed this code in the KeyDown of the
tabItem2.Focus();
searchTextBox.Text = searchTextBoxTeropatik.Text;
searchTextBox.Focus();
I wrote this small function for this purpose.
But there is a big problem.
I press the Key
tabItem2 gets the focus.
But searchTextBox does not get the focus.(My problem)
Call UpdateLayout() after focusing the second TabItem so the system gets the time to redraw the tab.
tabItem2.Focus();
UpdateLayout();
searchTextBox.Focus();
Related
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".
}
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();
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.
I Have created a Grid (g1) with a TabControl (t1). t1's TabItem content has Grid (g2). g2 has another TabControl as t20,t21,t22 (vertical TabControl) and each t2 series TabItem has another Grid (g3) .
The issue I'm having is that a mouse event is not working g3. The same function works when placed in g2.
I have tried placing a button instead of g3 and click event works, and if I add a button to g3, then the button click events work.
What could be causing the mouse event to not work?
You have not given any code, however, there is a very common 'gotcha' in Silverlight regarding mouse events. An element will not raise these events unless it has a background explicitly set. Set your Grid.Background to Transparent and hopefully your events will work.
(If that doesn't work, my net guess is Z-Index!)
I have a popup containing a ListView. The ListView contains customer names. The popup is openen when a search bar is clicked. The user can enter text in the search bar (TextBox) and the Listview is filterd based on the input.
I want to close the popup whenever it loses focus. However, the default "auto close" behaviour StaysOpen="False" is no good, because it closes the popup everytime someone clicks on the search bar.
How can I close the Popup always when it loses focus, except when the focus goes to the search bar?
Maybe you can put some hooks on the search text box. When it receives focus, it can open the popup and set StaysOpen = true. When the textbox loses focus, it can set StaysOpen = false on the popup.
XAML Code:
<Popup x:Name="pop" StaysOpen="False">
Add an event handler to the Leave event (called when focus on the control is lost). In this event handler, you can then check to see if the new item that has focus is the search text box.
if(FormName.ActiveForm.ActiveControl == txtSearchBox)
Then set StaysOpen appropriately based on whether or not the search textbox has focus.
How about:
Forward the focus-lost(Leave, occurs when the control is no longer the active control of the form) event of popup to the parent form
Parent form would, do nothing, if the current focus is on the search bar; else, it would close the the popup.