CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2000
    Location
    CA
    Posts
    52

    Width of text added to a control

    Probably an easy question, but...

    I desire to paste a certain text string into an Excel Spreadsheet Cell. If the text is wider (in pixels) than the receiving cell's width, the text should be broken and continued in the cell below the receiving cell. Is there a way to determine the width of the text string (in pixels?). I am constrained by an existing EXCEL Spreadsheet layout and cannot change the Font of the text I am printing nor can I exceed the width of the existing cell.

    Thanks...


  2. #2
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Width of text added to a control

    Not that easy

    There is the builtin VB TextWidth method - however, this applies to :

    - Forms (eg. Form1.TextWidth("some text"))
    - PictureBox
    - Printer Object
    - Property Page Object
    - UserControl object
    - UserDocument object

    - and of course, don't forget that the size in pixels relates to the font that is being used for that object.

    You'll need to capture the size (width) of the string before you paste it over to Excel - then of course, you'll need to find out how big the cell is in Excel (in pixels) and do some calculations on the String to see where to split it up.

    Good luck




    Chris Eastwood

    CodeGuru - the website for developers
    http://codeguru.developer.com/vb

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured