in

DotNetSide

Dot Net South Italy Developers User Group
Latest post 08 Aug 2007 19:31 by GBFoundation. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 08 Aug 2007 17:32

    • pixel
    • Top 25 Contributor
    • Joined on 30 May 2007
    • Posts 60
    • Points 320

    Ottenere la larghezza i pixel del testo

    Salve,

    sto utilizzando GDI+ per realizzare dei controlli, avrei la necessità di ottenere la larghezza in pxel del testo per centrarlo rispetto a un punto. Qualcuno ha dei suggerimenti ?

     

    Grazie

     

    • Post Points: 20
  • 08 Aug 2007 19:31 In reply to

    Re: Ottenere la larghezza i pixel del testo

    ..ciao pixel, potresti provare in questo modo:

    System.Drawing.Font font = new System.Drawing.Font( "Arial", 10);
    Bitmap bmp = new Bitmap( 1, 1);
    System.Drawing.Graphics graph = Graphics.FromImage( bmp);
    int width = Convert.ToInt32( graph.MeasureString( "Prova inserimento testo", font).Width);
    bmp.Dispose();
    graph.Dispose();

    ...purtroppo in questo modo sei legato al tipo di font/dimensione che usi...sicuramente esiste una soluzione più elegante

    http://addshare.blogspot.com/ Imparo, Imparo, Imparo

    • Post Points: 5
Page 1 of 1 (2 items)
Powered by Community Server (Commercial Edition), by Telligent Systems