C# Setting Button URL Direct At Runtime - c#

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.

Related

Get new Messagebox style - WPF

I am currently working on a Windows Presentation Foundation app and I need to make use of Message boxes. I want to get few information from user inside Message Box popup.
But they appear always like this:
But I think the actual look of it should be like that:
Does anybody know, why this is, and how to solve it? I tried all everything listed
here
, but nothing worked.
I agree with Keithernet, build your own. Its more of an Input Dialog box. You may want to plan it to create a window, create it with ex: 4 parameters which you could override so you can apply them in the form including
The title,
The prompt you want the user to fill in
optional default button 1 text
optional default button 2 text.
have the input value stored into a public property in the window for the text to be bound to during entry.
If the user clicks the cancel button (or similar), clear the text entry and close the window. If ok button, just close the window.
Then, when you call it with a YourWindow.ShowDialog(), upon return, you can look at the public property for that input text value.
You could even do with a property / flag if the user cancelled directly or not. I have done similar in a couple of my WPF apps.
MessageBox is very limited. Based on your screenshot, you should just create your own child Window with your own XAML so you can get the user input.
You can find sample service implementations/NuGets for this on GitHub. Here is one I've created sometime ago: https://github.com/Dirkster99/MsgBox
Just create your own is an oversimplifying statement in my opinion because this is usually a dialog that you want to show in different parts of the application. Therefore, you have to settle for a software design pattern (I chose a service implementation as suggested here).
Likewise, there are other design decisions that should be taken. I have for instance made sure that the API has a compatible subset of Show API calls with the standard .Net MessageBox to make its application as flexible as possible. I also settled for light and dark themes hoping this will make its application easy in any other theme...

How can I open a webpage first and then fill in text boxes and click a button and visibly view the results?

[edit] It is a requirement that the webpage spawn and open in IE and allow user manual interaction after the programmatic actions have completed.[/edit]
I've seen a lot of code examples online about opening webpages or filling in webpage textboxes and getting a return value without ever opening them visibly.
I would like to open a webpage in IE, fill in a few textbox buttons
and then click the submit button and view the results visibly.
I am able to do this with a dll called Selenium, but I do not want to use a 3rd party application and it seems that WebBrowser() should be able to do this?
I can post my failed code examples if that would help.
Thanks.
Maybe this qould fit better as a comment, but I don't have enoigh reputation.
Do you know how HTTP-Forms work?
It would probably be easier to send a HTTP-Request to the target of the form you want to fill, including the parameters you would like to fill into the form.
So you don't need any WebBrowser or similar, just a simple HttpWebRequest object, where you specity the target, the method (very likely POST) and the data you'd like to send.
You can use the webbrowser control in Winforms. It is possible to access every DOM object of the website using the control. No need to open the IE externally.
You just need to specify the webbrowser URL as your link.
Then, fill the textboxes with code,
BrowserID.Document.GetElementById("TextboxID").SetAttribute("Value", "NewVaue")
Also, you can click on the button using InvokeMember("click").
There are lots of stuff using WebBrowser. You can learn it here.

Programmatically change headphone's button behavior

Is it possible to programmatically change the process that starts once the user click the LifeChat LX-3000 center button?
I don't have any kind of experience programming with hardware so don't know if it's even possible. The problem is, a client of us has a lot of this headphones and we want to be able to change the default behavior of that button from open live messenger to open our CRM. I try to follow this instructions to modify the registry as doing (not programmatically):
Find HKEY_CLASSES_ROOT\CLSID{F5F545A6-39C4-40B5-814D-B45040A89FB5}\LocalServer32
Remove the (Default) value by double clicking it and deleting the text
Change the value to OurCRMExePath
But this doesn't work. I suppose things changed since the date that web page was wrote. Any idea? I suppose first step would be to know which registry entry does that button modify and then go and change it. But, how can one get to know that?

How to make a tab's name editable in C#?

So I have a few tabs in the form, and i want it to work like that:
When you click on the tab's name, it becomes editable, and when i stop editing it remains with the new name.
How would i do that with C# and winforms?
You can dynamically create a text box and place it over the tab area to make the user think they are editing the tab directly. When the text box loses focus you can then put the typed in value into the tabs property.
I agree with Eric, regarding how you could do this with the standard TabControl. You could also provide a dialog to do the name change (a slight variation on Eric's suggestion).
However, I would also recommend that you consider rolling your own tabbed control. They're not difficult to create and by rolling your own, you will be able to put in the exact functionality you need in a robust way rather than trying to piece it together from existing components that may not play nicely together.
There's no standard Windows control that does this, so you'll either need to look for a third-party control with this functionality (iffy) or write your own control which draws the appropriate edit box on the tab, etc.

Checking for Shift+Click or Ctrl+Click in a Web User Control

I have a requirement to produce a Web User Control (in C#) which will exhibit different behaviour when clicked depending on whether the shift (or control) key is pressed at the time. The control itself will contain an ImageButton and/or Hyperlink.
Is this possible?
Basically, if the logged in user is an Admin then I need to allow them access to update the associated URL. I don't want to have a separate page for this admin as it will cause confusion.
Thanks in advance
How about here?
To implement the Ctrl / Alt / Shift detection, you can use the properties event.ctrlKey, event.altKey, event.shiftKey and the deprecated Navigator-specific property event.modifiers.
Your control needs to emit some javascript to detect what keys are being pressed when it is clicked on.
Here is a primer from w3schools on events, here is a list of events of the window object you can listen to (such as onkeydown for keyboard presses).
I'd discourage this as it will get you into serious trouble with different browser versions.
As long as you aren't targeting one browser explicitly you'll be doing maintenance work for various browsers all the time.
A way around this is to find a supported Javascript library like jQuery that supports this behavior and let the maintainers of that library care about browser compatibility (You still need to update that library then..)
Well the 'powers' have decided that the Shift/Ctrl + Click approach was too clunky.
After a brainstorming session we have decided to go down the route of displaying a small 'Edit' button next to the control. This will only be visible for Administrator users and I've pulled it together in about two hours.
Thanks for taking the time to provide your input.
Can someone with a high rep please close this question for me - thanks.

Categories

Resources