|
Create a gradient background
|
Total Hit (4561) |
a gradient brush is a brush that contains all the color nuances that vary from a starting color to an ending color, like the typical background screen of many installation procedures or Microsoft PowerPoint slides. The simplest way to create a linear gradient brush is passing its size (by means of a
....Read More |
Rating
|
|
|
Dashed lines with custom caps
|
Total Hit (4290) |
You can set properties of the Pen object to create custom lines. For example, you can use the DashStyle enumerated property to draw dashed lines using a predefined pattern, and you can even create custom dash patterns by assigning an array of Single values to the DashPattern property. The StartCap a
....Read More |
Rating
|
|
|
Drawing Bézier splines
|
Total Hit (3456) |
GDI+ supports two different forms of a complex curve that can't be represented as an arc of a circle or an ellipse: a cardinal spline and a Bézier spline. A Bézier spline is a curve specified by four points: the initial point, the ending point, and two control points. The curve doesn't pass through
....Read More |
Rating
|
|
|
Printing formatted text and other data with the WebBrowser control
|
Total Hit (2224) |
Printing con be quite difficult in VB.NET (or any other .NET language), especially if you not only have to print plain text, but also tables, images, bulleted lists, text with different fonts, styles, colors and any other type of formatted data. Here's a tip that can make your life much easier, in m
....Read More |
Rating
|
|
|
Calculated columns that refer to relationships
|
Total Hit (2907) |
The DataSet is a container of multiple DataTables, and it allows to create parent-child relationships between two tables, as shown below:
«Code LangId=2»
' create a relationship between the Categories and the Products tables,
' against the CatID column
ds.Relations.Add(New DataRelation("CatPr
....Read More |
Rating
|
|
|
Close the DataReader before changing database
|
Total Hit (2675) |
The ChangeDatabase method of the ADO.NET Connection object requires an open connection to execute correctly. Even if the connection is open, you can still have an InvalidOperationException when invoking this method; this happens when you are reading data from the connection by means of a DataReader
....Read More |
Rating
|
|
|
Determine how many records the DataReader is about to return
|
Total Hit (2699) |
The DataReader is the ADO.NET counterpart of the forward-only, read-only recordset in classic ADO. For this reason you never know how many rows the DataReader is about to return. In most cases you don't need this information, because you tipically process each row as soon as it is being returned, an
....Read More |
Rating
|
|
|
Determine how many records the DataReader is about to return
|
Total Hit (2931) |
The DataReader is the ADO.NET counterpart of the forward-only, read-only recordset in classic ADO. For this reason you never know how many rows the DataReader is about to return. In most cases you don't need this information, because you tipically process each row as soon as it is being returned, an
....Read More |
Rating
|
|
|
Include schema information in a DataSet's DiffGram
|
Total Hit (2809) |
In the .NET Framework, the DataSet's WriteXml method when used to create a DiffGram does not provide the capability to include schema information along with the data. This is more of a design choice than an objective difficulty, though. When you return a DataSet object from a Web service method your
....Read More |
Rating
|
|
|
MDAC 2.6 is required for .NET applications
|
Total Hit (2667) |
All ADO.NET applications require MDAC 2.6 or later (MDAC 2.7 is recommended). MDAC 2.7 comes with Visual Studio .NET but no MDAC version is included in the Microsoft .NET Framework SDK and the .NET Framework redistributable package. If your .NET application attempts to open a connection without a va
....Read More |
Rating
|
|
|
Persist ADO.NET extended properties
|
Total Hit (3720) |
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
|
|
|
The DataTable's Compute method
|
Total Hit (3058) |
The DataTable class has a method, Compute, that executes SQL-like functions on the rows locally stored in the DataTable. It supports functions such as COUNT, SUM, MIN, MAX, AVG and others. Here's an example to calculate the average salary for the employees stored in the tableEmployees DataTable:
....Read More |
Rating
|
|
|
|
Implementing IClonable - Shallow copies
|
Total Hit (2526) |
An object that want to support cloning should implement the ICloneable interface. This interface exposes only one method, Clone, which returns a copy of the object. The ICloneable specifics don't specify whether the object that the Clone method returns is a shallow copy or a deep copy. The differenc
....Read More |
Rating
|
|
|
Implementing ICloneable - Deep copies
|
Total Hit (3351) |
The simplest way to create a generic deep copy routine, that is a procedure that can create a true, distinct copy of an object and all its dependent object, is to rely on the serialization features of the .NET framework.
«Code LangId=2»
Function CloneObject(ByVal obj As Object) As Object
'
....Read More |
Rating
|
|
|
Set up event handlers through reflection
|
Total Hit (2521) |
Reflection makes it easy to invoke a method (or assign a field or a property) by its name. For example, suppose you have the following classes:
«Code LangId=2»
Class Person
Event PropertyChanged(ByVal propertyName As String, ByVal newValue As Object)
Dim m_Name As String
Property
....Read More |
Rating
|
|
|
Release COM objects earlier
|
Total Hit (2932) |
If you're using a COM object through COM Interop you should be aware that the object isn't released as soon as you set it to Nothing, as it happens with VB6. Instead, the object will be released only at the first garbage collections that occurs after the object is set to Nothing or goes out of scope
....Read More |
Rating
|
|
|
Don’t use the GotFocus and LostFocus events
|
Total Hit (4472) |
Have you ever tried to change the BorderStyle, HideSelection, MultiLine, ScrollBars, WordWrap and TextAlign properties of a TextBox, or the ComboBox’s RightToLeft property from inside the control’s GotFocus or LostFocus events? You’ll get a System.ComponentModel.Win32Exception exception saying "Erro
....Read More |
Rating
|
|
|
Hiding pages of a TabControl
|
Total Hit (2782) |
Sometimes you may need to hide or show some pages of a TabControl according to the information you want to show, basing on the currently logged-in user for example (users with low privileges won't be able to get all the information or to change records). To do this, you may attempt to add or remove
....Read More |
Rating
|
|
|
Map an enumerated value to a set of OptionButton controls
|
Total Hit (2566) |
In VB6 and previous version, displaying an enumerated value in a group of option buttons is quite simple, provided that the option buttons be grouped in a control array. VB.NET doesn't support control arrays, so you can't reuse the same simple coding techniques. However, you can prepare a couple of
....Read More |
Rating
|
|
|
|
Skipping columns when tabbing on a DataGrid
|
Total Hit (3566) |
It happens quite often that you have a DataGrid with hidden columns (with width = 0), because you need their values but don't want to show them to the user. However, when you tab through the DataGrid's columns, these "hidden" columns are still taken into account in the tab order. This means that whe
....Read More |
Rating
|
|
|
Using multiple fields as value for the DropDownList control's items
|
Total Hit (4125) |
Being an avid Access Programmer I have been frustrated with the limitation of VB DropDownLists to using only 1 field as the value. I found a way to simulate/work around this behavior with concatenation of several database fields at the query level to be my columns(i.e. Select KeyId1 + '~' + KeyId2 +
....Read More |
Rating
|
|
|
Creating multiline tooltips
|
Total Hit (3347) |
In VB6 there was no easy way to create multiline tooltips for form controls, you necessarily had to resort to API tricks. And it was probably just not worth the effort. The good news is that doing this is straightforward in VB.NET! First add a Tooltip Provider control on the form to add the Tooltip
....Read More |
Rating
|
|
|
Multi-column menus
|
Total Hit (3565) |
The new Break and BarBreak properties of the MenuItem object let you create menus with multiple columns. All you have to do is set either property to True for the MenuItem object that must become the first item of a new menu column. The only difference between these two properties is that BarBreak d
....Read More |
Rating
|
|
|
Pasting data from the Clipboard
|
Total Hit (6252) |
Pasting data from the clipboard requires more code because you must ascertain whether the clipboard contains data in one of the formats you're willing to process. First, use the Clipboard.GetDataObject to retrieve an IDataObject object. Next, use the GetDataPresent method of this IDataObject object
....Read More |
Rating
|
|
|
Showing and enumerating MDI child forms
|
Total Hit (3170) |
An MDI child form is a regular form whose MdiParent property points to its MDI container form, so the code that creates and displays a child window is very simple:
«Code LangId=2»
Sub ShowMdiChildWindow()
' Display the MenuForm form as a child of this form.
Dim frm As New MenuForm()
....Read More |
Rating
|
|
|
Unload setup projects before running the Inheritance Picker
|
Total Hit (2823) |
If your solution contains a setup project and this setup project has been built at least once, you get an Assembly Load error when you run the Inheritance Picker in order to inherit from an existing form in your main project.
This problem occurs because the setup project generates several execut
....Read More |
Rating
|
|
|
Use VB6 ActiveX controls with VB.NET
|
Total Hit (4004) |
It is possible to use VB6 ActiveX controls - such as ADO Data Control, Chart Control, Comm Control, and the Windowless controls - with the designer of Visual Studio .NET, but you may encounter problems when doing so because VS.NET doesn't come with the design-time license for these controls, therefo
....Read More |
Rating
|
|
|
Working with owned forms
|
Total Hit (3177) |
If a form owns another form, the owned form will be always displayed in front of its owner form, no matter which is the active form. This makes owned forms ideal for implementing tool and palette windows. Another feature of owned forms: when the user closes or minimizes the owner form, all the owned
....Read More |
Rating
|
|