I am trying to store/retrieve a value that is stored in the Application Settings. From within my console application I can not seem to access the Properties.Setting namespace. My web surfing has revealed that a little more work might be needed to do this from within a Console application. How does one do this?
string test = Properties.Settings.Default.MyString;
Thanks!
By default there is no Settings file in a Console application. However, you can add one simply by right-clicking your project in the solution explorer, choosing "Properties" and then in the resulting window, click the "Settings" tab.
There should be a link saying "Click here to create a default settings file". Once that's created, you're off to the races.
Ensure the namespace of the class you're using is the default namespace of your project.
2.then you cna use
string s = Properties.Settings.Default.THENAMEINSETTINGS;
.
So.. Once I created my Settings.settings file in the project that is saving the property I ran into the issue of how to access these properties from another project in the same solution. The settings object is sealed so you have to use a little trickery to gain access to the property values in another project. I found my solution here:
http://blog.decarufel.net/2007/10/getting-access-to-settings-in-another.html
Basically you create a link file to the Settings.Designer.cs file in the project where you are trying to retrieve the values.
I hope this helps someone with a similar issue.
-Nick
Related
I am probably facing a basic problem. I would like to create TimePickers as in this project link: TimePickerProject
This project was given as reference in one of the Stack overflow answers Stack OverflowAnswer
You can download and directly run that project really easy. But couldn't add it to my own project as an independent TimerPicker Object. TimePicker class is inside Opulos folder. As you can see Opulos folder is copy pasted to my own project.
I
And I can see that Timepicker inside my toolbox.
But when I try to drag it to my panel I am facing with this error.
To explain this process more clearly:
Just paste the Opulos folder into the root directory of your program. (I am here. Net framework 4.8 winform)
Edit Opulos/Core/UI/TimePicker.cs
Add the below codes:
public TimePicker() :this(3, true, true, true, true) {
}
Then rebuild the program, you could find it in the toolbox.
Output:
Thanks to jimi's explanation:
Pass default values or configure it to generate a different pre-defined behavior when the class is created via ToolBox.
Keep in mind that those classes are not built with the ToolBox in mind (no reference to ToolBox behavior is specified anywhere), it looks like all are meant to be instantiated in code.
I.e., you may have the same problem somewhere else.
You should know what to do (though decorating the public Control classes with appropriate [ToolboxItem], [ToolboxBitmap] etc. stuff should be considered)
If you are trying to drag another folder into your solution folder, then you can use the default windows file explorer. If you want to import a library from another project, simply right click Dependencies->add project reference, browse, and select the library. In general, you should avoid copying the code itself, and instead add a reference to the output.
Hope I could help, if I misunderstood your question I apologize!
I have a solution that contains 2 winforms app and a classlibrary referenced by the 2 apps... I added some images in resource
but when I go on the winform app and try to add the image into a button appears this:
Is there a way to do this?
thanks
You have to make resource items public instead internal.
To do this, in .resx file in solution explorer select Property Window (Alt+Enter) and in File Properties -> Custom Tool should be ResXFileCodeGenerator
Change this option to PublicResXFileCodeGenerator (if option don't show in dropdown field, don't worry aboit it, write/type PublicResXFileCodeGenerator in field)
After that resources member class will be generated with public modifier and you can access to it from any project that reference assembly.
I hope it can help you!
I'm trying to use an embedded resource in a console application, but apparently console applications don't come with a resource file automatically. How do I create a resources file for my console app?
The project template for a console mode application doesn't have pre-cooked Resources. You simply add it with Project + Properties, Resources tab, click the "Click here to create one" link. Take an hour and click around some more. This is all very discoverable but you have to take a look.
Right click on the console application project node in the solution explorer. Add->New Item->Resources File.
edit: as has been pointed out, if you open the Properties of the console app project, it will also have a Resources tab, which will tell you that it doesn't have a resources file and provide you with a link to create one. This will do the same thing as the above, except that it will create the files under the Properties folder.
I added the answer in my answer to your previous question:
Right-Click on 'test' in Solution Explorer -> Add -> New Item -> Resources File
Then double-click on the created file (e.g. Resource1.resx), and take it from there.
Then use it:
string s = Resource1.String1;
Right click your project.
Select Properties.
In Resources click the link "This project does not contain a default resource file". Click here to add one.".
Understanding the fundamentals.
Just build your default
public class Lang {
public string Title = "my title";
}
then
public class Lang_en_US : Lang{
public Lang_en_US(){
Title = "my US Title";
}
}
then find your lang you want to case into with switch, if not match, just use the default
ASP.net compiles into classes like the global resource.
:)
This is a pretty minor annoyance, but I noticed that every time I create a class in Visual Studio there are a few things that I would like to be automatically-generated for me. For instance, all of my classes start with a log4net declaration. It's only one line of code, but it's annoying having to find a class where I declared it in to copy/paste from.
In addition, there are multiple common 'usings' which I use, but that are not created by default.
Is it possible to setup VS to do this?
You just need to edit the default Visual Studio Class template. A walkthrough of the process can be found here.
From the File menu, select "Export Template".
You can create your own item/project templates. Here is a primer from MSDN:
http://msdn.microsoft.com/en-us/library/6db0hwky.aspx
Basically you'd create your own custom class template.
From MSDN:
Creating Project and Item Templates
How to: Manually Create Item Templates:
Create a project and project item.
Modify the project item until it is ready to be saved as a template.
As appropriate, modify the code file to indicate where parameter replacement should occur. For more information about parameter replacement, see How to: Substitute Parameters in a Template.
Create an XML file and save it by using a .vstemplate file name extension, in the same directory as your new item template.
Author the .vstemplate XML file to provide item template metadata. For more information, see the example in the following section.
Save the .vstemplate file and close it.
In Windows Explorer, select the files you want to include in your template, right-click the selection, click Send To, and then click Compressed (zipped) Folder. The files that you selected are compressed into a .zip file.
Copy the .zip file and paste it in the user item template location. In Windows Vista, the default directory is ..\Users\\Documents\Visual Studio 2010\Templates\ItemTemplates. For more information, see How to: Locate and Organize Project and Item Templates.
Although not exactly what you are asking for, one option is to declare code snippets. This will allow you to leave the standard class alone (not change the template) and add in the pieces that you require without having to find a class with it. However, if all your classes for every project you create requires the same basic set of code then Templates are the way to go.
C# Code Snippets
How to use them can be found How to Use Snippets
I have a C# web service, created using VS2008.
I have a deployment project that creates the MSI I use for deployment.
Is there a setting somewhere to change the default virtual directory that the user is prompted with during the installation?
I'd prefer to not change the name of the webservice to do this.
But isn´t this a simple case of right-clicking the setup project:
select View-> File System.
From the File system explorer, click the Web Application Folder. Press F4 to bring up the properties window (if it isn´t already visible).
In the properties window, scroll down to VirtualDirectory and change it to whatever you want.
Does that work for you?
I think I have the fix.
I couldn't find a fix thru the VS UI, so you'll need to locate your deployment project (file extention is .vdproj) and open in notepad.
Search for "VirtualDirectory"
You'll find a line similar to this:
"VirtualDirectory" = "8:OldName"
Where OldName is the current default you're seeing during installation.
Change "OldName" to whatever you want for a default. Save and build.
If there's a way to do this thru the UI, that would be even better, I couldn't find it and this works.
Visual Studio 2015. The virtual directory can be changed on the properties for the Web.ApplicationFolder for web applications