I'm programming in WPF(C#). I have a lot of controls in my Window. I normal situation, pressing TAB button causes to move focus from starting point(1) to next control (2) and then (3) and ... At the end of this scenario, I need to move focus from end point(17) to start point(1) as you see below:
How can I do it?
I need some thing like this method:
MoveFocus(Control controlName)
{
// code...
}
Related
Normally a menu is opened by click right mouse button(this part is handled easily),yet sometimes I need to open the menu automatically and wait for the user to choose an item. My approach like this:
//let menu be a ContextMenuStrip
//newlyCreatedObject be a object set by menu's click event handler
public Object createNewObject()
{
menu.show(); //this line should block until menu close,but it didn't
return newlyCreatedObject; //ERROR:immediately return before event handler run
}
Ideally the menu.show() part should act like a MFC Dialog's DoModal() that handle all the menu's interaction and return when menu is closed. After that i can get the newlyCreatedObject and do whatever i want with it.
So my question is how can i wait the menu to finish,before return newlyCreatedObject?
PS:I am trying to write a UE4 blueprint like application. In UE4 Blueprint you could either click right mouse button to show up a menu and choose what to add or drag a link out of a pin and release button to show up a menu and link the newly added function automatically(this part is what I want to achieve). I guess it would be possible to break up the create part and link part, but this must lead to a lot of state condition.
I have made a custom MessageBox for my application and it launches as a UserControl. I have two buttons inside it and I would like to allow users to press Tab to switch between Buttons. However, since it's a UserControl overlaying the content, Pressing tab more than twice makes the focus go in the background on elements that aren't supposed to be tabbed at.
I can't figure out a good idea how to prevent this, I've thought of making a method that will select all elements and make their IsTabStop values to false and then restore them later, but I think that would be more of a problem then a solution.
Is there a way around this to limit tabbing only to the UserControl?
I would also appreciate advice on working with the message box.. the whole messagebox is an async function that has an infinitive loop until the answer is given. Is there another way to stop the application until one of the message box options was selected?
Crowcoder's reference has lead to correct MSDN page where I found my solution:
dialog = new UCMessageBox("Are you sure you want to exit the application?", MBType.YesNo);
AppMessageBox.Children.Add(dialog);
KeyboardNavigation.SetTabNavigation(dialog, KeyboardNavigationMode.Cycle);
The key was to call .SetTabNavigation function and direct it to my dialog (custom UserControl for the message box) and setting the KeyboardNavigationMode to Cycle.
After closing the UC rest of the application continued normally regarding navigation.
Not sure My title is correct or not actually.
I have a button, when I click on it, it will pop up a small window (based on data in a repeater) to let the user key-in information and click the OK button to proceed to next step.
Below is my code of the Button.Click :
protected void btnRedeemAll_Click(object sender, EventArgs e)
{
foreach( RepeaterItem itm in repGiftResults.Items )
{
if (pr.AdditionalFieldsEnabled == true)
{
AdditionalInfoGiftProcess(pid, giftId, txtQty, txtToken);
}
}
}
divAdditionalInfo is a division ID, divAdditionalInfo.Style["visibility"] = "visible"; and divAdditionalInfo.Style["display"] = "table-cell"; is to prompt out a window to let user key in information and click on "OK" button to continue :
The following the the code of AdditionalInfoGiftProcess() function :
public void AdditionalInfoGiftProcess(int productID, int giftID, TextBox txtQty, UserControls_TokenControl txtToken)
{
/*
Some logic here
*/
//generate pop up window
divAdditionalInfo.Style["visibility"] = "visible";
divAdditionalInfo.Style["display"] = "table-cell";
}
And below is my code of divAdditionalInfo in html :
<div
id="divAdditionalInfo"
class="BlackCover"
style="VISIBILITY:hidden; DISPLAY:none;" runat="server">
<!--
html code that generate the pop out window.
consist of text box and `OK` button, and "Cancel" button.
-->
</div>
When I click on temoBtn button, I only get 1 time window(div) pop out, means I only can enter 1 time information and click on OK button.
I want the window(div) to pop out 3 times one by one, so that I can key in information for 3 times and click on the OK button 1 by 1.
But, the last time window pop out seen like already override those early pop out window.
Any idea to solve this?
p.s.: Actually you can ignore the html code. It is just a code to generate the pop out window. Means, when I click on tempBtn button, the division with id = "divAdditionalInfo" will prompt out as a window to let the user to key-in info and click on the OK button.
You don't have anything to accept input, in your loop.
All you are doing is setting the visibility 3 times, then moving on.
In your handler for the OK and cancel buttons, you could check for any pending messages and show the next one, if necessary.
What do you want to happen here? When the user clicks OK, should anything happen? Or does the user need to click OK three times in order for the popup to go away?
In any case - as your code stands now, the server is generating a div that is visible. Making it visible once has the same effect as making it visible three times. Once you're by the client, you can try to use JavaScript to force the user to work with the div three times before it will go away.
This doesn't sound like a good situation for the user; maybe consider using separate elements for your three popups?
EDIT:
I'm still not sure how you are setting the style of different elements with your code. Where is the div declared? Inside the template of a repeater? If so - I'm surprised that your code compiles. You would need to loop through the generated template instances of your repeater and call FindControl("divAdditionalInfo") on each of them to get access to each instance of the div.
I want to set the focus to a control within an application without giving focus to the whole application.
For example: Click a button which takes a while to load a screen, when the screen is loaded set the focus on one of the controls. In the meantime I have gone to a different application to do something and the focus returns to the previous application.
This happens when I use Keyboard focus or Logical focus.
Is there any way to stop this happening?
Here is the code:
private void SetFocusInternal()
{
// Focus the first control we find with the 'PositionCursor' indicator expression
FrameworkElement controlToFocus = GetFirstRequiresFocusControl();
// Give focus back to the control which last had it (if any)
if (controlToFocus == null)
controlToFocus = GetLastFocusedControl();
// Just focus the first thing we can find
if (controlToFocus == null)
controlToFocus = GetFirstFocusableControl();
// Using any of the following goes wrong!!
controlToFocus.Focus();
Keyboard.Focus(controlToFocus);
FocusManager.SetFocusedElement(FocusManager.GetFocusScope(this), controlToFocus);
}
So, I'm making a game in C#, and I've created a window to handle custom controls schemes.
On this page there is a tab Control, with three tabs: Scheme 1, Scheme 2, and Custom
Scheme 1 and 2 are perfectly fine, but on the Custom tab, whenever the mouse hovers over it, it displays the wait cursor. The controls inside the tab work perfectly fine and without lag, but it just always displays the waitcursor.
I can't change the cursor property in the Design window (it just goes back to waitCursor), and I've tried changing it in code, but it won't work.
Please check the following property in your tab control and each tab:
UseWaitCursor set to true
If UseWaitCursor = true for a parent control then it will propagate this property to all child controls. I think this is probably your issue. Please see the link below for an explanation of the property:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.usewaitcursor.aspx