mercredi 2 janvier 2008

#ifndef in c sharp

#ifndef _DEBUG
//Code only run in non debug mode
#endif

is translated in c# to:

#if !DEBUG
//Code only run in non debug mode
#endif

jeudi 27 décembre 2007

Read Only Combobox in VS .Net 2005

To make a combobox read only, i.e. the end-user can't edit the list, you have just to change the "DropDownStyle" property to "DropDownList".

Printing a Form with Power Pack for Visual Basic 2005

Sometimes, we need to print a VB Form especially if it contains charts or data tables. A simple solution for printing forms in VB .Net 2005 is to use the Power Pack.

The Power Pack is a free toolkit for VB .Net 2005 which allows the developer to draw a line and an oval/rectangle shape. It also used to print a form. To download the Power Pack, go to: http://msdn2.microsoft.com/fr-fr/vbasic/bb735936.aspx

Using the Print Form is very easy.

Sample Code:
' Set the PrintAction to display a Print Preview dialog
PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
' Print a copy of the form
PrintForm1.Print(Me, PowerPacks.Printing.PrintForm.PrintOption.FullWindow)

You can also hide the parts of the forms that you don't want to print. The Power Pack contains an example of how to use the Print Form.

Editing Assembly Information in Visual Studio .Net

The assemply information are the information that will be displayed in the version properties of the generated file by visual studio such as the company name, file name, file version, copyright...

To edit these information in visual studio 6, we used to edit the version ressource strings. In visual studio .Net, this information can be edited from the project properties dialog box or directy in the "AssemblyInfo.cs"/"AssemblyInfo.vb" file.

More Informations.

How to use splitters in the VS .Net Designer

Using splitters is not complicated as it sounds. Here is an example:

1. Draw a panel on the form

2. Draw a textbox on the panel ( TextBox1.width is ( 1/2 Panel1.width ) )

3. Set TexBox1's Dock property to Left

4. Draw a splitter on the panel and set its Dock property to Left

5. Run Your Application

6. Now resize your TextBox1 by dragging the splitter

The splitcontainer in VS 2005 is also very helpful.

Resizing a Form -- Anchor Property


Use the Anchor property to adjust how each Control "Clings" to the walls of the Form. This allows you to resize the window to get a better view if we have long filenames or a large number of results. Anchoring is one of the convenient layout tools builtin to the VS .Net environment.


mercredi 26 décembre 2007

To avoid the "Cross Thread Exception"

To avoid the "Cross Thread Exception" that happens when a thread Thread1 try to access another thread's control(Thread2, Control2), you have to do the following :

1. Add a method that change the control in Thread2, for example :

Public Sub EditControl (ByVal Text As String)
'bla blaa bla Control2.zone_text = text
End Sub

2. Add in the declarations of the Thread2, a declaration of a delgate to the previous method (a delegate is like a pointer on a method, it must have the same arguments) :

Delegate
Sub EditControlDelegate (ByVal Text As String)

3. In the Thread1, do the following to run the EditControl method of the Thread2 :

Me.Invoke (New Thread2Object.EditControlDelegate(AddressOf Thread2Object.EditControl), "This Text is the unique argument of EditControl method")