Hello, I have a program that makes a barcode on a picturebox that is on my form, then saves it to a file. Below is the code:

VB Code:
  1. Private Sub CreateBarcode()
  2. Dim X As Integer, Y As Integer, z As Integer, pos As Integer
  3. Dim Barcode As String
  4. Dim Cur As String
  5. Dim CurVal As Integer
  6. Dim BC(43) As String
  7.  
  8.     BC(0) = "000110100" '0
  9.     BC(1) = "100100001" '1
  10.     BC(2) = "001100001" '2
  11.     BC(3) = "101100000" '3
  12.     BC(4) = "000110001" '4
  13.     BC(5) = "100110000" '5
  14.     BC(6) = "001110000" '6
  15.     BC(7) = "000100101" '7
  16.     BC(8) = "100100100" '8
  17.     BC(9) = "001100100" '9
  18.     BC(10) = "100001001" 'A
  19.     BC(11) = "001001001" 'B
  20.     BC(12) = "101001000" 'C
  21.     BC(13) = "000011001" 'D
  22.     BC(14) = "100011000" 'E
  23.     BC(15) = "001011000" 'F
  24.     BC(16) = "000001101"
  25.     BC(17) = "100001100"
  26.     BC(18) = "001001100"
  27.     BC(19) = "000011100"
  28.     BC(20) = "100000011"
  29.     BC(21) = "001000011"
  30.     BC(22) = "101000010"
  31.     BC(23) = "000010011"
  32.     BC(24) = "100010010"
  33.     BC(25) = "001010010"
  34.     BC(26) = "000000111"
  35.     BC(27) = "100000110"
  36.     BC(28) = "001000110"
  37.     BC(29) = "000010110"
  38.     BC(30) = "110000001"
  39.     BC(31) = "011000001"
  40.     BC(32) = "111000000" 'W
  41.     BC(33) = "010010001" 'X
  42.     BC(34) = "110010000" 'Y
  43.     BC(35) = "011010000" 'Z
  44.     BC(36) = "010000101" '-
  45.     BC(37) = "110000100" '.
  46.     BC(38) = "011000100" '<spc>
  47.     BC(39) = "010101000" '$
  48.     BC(40) = "010100010" '/
  49.     BC(41) = "010001010" '+
  50.     BC(42) = "000101010" '%
  51.     BC(43) = "010010100" '*  (used for start/stop character only)
  52.    
  53. picBarCode.Cls
  54. pos = 10
  55. Barcode = UCase(FixedItemCode)   'fixeditem code = the charactes in a textbox that is entered and converted to a barcode.
  56.  
  57. 'Add Start & Stop characters
  58. Barcode = "*" & Barcode & "*"
  59.  
  60. 'Generate Barcode
  61. For X = 1 To Len(Barcode)
  62.     Cur = Mid$(Barcode, X, 1)
  63.     Select Case Cur
  64.     Case "0" To "9"
  65.         CurVal = Val(Cur)
  66.     Case "A" To "Z"
  67.         CurVal = Asc(Cur) - 55
  68.     Case "-"
  69.         CurVal = 36
  70.     Case "."
  71.         CurVal = 37
  72.     Case " "
  73.         CurVal = 38
  74.     Case "$"
  75.         CurVal = 39
  76.     Case "/"
  77.         CurVal = 40
  78.     Case "+"
  79.         CurVal = 41
  80.     Case "%"
  81.         CurVal = 42
  82.     Case "*"
  83.         CurVal = 43
  84.     Case Else 'oops!
  85.         picBarCode.Cls
  86.         picBarCode.Print Cur & " is Invalid"
  87.         Exit Sub
  88.     End Select
  89.    
  90.     For Y = 1 To 9
  91.         If Y / 2 = Int(Y / 2) Then
  92.             'SPACE
  93.             pos = pos + 1 + (3 * Val(Mid$(BC(CurVal), Y, 1)))
  94.         Else
  95.             'BAR
  96.             For z = 1 To 1 + (3 * Val(Mid$(BC(CurVal), Y, 1)))
  97.                 picBarCode.Line (pos, 1)-(pos, 50)
  98.                 pos = pos + 1
  99.             Next z
  100.         End If
  101.     Next Y
  102.     pos = pos + 1 'make inter-character gap (ie: 1 narrow space)
  103. Next X
  104.  
  105.     picBarCode.CurrentX = Len(Barcode) * 7 'kinda center
  106.     picBarCode.Print Barcode
  107.  
  108. SavePicture picBarCode.Image, BarcodePicture

My question is, right now I have a picturebox that is 8835 twips wide...is there a way that I can have it automatically resize to the size of whatever the barcode is? Say the picturebox starts out at 8835 twips...when a barcode is generated, and the barcode itself only takes up 1000 twips...it resizes the picturebox and centers the barcode.