Friday, January 23, 2009

How to include the DotNetFx folder and the WindowsInstaller3_1 into my application

Another way to ask this question is - "How to get the setup application to build the dotnetfx folder and the WindowsINstaller3_1". 

So that when you run the build of the setup application it creates a folder called dotnetfx and another folder called WindowsInstaller3_1

Well to do this, right click on your Setup project (from within the IDE), and then select Properties.  Then click on the "Prerequisites" button.  In the window that pops up make sure "Create setup program to install...." is checked.  In the next area, select ".NET Framework 2.0" and "Windows Installer 3.1" and in the radio buttons towards the bottom, select "Download prerequisites from the same location as my application"  Then click 'OK'.

Now when you build your application it will create thos folders for you.


Friday, January 16, 2009

Image.Save produces Bitmap with an incorrect header












The above two images will be referred to as good (left) and bad (right). They both look alike, but their headers contain a small difference. Most applications do not seem to mind this but some will give an invalid bitmap error when you use the bitmap saved from Visual Studio 2005. To recreate the bug:
Just create a VB.Net program and do the following:
Dim img1 As Bitmap = New Bitmap("c:\good.bmp")
img1.Save("c:\bad.bmp", Imaging.ImageFormat.Bmp)

Not sure if when you download the above two images if you'll get what I was working with, but just use any bitmap images. These are color, I've been able to recreate this issue using grayscale 8bit images at 500 ppi. If you were to open both bitmaps in a binary viewer you will see that that the header of bad.bmp is different. The good has the field "size of the image data" (offset 34) as F4080900, while the bad has the size of the image data as 00000000. I've also seen situations where the good has the field (offset 47) "number of colors in image" as 00 while the bad has it as 01. I am using Visual Studio 2005 SP1 and working with Visual Basic.

My solution was to create a function in C and to call that from the VB program instead of using the native Image.Save. I can't show that solution right now.

Additionally, the following incident seems to allude to a similar problem with the header but their problem looks to be different than ours.
http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=214834

The field header locations and values were found on this website:
http://www.fastgraph.com/help/bmp_header_format.html

Thursday, January 15, 2009

Great page on the TabControl.

http://dotnetrix.co.uk/tabcontrol.htm

Topics include

Change the colours of a Tabcontrols Header Item.
A Completely OwnerDraw TabControl.
Associate a ContextMenu with the TabItem headers of a Tabcontrol.
Hide and Show Tabpages in a Tabcontrol.
An alternative approach to Tabpage Navigation.
Tabpage order has changed.
Reposition TabItems at runtime.
Add Mnemonic support to Tabpages.
Tabcontrol using custom Tabpages.
Mirrored Tabcontrol.
Prevent users navigating TabControl via Ctrl+Tab and Ctrl+Shift+Tab.
Add a SelectedIndexChanging Event.
Add a HideTabs property to turn on/off the Tabitems.
Add a custom Scroller to Tabcontrol.


Tuesday, January 6, 2009

How to create a Left-Click Context Menu that looks like its a drop-down list on a button

Copy and paste the code from the post just below this.  The key part is the function below.  When you click on the button, you want the ContextMenu to show up below the button making it appear that it is drop-down list.

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Me.ContextMenuStrip1.Show(Button1, New Point(0, Button1.Height))
  End Sub

How to dynamically create MenuStripItems and ContextMenuStripItems

To get this code working, drop a MenuStrip, ContextMenuStrip and a Button on the form, and then past the following code:


Public Class Form1
  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    SetMenus()
  End Sub
  Private Sub SetMenus()
    Dim mnuMenuItem1 As ToolStripMenuItem, mnuMenuItem3 As ToolStripMenuItem

    mnuMenuItem1 = New ToolStripMenuItem("Item 1", Nothing, New EventHandler(AddressOf mnuMenuItem1_Click))
    MenuStrip1.Items.Add(mnuMenuItem1)

    mnuMenuItem3 = New ToolStripMenuItem("Item 3", Nothing, New EventHandler(AddressOf mnuMenuItem3_Click))
    MenuStrip1.Items.Add(mnuMenuItem3)

    Dim mnuContext1 As ToolStripMenuItem
    Dim mnuContext2 As ToolStripMenuItem
    mnuContext1 = New ToolStripMenuItem("ToolStripMenuItem1", Nothing, New EventHandler(AddressOf mnuContext1_Click))
    mnuContext2 = New ToolStripMenuItem("ToolStripMenuItem2", Nothing, New EventHandler(AddressOf mnuContext2_Click))
    ContextMenuStrip1.Items.Add(mnuContext1)
    ContextMenuStrip1.Items.Add(mnuContext2)

  End Sub


  Private Sub mnuMenuItem1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    MessageBox.Show("Menu Item 1 Clicked")
  End Sub


  Private Sub mnuMenuItem3_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    MessageBox.Show("Menu Item 3 Clicked")
  End Sub

  Private Sub mnuContext1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    MessageBox.Show("mnuContext1 Clicked")
  End Sub

  Private Sub mnuContext2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    MessageBox.Show("mnuContext2 Clicked")
  End Sub
  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Me.ContextMenuStrip1.Show(Button1, New Point(0, Button1.Height))
  End Sub
End Class