We are importing form, from existing project to our new project.
It works well in run time, but we can't see controls to modify them in design mode!
Do you know how what we do to see them?
i found it, when i add exist form to my project, in addition add formX.cs, also add another along files (designer and res). thats enough add formX.cs .
Related
In short, im creating a Visual Studio extension in c# that enables non-automation testers to create automation scripts for web based solutions (using selenium).
We've created a template already for users that lays out the project file structure (test runners etc) and im using windows forms toolbox controls to create the dialogue windows where they will enter things like URls, Xpaths, page names etc etc
My question is this;
How on earth do i go about creating .CS files dynamically based on their inputs in these toolbox windows?
The simplest (he says) window i have is one that simply allows them to enter a URl and a webpage name. When they click the 'ok' button on this window, it should create a new .CS file with the webpage name as the class name, the url as a string that the webdriver can use to kick off the test and a few other bits and pieces as a template for them to start adding web elements to.
Any guidance would be greatly appreciated, there seems to be precious little around the web about creating VS extensions!
You got a few options here.
Typically, most people would do this by implementing a custom project item template, along with a custom IWizard based wizard associated with your template.
If you are displaying a modal UI from your IWizard.RunStarted, you can simply populate the ReplacementsDictionary with the text gleaned from your custom UI, which would then be swapped for the tokens in your templatized .cs file.
Or you could programmatically add code to the file after it was generated and added to the project (admittedly a much uglier and more difficult to code).
And finally, you could just generate the file in the project directory, and programmatically add it after the fact.
There's a number of old blog articles from the archived VSX Arcana blog that you might also find helpful.
I'm very newer developing .NET web applications. Before read, I'm so sorry if I'm not able to explain correctly or if I'm confusing about something of .NET. Hope all of you can give me some light in .NET environment.
Context: We have two different solutions because the original idea was to develop two different applications with no common pages or content between them. Now, we need to have one of the aspx page that is in the solution1 inside the solution2 (and probably more in the future) because it's common between them.The idea is not to have two different maintenance of the same page. This two solutions have only one project inside them and each project has his own master page.
Solution1:
-Project1
Solution2:
-Project2
Question 1: Is it possible to import or use complete aspx page across the solutions? I mean, I know that is possible to import aspx files from the project1 into the project2, but doing this way, every change into the original aspx file of project1 means that is needed a new import into project2 (or this is what I think) to have the page up to date. What is the best way to share content between different solutions?
Thanks in advance.
You should be able to add the aspx page which exists in one solution (and version controlled hopefully!), to your other solution by adding it as a linked file.
MSDN explains how Visual Studio allows you to add an item as a link rather than directly adding the file to your project.
By linking to a file, you can capture ongoing changes to a source file without having to manually update a copy whenever changes are made. However, if the underlying file is deleted, the link will be broken.
To create a link to an existing item
In Solution Explorer, select the target project.
On the Project menu, select Add Existing Item.
In the Add Existing Item dialog box, locate and select the project
item you want to link.
From the Open button drop-down list, select Add As Link.
https://msdn.microsoft.com/en-us/library/9f4t9t92(v=vs.90).aspx#Anchor_0
Another helpful article by Grant Winney on the topic here:
https://grantwinney.com/visual-studio-add-file-as-link/
When I create a new project of the predefined templates, say a new windows form application – it starts out showing me the designer view of Form1.
What I want to do is something similar with the custom template. (Actually, I want the code-view.) Currently, nothing is shown automatically.
I created the project with “Export template”.
open your template zip file and in file *.vstemplate add attribute OpenInEditor="true" to code files you would like to open on project creation (ProjectItem). i tried to open code for Form and i failed, but it works pretty well for simple code files.
I found some code to help me in a project and when I first ran the code I received an error message indicating: "Visual Studio cannot start debugging because the debug target c:\path\'dirInfo.exe' is missing. Please build the project and retry, or set the OutPath and AssemblyName properties appropriately to point at the correct location for the target assembly."
Then I select OK and receive an error message indicating that partial is missing. I add partial to the code and receive 3 more error messages.
The type 'RecursiveSearchCS.Form1' already contains a definition for 'components'
does this mean I should delete this from the Form1.cs file?
Type 'RecursiveSearchCS.Form1' already defines a member called 'Dispose' with the same parameter types.
Type 'RecursiveSearchCS.Form1' already defines a member called 'InitializeComponent' with the same parameter types.
(I notice, when I comment out the InitializeComponent line and/or Dispose line, many more error messages populate in ERRORS)
By they way you can find the original code # MicrosoftSite.
Any help would be greatly appreciated.
Thank You
Just gut instinct, if you were following along and copy pasting remember one key thing:
The designer creates two files when you create a form: A "code" file, and a "designer" file. However, when microsoft (and others) release "templates", they like to merge these two files.
Just create a new .cs file and paste the code and all should be good. It's the code basically saying "in the designer, we already have this stuff". (a good way to note this is the "partial" keyword located before your Form1 declaration)
More info:
The Code file will house all your own implementations. That is click events, methods you personally override, events you bind to, etc. This is the default file when you select "View Code" from either your solution explorer or the dialog itself. Within this file is a construct that calls a "hidden" method, (InitializeComponent) that if you right click and "Go to Definition" will bring you to the next file:
The Designer file is the IDE's generated file. This takes everything you do in the designer and stores it for you. That includes new controls, location and properties of the controls, and the IDisposable implementation. The idea is to keep the "meat an potatoes" out of the way while you worry only about implementation.
Yes it sounds like you've copied the entire code which includes many things already contained within your Form in a partial class. Either remove these or remove the partial class and partial class declaration from your Form to get rid of these errors
I went to the Microsoft site to see what you did. The site shows code for an entire "one file" solution. We've all agreed that Visual Studio creates multi-file solutions, so you're duplicating code.
I don't know if the current answers/comments have helped you get this sample code working, so I thought I'd add my share. I was able to get this sample working by doing the following:
First, where the sample code at the Microsoft site shows declarations for button, textbox, labels, and combobox, rather than attempting to copy that portion, I simply used the toolbox and dragged a button, the labels, the textbox, and the combobox from the toolbox to my form.
You'll probably want to arrange these to your liking.
This process created my form correctly with the appropriate objects on it. All I had to do was use the properties window for each object and rename them according to what they were named in the sample. For example, my new button was originally button1, but I renamed it to btnSearch just as it is named in the Microsoft sample.
I noticed that the Microsoft sample has an established event handler setup for the Form1_load() event. I created this same event in my form by clicking the form in the designer, clicking properties, clicking on the Events button in that properties, and double-clicking the "Load" event. This automatically generated the appropriate code.
In a similar way, I had to create the btnSearch_Click() event. I did this by simply double-clicking the button in the designer.
After that, all I had to do was manually copy and paste from the specific sections of the sample to my code -- fill in the Form1_Load() event with what was in the sample. Copy the DirSearch() method over. Fill in the btnSearch_Click() event. That was it.
I hope this helps solve the overall issue and gives you more insight into how you can avoid these problems in the future.
You have duplicated functionality in the classes, you have a file that was automatically generated with that functionality already in it.
I have a form in my existing project.
My current task is to make a duplicate of an existing form and change few things on the new form. Making a copy of the form cs files would not do since the existing contents themselves refer to file information.
Simply put, I am trying to crate a form name MyNewForm, which will be a direct duplicate of MyCurrentForm without causing any naming conflict that may arise in mere copy pasting of code content.
What is the fastest way I can achieve this?
Copy the form in visual studio solution explorer. Rename it. And change the class name manually both in .cs and .Designer.cs files. Do not use VS refactoring feature as it blows away references to the original class.
To duplicate a form (in the same project):
Right click on the source form --> Copy
Right click on the destination folder/project --> Paste
Right click on the new form --> Rename
Change manually the class name in .cs
Change manually the constructor name in .cs
Change manually the class name in .Designer.cs
Enjoy!
Why do you need to make a duplication of the form? Try to find some refactoring that can help you, e.g. create some base form and extract common logic there.
Every time you make a duplication kitten dies!
You can just add a new blank form and then select all items on the original aform and paste them onto the new form. This will not copy the code behind though. But that can also be solved with copy paste.
This will not cause any renaming conflicts.