Monday 29 November 2010

Minimise VB.net app to the Notify Area on startup


It’s often desireable to create applications which startup in the Notify Area (or System Tray as it’s sometimes referred to).

The most obvious way to achieve this, one would think, would be to simply set the “Visible” Property of the main form in it’s Load Event. However, as this isn’t possible we have to use a work around.

The simplest method is to set the Visible Property asynchronously using a Delegate…

Public Delegate Sub InvokeByDelegate()


’ Hide Form

Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As  System.EventArgs) Handles MyBase.Load

Me.BeginInvoke(New InvokeByDelegate(AddressOf Me.HideForm)) ‘Invoke the Hide Form Routine Asynchronously

End Sub


’ Hide the Main Form

Private Sub HideForm()

Me.Visible = False

End Sub

Friday 26 November 2010

VB.net - Defaulting a databound ComboBox to show a blank value

 

Once a Combobox is bound to a datasource, we no longer have control over it’s List Collection, so we can’t add a blank item directly to the Combobox’s Collection using the Add Method.

However, we can temporariliy add a row having a blank value in the field bound to the Combobox’s DisplayMemebr property. We can then set the Selected index of the Combobox to that of the new “Blank” row…

dim drwBlankDataRow as DataRow


’ Databind Combobox

cmbComboBox.DataSource = dtsDataSet.tblTable
cmbComboBox.ValueMember = “ID_Column”
cmbComboBox.DisplayMember = “Display_Column”


’ Add a blank row to the DataSet

drwBlankDataRow = dtsDataSet.tblTable.NewRow
drwBlankDataRow(“Display_Column”) = “”
dtsDataSet.tblTable.AddtblTableRow(drwBlankDataRow)


’ Default the ComboBox to the Blank Row

cmbComboBox.SelectedIndex = cmbComboBox.FindStringExact(“”)

The Combobox will now show the new “Blank” row value.

Monday 15 November 2010

Shared Apache Server Directories require index page in order to access files from the web

For security reasons, Apache hosts enforce that, for a directory and it’s contents to be accessible from the web, the directory must contain an index.htm page.

This can be overridden by adding a .htaccess file with the following lines included;

ErrorDocument 401 "Unauthorized"
DirectoryIndex index.php index.shtml index.html publish.htm publish.html

Using an Apache Server to Host “ClickOnce” .net Deployment

Normally, to deploy ClickOnce applications, you would upload files to a Windows Server hosting environment. However, with the addition of a simple .htaccess file, you can host ClickOnce on an Apache based server.

Simply create a text document with the following content:

ErrorDocument 401 "Unauthorized"
DirectoryIndex index.php index.shtml index.html publish.htm publish.html
AddType application/x-ms-application application
AddType application/x-ms-manifest manifest
AddType application/octet-stream deploy

Save the file as .htaccess and upload to your deployment directoy.

The line:

DirectoryIndex index.php index.shtml index.html publish.htm publish.html

Allows the server to show the standard Visual Studio “publish.htm” file as default.

VB.net : Printer Dialog Box does not appear

Turns out there's an incompatibility with some versions of windows 7 (possibly 64bit versions), which prevent the standard PrintDialog box from appearing when invoked.

This can be worked around by setting the UseEXDialog property to "True".

This forces the dialog into windows XP mode, allowing it to be shown correctly....


Annoying eh!