With .NET you can easily change the current cursor by using the Cursors class. To change the cursor to a hourglass, we’ll be using the WaitCursor: this.Cursor = Cursors.WaitCursor; To change it back to normal after the application has stopped loading: this.Cursor = Cursors.Default; As IntelliSense points out, you can change the mouse cursor to various shapes (crosshair, […]
How to launch an URL in the default browser
If you pass a URL to the Windows Shell, it will open it with the appropriate application, in this case the default browser. Thus, to launch the Geekpedia website in the default browser, the following code is needed: System.Diagnostics.Process.Start(“http://www.geekpedia.com”);
How can I set the date of a Calendar control to the current date?
Most of the time when using a calendar in your Windows or web application, you’ll want to set its initial date to the current date. This can be easily done using the SelectedDate property: Calendar1.SelectedDate = System.DateTime.Now;
How can I compress files from my C# application?
If you want to reduce the size of a file from your .NET application you will probably want to use a library that compresses this file using GZip/Zip or other similar type of compression.There are numerous libraries for this, such as: SharpZipLibPowerTCP Zip CompressionXCeed Streaming Compression for .NET
How can I set the ASP.NET validators to be visible by default?
To make the validators on a page visible by default you can call the page’s Validate() method when it is loading, as in: private void Page_Load(object sender, System.EventArgs e){ if (!IsPostBack) { Page.Validate(); }} Or if you want to make visible only one validator, use: private void Page_Load(object sender, System.EventArgs e){ if (!IsPostBack) { // Where reqEmail is […]
In .NET 2.0 Form.Flash and Form.StopFlash seemed to disappear…
They indeed disappear. As Erick Ellis from Microsoft explains: We removed the Flash API because it was too simplistic and failed to address the core scenario which is Messenger’s use of flash. You could stop and start it, but you couldn’t control duration, end state and several other aspects. We just had to pull the plug […]
How can I easily deploy an ASP.NET web application to a web server?
Of course, you can just upload all the files of the application to the server via FTP, but on larger projects you’ll want to filter out the files that you don’t need for the project to run on the server. You can easily do this from Visual Studio .NET via the Project menu, Copy Project window. You have […]
How can I format a number to x decimal places?
If you have the number 28 and you want to display it as 28.00 here’s how you can format it: int val = 28;string formatted = val.ToString(“N2”); Of course, if you want to format it to 5 decimal places just use ToString(“N5”) instead.
How do I retrieve the Major and Minor application (assembly) version and the Build and Revision number?
You can nicely retrieve the major and minor version of your application by using the Version class to retrieve and decode the version from the assembly. Version vrs = new Version(Application.ProductVersion);MessageBox.Show(“Major: ” + vrs.Major + “\r\nMinor: ” + vrs.Minor); Also, you can get the build and revision number using the rest of the properties: Version vrs = new Version(Application.ProductVersion);MessageBox.Show(“Build: […]
What’s the range of each value data type in C#?
These are the basic data types in C# and their range: Keyword Class Range bool System.Boolean true and false byte System.Byte 0 to 255 sbyte System.SByte -128 to 127 short System.Int16 -32768 to 32767 ushort System.Uint16 0 to 65535 int System.Int32 -2,147,483,648 to 2,147,483,647 uint System.UInt32 0 to 4,294,967,295 long System.Int64 -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 ulong […]