I'm writing some code that draws a barcode at a given size and scales it. It starts off with an image that varies in width but is always one pixel in height.

When I'm ready to draw the barcode, it scales the image to fit into a label control (a simple call to e.Graphics.DrawImage(...) in the Paint event).

What I'm getting, however is a barcode that is half the height of the label control, regardless of the size of the label control.

To use this, create a new form with a text box and a label. Label.autosize = false, text="". Anchor all four sides. Once running, type something into the text box. The code converts the 1 and 0 into black and white pixels respectively and sets a private field to the new bitmap. The label draws from this bitmap. Any ideas why it only fills half the label even though I provided label1.size to draw image? Seems like a bug.
vb Code:
  1. Public Class Form1
  2.  
  3.     Private bc As Bitmap
  4.  
  5.     Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
  6.         If Not TextBox1.Text = "" Then
  7.             Dim a As New BarcodeLib.Barcode
  8.  
  9.             'a.RawData = TextBox1.Text
  10.             'a.EncodedType = BarcodeLib.TYPE.CODE128
  11.             'a.Encode()
  12.             'bc = BCFromEncodedData(a.EncodedValue)
  13.  
  14.             bc = BCFromEncodedData("1011001101100110110011011001101100110110011011001")
  15.  
  16.             Label1.Refresh()
  17.         Else
  18.             bc = Nothing
  19.             Label1.Refresh()
  20.         End If
  21.     End Sub
  22.  
  23.     Private Function BCFromEncodedData(ByVal data As String) As Bitmap
  24.         Dim a As New Bitmap(data.Length, 1, Imaging.PixelFormat.Format32bppArgb)
  25.  
  26.         For i As Integer = 0 To data.Length - 1
  27.             If data(i) = "1" Then a.SetPixel(i, 0, Color.Black)
  28.         Next
  29.  
  30.         Return a
  31.     End Function
  32.  
  33.     Private Sub Label1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Label1.Paint
  34.         e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.NearestNeighbor
  35.  
  36.         If bc IsNot Nothing Then
  37.             e.Graphics.DrawImage(bc, New Rectangle(Point.Empty, Label1.Size))
  38.         End If
  39.     End Sub
  40.  
  41.     Private Sub Label1_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label1.SizeChanged
  42.         Refresh()
  43.     End Sub
  44. End Class