A form contains many elements, such as labels, Textbox, radio options box etc
How do you detect the user has changed a textbox input value, or has choosen a radio option within the content of a web browser control? (not the winform itself).
Do you handle a winform event for when the mouse clicked or keyboard keys pressed? or is there a better way to detect changes in the web browser content?
There are "quick and easy" ways, but IMHO, a better way is to load the state of the form into javascript variables (on load), and then compare only the elements you are interested in, when navigating away, or whatever.
For example, there may be some fields that aren't so relevant (say, a different value in a minor drop-down box) but some that are very important (i.e. the contents of this message box).
It's fairly trivial to do anyway; just check the values you have currently (on the given event you are capturing, i.e. browser close) and then compare them with the ones you saved.
Related
I have a program I created which amongst other things has 20+ buttons which link to various sites and programs I use for work. The program has started being used by other people and the buttons don't quite meet their need.
What I would like to do is allow the user to set the button up to direct to a specified URL at runtime, and maintain that information for future use (I'll work on that bit later) - Allowing every user to cater it to their own criteria.
To make this easier, the buttons already exist with a generic name, and no text, and are initially invisible. All of them when in use would direct to a particular URL, nothing else. I would like the user to be able to click an "Add" button, set the button Text, text colour (I can do this bit) and fill in a text box to set the url for the browser (Default browser, not webBrowser.), which they would save, making the button visible, and usable.
I've had a look around, but cannot for the life of me work out how to do this.
Some guidance on the issue would be fantastic
Thanks in advance
Anthony
You could accomplish this using a DataGridView with a DataGridViewButtonColumn.
Because I had a set number of available buttons, I was able to create them and hide them. Set it up so the user sets the variable that the Start.Process. is using for the url, as well as set the button text in real time.
They save this information in a text document that's stored in the programs home folder, and this is pulled back through when the program is re-opened. This will work well for my simple purposes.
This might just be a small quirk. But I've built a small windows form application with multiple tabs.
I have a feature that allows users to "load" the entries in each of the tabs by opening a json file. This lets them avoid manually inserting the data. At the same time, I have a "check" to make sure that all required fields have been populated.
What I've found is that even if the load process is successfully populating all the right fields, the user still needs to select each tab (even though they are already filled), in order to avoid hitting the flag.
Hopefully, this makes sense. Right now, my work around is to have the program flip through each tab automatically upon "load", but it seems strange that winforms can't detect a text box has been filled unless the tab is viewed.
Any advice?
Some events only fire when the control is visible. This sounds like what you should do is decouple the text entries from the control and store them in another object which fires off the filled events then do data binding to those entries.
This has the nice benefit of decoupling the UI from the data storage (always a nice thing) as well as freeing you from the vagaries of the .net UI system (both winforms and wpf have 'interesting' quirks like the above which assume specific behavior preferences).
Since Microsoft doesn't allow to replace the system's virtual keyboard, I've developed a custom virtual keyboard as a UserControl to be used inside my Windows Store App. My current problem is that the default virtual keyboard always pops up whenever a user taps a TextBox.
I've been searching for a solution to this problem since yesterday, but I couldn't solve it. My almost successful attempt was developing a TextBox with a transparent Canvas over it. When the user taps the Canvas, the focus is programatically transferred to the TextBox and my custom virtual keyboard is instantiated. However, if no physical keyboard is connected to the tablet, the system keyboard also pops up with this approach (over my custom keyboard).
The main reason why I want to use a TextBox is because that way I can preserve and use the already implemented caret function, but it is not mandatory.
Any input will be helpful, thanks.
There are a couple of things you could do:
There are events for when the keyboard shows up, check those and see if you can prevent it.
You could implement a custom TextBox that suppresses OnPointerPressed event so that the TextBox is never focused. There are a couple of other things you'll need to do (such as prevent tabbing into it giving focus by setting IsTabStop=false.
You could implement a custom TextBox from the ground up (that looks and acts like a TextBox).
I think the second option is the easiest and most interesting option to try.
Edit: You could also give your TextBox a DependencyProperty that you set the current Page to via bindings. In the TextBox's OnGotFocus event, set the visual state to "CustomFocus" (or whatever you call it), then call Page.Focus();
Is there a way to store all the window form events inside a list, so all of those events can be reapplied when the user opens the form next time?
Example: Let's say the user clicks a button inside a form and types in a string and then closes the form. After a while the user reopens the application again, and the form is re-initialized so that the click action and the string the user input is restored. (Kind of like an auto-save function.)
Purpose for this:
Recover after suspension.
Allow user to undo their work (Undo Button).
I am still not sure I understand you, but you say you want to get a list of events, okay, that can be done using Reflection. Here is a good link: http://www.switchonthecode.com/tutorials/csharp-tutorial-using-reflection-to-get-object-information
Your example:
Let's say the user clicks a button inside a form and type in a string,
he then closes the form, after a while he open the application again,
and form can re-initialize the form and apply the click action and the
string he inputted(kind of like an auto-save function).
-You can do this without getting a list of events. So I don't see why you have to do it this way. There are multiple ways to do this. If you are using a winform, one basic solution is to define properties using the settings page. Check this out:
http://msdn.microsoft.com/en-us/library/cftf714c(VS.90).aspx
Use the Settings page of the Project Designer to specify a project's application settings. Application settings enable you to store and retrieve property settings and other information for your application dynamically. They also enable you to maintain custom application and user preferences on a client computer. For more information, see Application Settings.
To access the Settings page, select a project node in Solution
Explorer, and then, on the Project menu, click Properties. When the
Project Designer appears, click the Settings tab.
You can establish waypoints (to borrow a term from aviation) and save values to your settings collection periodically without the user having to do anything, like they would have to do if you provided a save button. But that just brings up the point, what's wrong will the lowly save button. It's a well known convention. People know that if they don't want to lose data, they should save every now and then.
Is it possible to take focus from another program to respond to an event, but then once the response has been handled, switch back to the previous program and restore the cursor where it was?
This sounds like a weird question, but think of it along the lines of
User is typing in a text box in Program A.
A window for Program B pops up and user presses a few buttons to confirm something.
Program B returns control to Program A and restores the selection of the textbox.
If there is a complete C# solution, then great, but this sounds like it might require a little more effort than usual.
Any thoughts?
Personally, doing this could very likely result in the user selecting undesired values in the popup window. For example, someone is typing away in Word. Your application pops up a window, where hitting "Enter" selects a value ... such as the default button. Without wanting to, the user "selected" an incorrect value on your form.
Windows itself tends to do this, and it's very annoying. Quickly double-clicking a desktop shortcut to open an application and then switching back to (for example) an e-mail before the app launches, will tend to remove focus from the focused e-mail window and put focus in the just-opened application, causing your e-mail text or keyboard strokes to go to the just-opened window.
In my experience windows programs work just this way. It often appears that they don't because the user is returning focus with a mouse-click, which itself resets the focus. If it's a winforms app you can probably do something with the lost focus/got focus events at the form level.