Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I am using Visual Studio in C# (.Net 4.5). I have a lot of code behind one button and it gets confusing. Can anyone tell me how I can split that code and put some of it in a separate file and link the file to the main one? I don't wish to create classes and all, operations behind that button should execute in a sequential mode. This must be simple but I can't find the solution on the web. Perhaps it is even too simple... Forgive me, I'm a total noob!
There is nothing wrong with having class at all, and it makes thing less convoluted and clear. It's actually exactly what you want to address, as you're not happy with the code you have.
Try this, and if you're not happy with outcome, keep having long, "pythonish" function
Split your button big logic into semantically pronounced pieces, even with comments and moving code up and down
Create a class
Move pieces created at 1st step into separate distinct functions
Call them sequentially, as you want, into the "big" function of a class you've created in 2nd step
Call that single function of newly created class from your Button click handler
Make your class Partial and move different functions created on 3rd step into different files
This is very bad practice. This anti-pattern is magic pushbutton. Changing the user interface (or adding a new interface) becomes difficult, for example, deleting a button may result in the removal of related methods.
More information: https://en.wikipedia.org/wiki/Magic_pushbutton
Perhaps this page in the visual studio documentation is what you are looking for.
In Microsoft Visual Studio, Solution Explorer, right-click the
project to which you want to add an existing item and click Add
Existing Item.
In the Add Existing Item - dialog box, browse to and select the file that contains the item you want to add.
Click Add to create a copy of the selected file, or click the down arrow to the right of the Add button and click Add As Link to create a link to the file instead of creating a copy of the file.
https://knowledge.autodesk.com/search-result/caas/CloudHelp/cloudhelp/2015/ENU/AutoCAD-NET/files/GUID-9C205780-8091-4AFE-9480-5BD69711B806-htm.html
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Me and my family use a command line application frequently. It gets tedious because sometimes the amount of chars entered can be a lot. My son asked me if it is possible to make it like a normal program. (He's 10, doesn't even know what a VCR or a touch-tone phone is lol.) Anyhow, I told him that someone would have to write a program for it. He say's he wants to. (I'm thinking I know who's going to take care of me and my wife in the future... lol j/k...) This will be a learning experience for both of us.
So, let's begin his career!
I'm not looking for someone to write the whole thing for us. We just need a good start.
How can we create a GUI for a command-line exe? (The exe is open source and is written in python but for now we'll stick with passing cmd's to the exe and reading its output.)
So we are looking for:
a textbox for our input, a few radio buttons for args, submit button and a clear button. I guess there should be a place to define the path to the exe.
Syntax: command --argument-abc --argument-xyz <textbox-data>
If no options are selected it should default to: command <textbox-data>
The 3 options we basically are starting with are: This way, That way or both
It should show the console output live as its running.
Here is a SS of where we want to start.
Preliminary Layout
Down the road we will package it together but I think this should be a good start to get us going. The exe has hundreds of different args that will be added over time on an options tab or what not.
We are using Microsoft Visual Studio 2017
Sorry for the rambling.
Oh and one last thing. Please point us to some good articles, how-to's, or anything that you think will help us learn what we need for this.
If you don't mind doing it in Python, then perrhaps PySimpleGUI will work for you.
There is a Demo program that does exactly this, add a GUI to the front-end of a command-line program.
OpenSource.com recently published an article that steps you through how to do this.
Just for fun I've duplicated the GUI you posed using PySimpleGUI. It is under 20 lines of code.
I recently combined my GUI python programs with PyInstaller. It produces a single .EXE file that runs and shows only my GUI window. The command I use instructs PyInstaller to hide the dos window.
pyinstaller -wF my_gui_program.py
PySimpleGUI Code and screen capture of window
With CommanUI you can specify your command line model and generate a GUI for it without coding.
Another alternative option is to use PowerShell to do this - the later versions have the .net framework built in, and can create user forms like in vb.net. If you have experience in vb.net, it should make it easier. As an extra advantage, PowerShell can usually use the same (or similar) commands as Command Prompt, so it should be familiar.
Take a look here for more information, however a quick google search for PowerShell GUI should be sufficient.
However, MikeyB is quite correct when he says that Python is a good language to learn - it's used in a lot of different areas in the industry (I still personally prefer vb.net though, I only looked at Python for a month).
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I've got this task that requires me to generate some basic C code using a software written in C#.
The generated code should be based on some input files I provide to my software, we'll call it btOS for easy of communication.
So when starting btOS I give it as input file1, config.xml. When I hit run it should output a file.c that contains some basic structures and/or methods based on what the input files contain.
Is there any elegant way to do this ? Maybe some already generated templates or methods or stuff like that ? The only way I could think of handling this was creating specific strings in C# and outputting them to a C file.
L.E.: It seems that somehow my question was not clear enough. I assume the fault of including C++ in the title, I have remove it but I don't see how that is relevant because the question was very simple.
Anyway, to make it more clear. All i need to do is read some config files (their content is irrelevant, all they contain are some variables that will be used to generate some function templates, which will mostly impact the name of the function) - and write an output file with the extension .C (as in Main.c) that will contain those templates I generated.
So, again, the question: Are there any "elegant" and maybe somehow "professional" ways to do this other than using custom generated strings within the code that I will write to the file ? Right now the only way I see fit to do this without too much hassle is using some template text files with a naming convention defined by me(e.g. function_variableName{...}) where I just change the [variableName] text with whatever I need to to be there and "Abracadabra" I have a function that I will write to the file.
Now as Soonts suggested please try and be helpful, read multiple times if you don't clearly understand or maybe even don't bother - let somebody who is interested in this topic, tries to help or gain some new knowledge before flagging it.
Double Cheers.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
So i have a Pricing Table with 3 options, all on Upgrade.aspx.
'Starter'
'Champ'
'Master'
There is a button for each option. They will all navigate to Payment.aspx, but i want some variables, such as cost, and plan name, to be different based on what button they clicked on the previous page.
So if they clicked 'Starter' button, the Payment.aspx page would say Starter. But if they clicked the 'Champ' button, the Payment.aspx page would say Champ.
There are a lot of different ways you could do this. It seems a little ambiguous what would work best for your situation however.
One option is to create a singleton class with a variable which you set via button handles (IE sets the variable to "Starter" if that button was pressed).
Then the view for the Payment.aspx page could pull the information from the singleton class or consume it however you want it to.
You could also use form data, cookies, databases, and a variety of other things. It depends on where you want to store the data and how is easiest for you to store it.
There are a ton of facilities for this kind of event handling. I'd recommend looking at this article and see how it works for you MSDN - Cross-Page Posting in ASP.NET Web forms
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm trying to make like a container application where you can drag and drop files of any kind on the form and afterwards to be able to open it from there. I found some solutions where you can drag and drop files to a list view and you get it's path.. but is not how I want.. I want to have on my form in a panel or what ever is better like a shortcut of the file, an image or something to be able to see the file icon like is in explorer.
Have someone ever done something like this or point me to the right direction?
Set "Allow drop" property to "true" on your control and make use of Control.DragDrop event - it's exist on all controls, and it's invoked after drag'n'drop anything on anything(if "Allow drop" is true of course).
It this event-handler you can add new item to this or another control(ListView fits nicely to your needs), and for example to some "Dictionary" where you will store "Item and filename mapping".
Also you need to make handler for item click'ing - for ListView there a ItemActivate event. Inside this handler you can click execute default shell-action for this file by using Process.Start
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I need to learn a certain programming subject and I don't know where to start, would like your help.
This is what I need do do, I have a user form (UI) and the user enter "Rules" in the form of:
if operator(obj1) then assign(obj1,string)...
I take this rules, and translate them into actual code, and I want to put that code somewhere in a function/my code.
for example:
main {
UI...
/* when we reach here, means the user done writing rules */
/*Function that translate the user rules to actual code */
translate();
for {
/* This is where I want to put the code after translation */
}
}
How do I put the code inside the loop (or anywhere else for that matters) after the program started running?
I ofcourse don't look for an actual answer, more to give you an idea what I need so you can refer me to a certain subject to study about.
I presume, you are in process of creating a custom rule engine, which has the capability of validating your rules on fly. Within my ability, you need to start reading c# scripting, code generation, dynamic loading or reflection etc are some to start with.
To give a kick start, following are some of the step which I can think off;
Grab the rule definition (xml or csv)
Write a small helper which will read rule entries from the definition and convert it into
c# source code. This is similar to c# scripting.
On successful completion of (2), create a dll out of the source code
Now reflect/dynamically load the dll from (3) to where ever you wanted to validate the rule.