CreateGraphics for a control

T

takilroy

Hi,

I am trying to implement this snippet of code from the .Net help
documentatiion so that I can modify the width of a textbox on one of my
aspx forms. However, for some reason visual studio thinks that
CreateGraphics is not a member (or method) of System.Web.UI.Control.
Can anyone help? Do I need to import something?

Private Sub AutoSizeControl(ByVal control As Control, ByVal
textPadding As Integer)
' Create a Graphics object for the Control.
Dim g As Graphics = control.CreateGraphics()

' Get the Size needed to accommodate the formatted Text.
Dim preferredSize As Size = g.MeasureString( _
control.Text, control.Font).ToSize()

' Pad the text and resize the control.
control.ClientSize = New Size( _
preferredSize.Width + textPadding * 2, _
preferredSize.Height + textPadding * 2)

' Clean up the Graphics object.
g.Dispose()
End Sub

Thanks,
Teresa
 
B

Bruce Barker

use System.Drawing

note: this code will not really work, as the browser is not necessarily
using the server font (or size). for a good example, hit your site from
computer with large fonts selected.

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top