Go back to the main menu at any point during a method - c#

If the user is in the middle of adding a Customer, they may decide that they want to go back for whatever reason. When the user is entering new details, I want them to be able to press the "Esc" button at any point to go back to the main menu. I've already implemented it in my application where the user can select a number from a menu, but that's only when they reach a certain point within the program. can anyone help?

I would suggest encapsulating all of your prompts and reading input as one method that takes parameters.
public static string PromptUserForInput(string promptMessage, bool checkForEscape = true){...}
Then use the readkey like #h0r53 said. I was going to build out a basic example, but it looks like one can already be found here. Then just tweak as needed.

Related

Xamarin.Mac Secure Text Field to move the focus by inputting Enter key

I would like to move the focus by input enter key after entering a string into a secure text field, but I have no idea how to do it at all.
Do I define it as an Outlet? What do I do then?
I couldn't find anything on Google the following code in fragments only:
public override void ViewDidLoad()
{
base.ViewDidLoad();
textPassword.ShouldReturn = (NSSecureTextField) =>
{
textPassword.ResignFirstResponder();
return true;
};
}
Of course, it doesn't work. What do I need to do to make this work?
In order to do what you are trying to achieve you will want to go into your storyboard and right click on both your NSTextFields individually.
This will bring up a list of methods that can be utilised
see screenshot
Dragging action into your viewcontroller.h file within xcode will set up the action link for both textfields.
Now in order to link this to your Viewcontroller.cs youll need to add the methods you set up into your viewcontroller.See screenshot
The code you found on google was close however it seems in order to resignfirstresponder on mac you need to assign first responder to something else.
Looking at the screenshot above i've taken first responder from the emailtextfield(1) and given it to passwordtextfield(2) which seems to be similar to what your looking to do.
Let me know how you get on.
Rob

How do I force selection of a keyboard type in a Xamarin.Webkit.Webview

We have a Xamarin app (Android) that at one stage opens up a web view (Webkit.Webview not Forms.Webview). This directs the user to a page on a third party site which has been set up for us.
Firstly - on certain input fields the keyboard which shows up is the wrong one - we are expecting a dismissable keyboard (i.e. "Done" in the bottom corner, not a "Submit"). I know this can be changed but not sure what is the correct way to do this. Does it have to be the metadata/text inputs on the web page that is changed? If so - what needs to be modified per text box entry on the html of the page? Just the type? i.e:
<input type="email">
Secondly, rather than wait for the third party to fix the page, is there a way we can force the webview to always open a certain keyboard type?
We have an option of intercepting the keyboard key presses and trying to dismiss the keyboard on return press at the minute. But would prefer not to put a hack in that intercepts every key press.
Appreciate the help, not sure what the way forward is here.
Thanks
From the comments: To your second question about forcing a keyboard button, you can check out this link which describes how to override OnCreateInputConnection to specify the Keyboard Enter Button type.
public class MyWebView : WebView {
...
public override IInputConnection OnCreateInputConnection (EditorInfo outAttrs) {
var inputConnection = base.OnCreateInputConnection (outAttrs);
// outAttrs.ImeOptions in Xamarin only allows ImeFlags but it also should allow ImeActions
outAttrs.ImeOptions = outAttrs.ImeOptions | (ImeFlags)ImeAction.Next;
return inputConnection;
}
}
That will not dismiss your keyboard when tapped though since it is meant to take the user to the next input. Hopefully someone else can come along and either provide a better answer or give a good way to dismiss the keyboard in this situation without hacking something together.

Is my code legal in Android usage?

I asked a question recently about how to disable the back button is Android, after a while I got it working with these lines of code
public override void OnBackPressed ()
{
// base.OnBackPressed (); /* Comment this base call to avoid calling Finish() */
// Do nothing
}
And just recently someone commented this
Disabling the back button is counter-intuitive and breaks the device
usage contract imposed by Android. So i suggest you rethink.
-Question-
What would be a possible change to this? I dont want to be able to press the back button when playing my quiz game because that would make be able to cheat. New to android Development
Instead of simply making the back button do nothing, you could have it create a popup asking something along the lines of "Are you sure you want to leave the quiz? (This will count as a loss)". And have it take the user back to the main page of your app if he confirms (instead of back to the previous page).
Why not imitate what many websites do and make it so going 'back' to a page works but doesn't display any information?
It depends on your code, but perhaps you can make your buttons and text (or whatever it is you don't want them interacting with) change to be unseen whenever they move on to a new page. Or just throw up a message that says 'You can't do that' to cover the page that they'll only ever see if they go back to view it again.

Need an example about console application which user can interact console window

I need write a console application like as hiren boot screen:
alt text http://xahoithongtin.com.vn/Images/diembao/2006_10/Hiren2.jpg
User can input a arrow key or a number for choosing. When a menu item is selected, I will fill a background for the selected menu item.
Please give me some guideline or example. Thanks.
The console class has all the core functionality you need.
To set the cursor to any desired position you can use the Console.CursorLeft or Console.CursorTop properties. A little example is already posted here.
For the colors you can use the Console.BackgroundColor and Console.ForegroundColor.
With these properties you should be able to write all this stuff onto the screen. Afterwards you need to check the user input (KeyUp, KeyDown pressed). This can be done by checking the result of Console.ReadKey() method. By setting the boolean paramter to true you can prevent that the pressed character is displayed on the screen itself.
With this base functionality you should be able to write your own helper class to make all this stuff a little more comfortable.
There are several .NET based NCurses libraries around that make creation of console based interfaces easier:
Curses#
MonoCurses
CursesSharp

how to identity a click out of the form and 1 more question

i want to build a simple program which help you selecting pictures.
if you have lot of picture and you want to choose some of them then you see them 1 by 1 and when you see a picture you would lik to save on other folder on your pcyou just press a button ,lets say f5 and the program copy the phtot from the path you looking at to the destiny folder.
for that program i need to ask how to know if someone pressed f5 out of the form area and how to know in which path the user looking at.(i want to build it for myself atm so if its help i look with microsoft office picture manager)
about the clicking i search a little and get something named global clicking and hooks which i dont understand so much and about identify the path i have no idea .
tyvm for help:)
I'm not sure I follow the rest -- but if you want to capture the keypress event, simply add an event handler for KeyPress and determine if the pressed key is equal to the F5 button by using the Keys constants.
Here is a project on Code Project that does exactly what you need :)
http://www.codeproject.com/KB/cs/globalhook.aspx
The key press event wont work with the following (Link):
TAB
INSERT
DELETE
HOME
END
PAGE UP
PAGE DOWN
F1-F2
ALT
Arrow keys
Note: I think there is a typo on the page and the F1-F2 really should be F1-F12.
When you decide the key for your on key press event for the form area you are talking about it will look like this:
private void Form_KeyPress(object sender, KeyPressEventArgs e)
{
if(e.KeyChar == [keypressvalue])
{
//do your copy logic
}
}
[keypressvalue] will be the code for F5 if you choose to use this. I have found a mix of values for this (i could not get my test keypress event to pick up the F5 event, hence my note above) so i recommend running the event once with a brake point, inspecting the code, then brake and update your code, then test your logic.
Like the rest i'm not really sure what you want your custom logic to do.
Clairifcation: I'm trying to understand your question, so what you want is: When in Microsoft Picture Manager when you press F5 you want the image that is currently being viewed to be moved to a particular directory? Now if you are writing your own picture viewer and move software then i think we can help if it is the above i'm not really sure you can do that.

Categories