Windows Develop Bookmark and Share   
 index > Windows Forms General > Retrieving text width, length, x, y after drawstring
 

Retrieving text width, length, x, y after drawstring

This is my function Pic is a Picturebox on my form.
--------------------------------------------------------------------------

    Private Sub TxtDim(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Pic.Click

        Dim TxtCreator As Graphics = Pic.CreateGraphics
        Dim myBrush As New Drawing2D.LinearGradientBrush(ClientRectangle, Color.Red, Color.Yellow, Drawing2D.LinearGradientMode.Horizontal)
        Dim myFont As New Font("Times New Roman", 24)

        TxtCreator.Clear(Pic.BackColor)
        TxtCreator.DrawString("Look at this text!", myFont, myBrush, myRecF)

        'here

    End Sub
---------------------------------------------------------------------------
Well, the problem is the following:
1) where I've typed "'here" I must initialize a structure that saves X, Y, Width and Length of the drawed string.
2) I must draw a rectangle with those coordinates (X, Y, Width, Length)

3) I want to create a picturebox with "hallo" print on it how could I know the width and length of the grapic text "hallo"

Is that possible?

Thanks to all
MigrationUser 1  Tuesday, October 19, 2004 12:50 PM
Look up MeasureString, MeasureCharacterRanges.
MigrationUser 1  Wednesday, October 20, 2004 5:52 PM

You can use google to search for other answers

Custom Search

More Threads

• Question which control to use for a VB.NET App
• Fancy list components?
• Dynamicly Creating class DLL from EXE
• Extending user control
• Couldnt bring Focus to the Child Form
• Maximum window width is too small!
• Create a settings dialog box
• Themeing all the controls in Windows
• How to make a window with FormBorderStyle=None to be resizable?
• highlight text in textbox