|
Measuring a string drawn with a specific font
|
Total Hit (2614) |
When you're dynamically drawing text (either on a Windows Form or Web Form application), you may need to calculate the width and height of a string printed with a particular font. This is easy with the Graphics class's Measure string method, that takes in input the string being measured, and the fon
....Read More |
Rating
|
|
|
|
|
Add exception tracing with one line of code
|
Total Hit (3808) |
At times you want to keep a log of all the exception occurred in your application, including those that are correctly caught by a Catch block. At first you might believe that you need to add a call to the LogException procedure from each and every Catch block, which is clearly a nuisance:
«Code L
....Read More |
Rating
|
|
|
|
InstrTbl - Search a string for any character in a table
|
Total Hit (3571) |
«Code LangId=2»
' If INCLUDE is True or is omitted, return the first occurrence of a character
' in a group
' or -1 if SOURCE doesn't contain any character among those listed in TABLE.
' If INCLUDE is False, return the first occurrence of the character in SOURCE
' that does not appear in TABL
....Read More |
Rating
|
|
|
Reading text files
|
Total Hit (3871) |
In Visual Basic .NET you read a text file by first opening a StreamReader on it, and then iterating over all its lines until its Peek method returns -1:
«Code LangId=2»
Dim sr As New StreamReader("c:\autoexec.bat")
' Display all the text lines in the file.
Do Until sr.Peek = -1
' The Re
....Read More |
Rating
|
|
|
Caveats of the CopyMemory API function
|
Total Hit (4099) |
Here's the correct declaration of the CopyMemory API function, which is so useful whenever you want to move a block of bytes between two memory locations:
«Code LangId=2»
Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, _
source As Any, ByVal bytes As Long)
«/Code
....Read More |
Rating
|
|
|
|
Using "Date" intervals in VB.NET
|
Total Hit (2477) |
The versatile Date datatype in VB.NET provides a large amount of built in functionality to manipulate dates and times. The ability to add, subtract and compare date values is very useful in particular.
For example, suppose you are managing hundreds of clients in an insurance company. Since insu
....Read More |
Rating
|
|
|
|
|
A For Each loop that iterates in reverse order
|
Total Hit (11594) |
The For Each loop always iterates orderly on all the elements of an array or a collection (more precisely, on all the elements of a class that implements the IEnumerable interface). What happens if you need to iterate in reverse order, though? If you have an array or an ArrayList you can always refe
....Read More |
Rating
|
|
|
Persist ADO.NET extended properties
|
Total Hit (3708) |
Many ADO.NET classes, including DataSet, DataTable, and DataColumn, use the ExtendedProperties property to enable users to add custom information. Think of the ExtendedProperties property as a kind of generic cargo variable similar to the Tag property of many ActiveX controls. You populate it with n
....Read More |
Rating
|
|
|
|
Clipping the mouse to a rectangle area
|
Total Hit (2094) |
The Clip property of the Cursor is the rectangle within which the mouse cursor is confined, or its value is Nothing if the mouse can move over the entire screen. This rectangle is in screen coordinates, so you must do some conversions if you want to confine the mouse to an object on the form:
«Co
....Read More |
Rating
|
|
|
|
Creating applications that target .NET Framework v. 1.0 and/or 1.1
|
Total Hit (2648) |
As explained in this article, the applications you create with one version of the framework, can target only that version or both, according to the settings you put in the appname.config file. (Where appname is the full name of your executable file including the extension, such as myapp.exe, so the
....Read More |
Rating
|
|
|
Smart Socket
|
Total Hit (4955) |
A Smart Socket will allow you to send serializable objects via a socket without having to manually serialize or deserialize the data on either the client or the server. When working with low-level objects like TCP clients and listeners, much code needs to be written before you can start using the ob
....Read More |
Rating
|
|
|
|
SysTray from .NET
|
Total Hit (1671) |
The .NET Framework includes a NotifyIcon component but this unfortunately doesn't support InfoTip (balloon) notification; at least, not in v1.0 of the Framework. This sample provides an equivalent class which uses the Shell code directly to allow all the tooltip facilities to be used.
....Read More |
Rating
|
|
|
How Do I...Use Assembly Version Policy?
|
Total Hit (981) |
A primary goal of the deployment system in the .NET Framework is to eliminate conflicts between applications caused by shared components and shared states (or DLL conflicts). A key solution to this problem is a robust versioning system. The .NET Framework records information about an application's d
....Read More |
Rating
|
|
|
Using System.Net.Mail
|
Total Hit (858) |
Sending an e-mail with classes of the .Net Framework is pretty easy. Michel Fournier wrote an article titled Sending email from VB.Net in the April 2006 edition of the Level Extreme .Net magazine providing you a good wrapper that does most operations you need when an application needs to send an e-m
....Read More |
Rating
|
|
|
Updating with the SQLDataAdapter...
|
Total Hit (904) |
Using the SQLDataAdapter's Update method is a very valuable and timesaving approach when synching a DataSet with a database. The SQLDataAdapter updates the SQL Server data source through the DataSet object, which tracks changes at the row level, through the RowState property. There are several metho
....Read More |
Rating
|
|
|
How Do I...Use XML Schema Collection?
|
Total Hit (602) |
This sample illustrates how to use the XmlSchemaCollection class used by the XmlValidatingReader for efficient data validation. The XmlSchemaCollection class allows you to maintain a cache of multiple XML Schema Definition language (XSD) and XML-Data Reduced (XDR) schemas which can then be used when
....Read More |
Rating
|
|
|
|
Stopwatch - a High-Resolution code timer class
|
Total Hit (2183) |
Creating an application requires precisely measuring how long specific operations take to complete. You may be searching for performance bottlenecks prior to shipping, measuring to ensure that changes do not unexpectedly degrade performance, or (in my case), testing alternative architectural approac
....Read More |
Rating
|
|
|
.NET Button ListBar Control
|
Total Hit (2236) |
The Button ListBar control provides an emulation of the ListBar provided in the Windows Add/Remove Programs window. Under XP it uses the UxTheme API to draw parts of the toolbar, and degrades to use standard GDI drawing calls when used on earlier OS versions. Both C# and VB.NET versions of the same
....Read More |
Rating
|
|
|
|