Hi guys,
I have a Textbox that is being used to display a chunk of binary code from a portion of a file. It is a simple binary file preview with a Vertical Scroll Bar to change the position within a file. This allows one to open and view the binary contents of ANY sized file quickly by loading only what is to be displayed. All that works... But the simple task of determining how many characters across the textbox is capable of displaying is killing me. I want to know so I can load exactly the number of fixed-width characters that will fit in the sizable display. I'm using the Graphics.MeasureString method, and its returning a number that makes no sense when devided into the TextBox1.DisplayRectangle.Width property. I am assuming that it has to do with the .Unit property and scaling but I can't seem to get it right. Anyone got any ideas here?
Jim
![]()
Code:'The TextBox starts out at 262W x 264H pixels and DisplayRectangle ' is 260 X 262 and the fixed width font being used is Lucida Console 9.75 Dim g As Graphics = Me.CreateGraphics g.PageUnit = GraphicsUnit.Pixel 'This MeasureString should return a number in the ballpark of 8 ' I get 12.4012032 Dim CharsWide as Integer = Me.txtFileDisplay.DisplayRectangle.Width / _ g.MeasureString("X",Me.txtFileDisplay.Font).Width / 2) 'The /2 is there because the program displays character, space, etc.... 'This MeasureString should return a number in the ballpark of 13 ' I get 14.6249981 Dim CharsHigh as Integer = Me.txtFileDisplay.DisplayRectangle.Height) /_ g.MeasureString("X", Me.txtFileDisplay.Font).Height)) '13 ' The next line determines the total number of characters to load from ' the file to fit nicely within the display area. Dim GetChars as Integer = CharsWide * CharsHigh




Jim
Reply With Quote