|
In .NET (true for any language that targets the CLR) there is no such thing as global variables. Instead, though, you can create a class with static fields or properties (properties are usually recommended because you can validate inputs and use logic in your get or set accessors that access a private field. This has the same result, though, at least per AppDomain (if you need a "global" to span multiple AppDomain s, you should consider a ContextBoundObject ).
public class Globals
{
private static object someProperty;
private Globals()
{
}
public static object SomeProperty
{
get { return someProperty; }
set { someProperty = value; }
}
} If you need the power of a singleton, search the comments of this forum for a recent thread discussing various options. Just use the keyword "singleton", of course.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
How can I write to my application configuration file from my application?
Mazy
No sig. available now.
|
|
|
|
|
There is not built-in support for writing app configs, but you can use the System.Xml classes to manipulate the XML DOM. Note that your application will not see these settings until restarted, though. I did post several replies to similar questions in the recent past, so search the comments of this forum, using the AppDomainSetup keyword.
As far as writing to the config, you have to remember one very important thing: leave other settings untouched! Users may have customized how the CLR runs your app or even customized settings for your program (like, in <appSettings> ) that you don't want to overwrite. Nick wrote one article about this: http://www.codeproject.com/csharp/config_settings.asp[^]. There are others, too.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
twoPartQuestion = true;
1) When storing application state information such as window position, comm port settings, etc... should I be using the registry or special folders? I'm writing for Win2K or newer if that makes a difference.
2) If/when using special folders, what is a good way to format the data that needs to be saved? I'm thinking of a couple ways:
- Making a struct that contains all of the data that needs to be saved and serializing it as XML to a file.
- Using ADO.NET and making a table that is serialized to XML and saved in a file.
Is there a preferred or normal way to handle this data?
Thanks,
Ken Galer
Electrical Engineer
Preferred Utilities Corp.
Danbury, CT 06810
|
|
|
|
|
Ken Galer wrote:
should I be using the registry or special folders
Never use the registry unless you have to. This breaks XCOPY deployment (at least with base settings). It's also not recommended because...well...it's just not!
As far as serializing to an XML file, this is pretty common but it is up to you how, when, and where. There is no "standard". You could use the XML serialization attributes in System.Xml.Serialization , a DataSet (both of which you said), or write-out an XML file using the DOM.
Do a search here on CP and you'll find several articles about writing-out XML files, or appending data to the .config file for your app (true, just another XML file, but a specially named one if you wanted to use an IConfigurationSectionHandler like other settings). I believe Nick Parker wrote a good one on that, so you could search for articles from him.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
i have win form and i have registered keyboard event for it
but it doesn't work
////////////////////////
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.MainForm_KeyDown);
////////////////////////
private void MainForm_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
MessageBox.Show(e.KeyValue.ToString());
}
////////////////////////
but when i press any key on my keyboard, i doesn't recieve any thing.
thnx in advance
|
|
|
|
|
i recieve nothing.....
thnx
|
|
|
|
|
If another Control has the focus (and it most likely does), you won't receive keyboard events. You have to set Form.KeyPreview to true. Then you should have better results.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
but i wanna listen to more than one key
like "ctrl+h" or like this
|
|
|
|
|
As far as text in your console app go, you can use the Console.In properties (a TextReader ) to grab typeable characters like "h". When you get input like this, call the GetKeyState method (after P/Invoking it, of course) to determine whether or not a modifier key is pressed.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi
I am working on setting width of button depends on caption string width.
But I not able to find exact width of the string , using Graph.MeasureString
I have to set exactly 8 px gap at front and back..
Can any body help me pls..
Thanks
|
|
|
|
|
If you need a Graphics object while not doing any painting, use the Button.CreateGraphics method (inherited from Control.CreateGraphics ). See the documentation for MeasureString . It is an easy method to use and will calculate the SizeF (convert members to int when setting the appropriate properties) of the string, taking the Font into account:
Graphics g = button1.CreateGraphics;
SizeF s = g.MeasureString("Some Text", button1.Font);
button1.Width = (int)s.Width;
button1.Height = (int)s.Height;
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Does any one of u know how to get certified (from microsoft)
in C#.
Also is there any help availble on the topics issued by microsoft.
please give the exact links (if possible)
|
|
|
|
|
|
Ooh, here's a topic I love to tear apart!
Make sure you actually know what you're talking about before getting certified. Sure, it looks good on resumes but if you don't know what you're talking about and tout your certifications to people that do, you not only look like an idiot but make certifications look bad.
Personally, I am not certified because I really don't want to be. I know a large number of people with certifications that know crap. They studied for the tests, memorized a few things, took the tests (sometimes a couple times) and got their certs. They're still idiots.
That's not to say certifications are bad. Like I said, they do look good on resumes (the only reason I might someday do it if I have time...I already have the material and study books) and can up your salary at hire-time (or even at a current job if you work for that kind of company). Just make sure you have the knowledge to back it up!
That being said, you can also get your MCSD. Take the MCADs and pay attention to the courses you take. Take a look at the MCSDs and you'll find that MCAD - with the right courses - is a subset of MCSDs. There's only like a couple more tests you have to take if you take the subset of courses that get you your MCAD.
Good luck!
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hello,
I'm deploying an application in windows 98. My application uses some crystal reports. I'm using NON-EMBEDED reports in my application and have included rpt files separately in setup project. My application is running fine but throws axception (load report failed) when i try to open report. I already have included Merge Modules in my Setup project for Crystal Report with License Key. Same application is opening crystal reports fine when i deploy in Windows 2000 or XP. But why is it not Loading report in Windows 98.
If anyone has an idea, what else i need to open report after deployment in Windows 98, please reply.
thanks.
|
|
|
|
|
You might need to distribute updated MSVCRT merge modules (and related MSMs). The managed Crystal Reports are completely managed and do depend on somewhat newer VC++ libraries. Win98 might now have these, depending on what programs are installed. Including them won't hurt, though, besides making the MSI slightly larger (not much).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I would like to develop editor. This editor needs to open a HTML file and edit the content and save it. If the user needs to see HTML command then editor will able to see it.
Could you advise any one which is the good idea and how to finish faster way?
Thanks in advance
baski
|
|
|
|
|
You can use the WebBrowser control, often refered to as Internet Explorer. There is a property that puts the WebBrowser control in design-mode. This (or MSHTML, which the WebBrowser control hosts but doesn't provide as rich an API) is often what WYSIWYG editors use like FrontPage, VS.NET, and several others. You can also create interop assemblies for other interfaces that aren't in Microsoft.mshtml.dll to better control things, like drawing grips/anchors for controls and what-not.
There are some articles dealing with that topic here on CP as well as on the 'net:
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi,
Thanks for your information. I would like to clarify something, Actually I have windows forms (like notepad), this notepad able to open a HTML file then user will able to see the text only but source documents , where to reside? Actually, If the user need to see source document, they able to see. Could you give me which one is better idea and finish it faster?
Thanks in advance!!
bask
|
|
|
|
|
There's two questions you need to ask yourself:- Do your clients even know how to write HTML?
- Do your clients want to write HTML?
Using the way I mentioned gives you a WYSIWYG editor where users can drag and drop pictures, type paragraphs easily, etc. You can also provide buttons and use either the OLE commands or manipulate the DOM directly (I recommend the first method, for which there is documentation in the links I gave you).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
How to create a policy deployment package ensure my .NET program(*.exe) could run in IE, needn't adjust Zone Security at user's computer one by one.
wraps a security policy level into a Windows Installer Package (.msi file) that can then be distributed.
all user get the Windows Installer Package (.msi file) can run my program directly,needn't to adjust Zone Security?
|
|
|
|
|
If you open the Microsoft .NET Framework Configuration snap-in in Administrative Tools and right-click on the root node, you can create an MSI from a policy that you choose. This might overwrite the entire policy, though, so you'll definitely want to test that because you don't want to overwrite any code groups the user or administrator has set up.
Another way - which is what I do in our install and preserves what's there - is to create a custom Installer class that programmatically adds the code group (checking first to see if one with the same name already exists) and removes it upon uninstallation. See the System.Security.Policy namespace for details.
You can then use VS.NET's installer project to add the assembly containing the installer. Add a custom action that for the assembly and tweak the command line (if you want to handle command-line parameters in the Installer class.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
|
What kind of question is this? Of course I meant what I said. What is your question even in regard to?
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|