|
In WinForms there is a resource manager that is supposed to keep track of the resources for you, but I think its best practice to call free up resources right away.
If there is a managed wrapper for the resource just call Dispose on it to do that; else you'll have to dispose of it yourself.
James
Simplicity Rules!
|
|
|
|
|
Thanks Mr Johnson,
I realised about the Dispose, but what happens if I don't use it and the user exits the App.
Is there a resource leak ?
Regardz
Colin J Davies
Sonork ID 100.9197:Colin
More about me
|
|
|
|
|
As I understand it, if you used objects handled by the Resource Manager it will free those for you; ones that aren't handled by it will get free'd if and only if their finalize method frees them.
James
Simplicity Rules!
|
|
|
|
|
does anyone know how to create this file (app.config) when working with winforms(it's similar to the web.conf in asp.net)? This file gets created with some projects but not others and I was not paying attention when it got create. I just noticed it one day and started adding keys to hold my connection string. But now I need to know how to create this file and I don't know how.
|
|
|
|
|
Whooya!!! This one took me forever to figure it out. Basically, select a control. Then select its properties. For most controls you will have either DataBinding or DynamicProperties section on the properties list. Go into Advance and select the items you want to place in the config file. An app.config file will automatically be generated.
|
|
|
|
|
You can create MyApp.exe.config in the same directory where your app resides,
and than use System.Configuration.ConfigurationSettings to read the configuration file app settings.
Config file example:
<configuration>
<appSettings>
<add key="Database" value="MyDB" />
<add key="Username" value="code" />
<add key="Password" value="project" />
</appSettings>
</configuration
-Gile
|
|
|
|
|
I've found this topic not well documented.. actually, I was playing with Custom Configuration Handlers, but it's related.
Ok, to the point , every time you compile your program using Visual Studio .NET it will look for a file named app.config, if the file exists, it will create an output file on your destination directory (Release or debug for example) with the following name:
<ApplicationName>.exe.config
This file will contain the data you put on app.config.
Be aware that this file will be recreated everytime you compile your program (this got me for a while), so if you change the output config file, the changes will be lost on your next recompile.
If you need to change the config file during development, change app.config, you are going to see these changes reflected on your output file.
Hope this helps.
Andres Manggini.
Buenos Aires - Argentina.
|
|
|
|
|
Ok, I know this must be a really dumb question, but how do I add an image to my project in Visual Studio.NET so that I can reference it in code such as "myPicture.jpg" . Thanks again, don't laugh too much
Nick Parker
|
|
|
|
|
So such thing as a dumb question
Right click on the project and choose Add Existing Item, select your jpg. Click on it in Solution Explorer then in the properties box change the Build Type from Content to Embedded Resource.
Now when you want to load it,
Bitmap myJPG = new Bitmap(GetType(), "myPicture.jpg"); assuming that the class is in the same assembly (ie project) as the jpg.
Good Luck,
James
Simplicity Rules!
|
|
|
|
|
Thanks James, sometimes some of the easiest things aren't known by all, I just hope this helps someone else too.
Nick Parker
|
|
|
|
|
I wouldn't classify it as the easiest thing to come up with; it took me about a day of working on my own to figure it out. And then I read it last week in Petzold's book
James
Simplicity Rules!
|
|
|
|
|
James T. Johnson wrote:
So such thing as a dumb question
Are you sure ? :P
This question was one that got me though, and I still don't think I fully have a handle on how to make it work. It just happens to work in the project I am working on, so I don't mess with it. Actually, I think someone else fixed it for me...
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
LOL, I just now saw that I mis-spelled 'No'
Christian Graus wrote:
Are you sure ?
No, I'm never sure of myself; to become sure makes me ignorant of other possibilities. I am confident in my answers though but I leave myself open to other solutions
Christian Graus wrote:
Actually, I think someone else fixed it for me...
Wonder who?
I think when we've got the screensaver pretty hammered out I'll write an article on using resources. Then I need to write part two to Nish's Registry article
James
Simplicity Rules!
|
|
|
|
|
James T. Johnson wrote:
I think when we've got the screensaver pretty hammered out I'll write an article on using resources. Then I need to write part two to Nish's Registry article
I'd considered trying to hammer out a decent registry class. I still have my bottleneck detector code waiting for an article, as well. I'd like to get a decent article up on the screensaver as well, sometime soonish.
I'd love to read an article on using resources, I couldn't get that thing you did to put them into a subfolder to work at *all*.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
James T. Johnson wrote:
Bitmap myJPG = new Bitmap(GetType(), "myPicture.jpg");
James, if I wanted to draw this image in a random location on the screen after I create my graphics object Graphics grfx; , what method do you suggest, there are 30 of them with just the .DrawImage() method(s).
Nick Parker
|
|
|
|
|
If you just want to Draw it without modifications, use DrawImageUnscaled; each of the other variations of DrawImage let you do slightly different things, about half of them doing the same but taking RectangleF/PointF instead of Rectangle/Point.
James
Simplicity Rules!
|
|
|
|
|
Or you can change the Bounds of the PictureBox... do you use a picture box!?
------------------------------------
Rickard Andersson, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|
C++ allows to use default values for parameters e.g.
void MyFun(int nParam1, nDefault = 0);
Is it possible in C#? If yes, how to do it?
|
|
|
|
|
void MyFun(int nParam1)
{
MyFun(nParam1, 0);
}
void MyFun(int nParam1, int nDefault)
{
}
In other words, No...
|
|
|
|
|
Clever
|
|
|
|
|
Default parameters are not inherently supported in C#. You need to define an overloaded version of the method that doesn't require the parameter (that defaults it) and call the version that contains all the parameters. Before you say it, I agree that it sucks
Cheers,
Tom Archer
Author, Inside C#
A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the affairs of others.
|
|
|
|
|
How could they leave out something so trivial to impliment, and so useful ? Templates I can understand given that Microsoft are yet to release a worthwhile implimentation of templates on any platform, but this just blows.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
we've had many talks with Eric Gunnerson about this on the aspfriends.com email lists.
you may disagree with it...
but the reason they didn't implement it was because they favored ( by a small margin ) overall simplicity against More Features©
however, we have been fairly successfull at giving good arguments for it... and they are still considering it for v2.
|
|
|
|
|
lol, beat me to it
James
Simplicity Rules!
|
|
|
|
|
The more I use C#, the more it treats me like an idiot. It's clear to me they went for simplicity, for the benefit of people coming over from VB, I suspect.
Thanks for the insight.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|