473,378 Members | 1,375 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

CreateGraphics for a control

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

Nov 19 '05 #1
1 3245
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)
<ta******@yahoo.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
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

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: RickDee | last post by:
I really can't understand on how to use CreateGraphics. Even though I have follow what is shown in many sites, I can't get it working at all. For example. I have textbox name textbox1. I...
1
by: JH | last post by:
I have a tab control in my form. I am trying to create a dynamic pie chart. If I use the following code,it works fine on the main form. this.CreateGraphics().FillPie(brushtargeted,240,200,200, 200,...
0
by: Dennis | last post by:
THIS IS A COMMENT..NOT QUESTION: I have a user grid control that does all it's own drawing. Originally I had it set up where I drew the control and all changes on a graphics object created from...
6
by: saunderl | last post by:
Hello Everyone, I'm trying to just play with managed VC++. I just want to draw a box on the form when it is clicked. Here is my click event handler System::Void Test_Click(System::Object^ ...
1
by: Jeff Waskiewicz | last post by:
Hello All, I'm trying to solve a nagging problem. The goal is to draw a rectangle over the top of all the other controls on a form. Specifically, over a ChartFX control. The user would draw...
8
by: pigeonrandle | last post by:
Hi, Please pity me, i am on a dial-up connection for the first time in 5 years :( ! Does anyone know how the resulting Graphics objects differ ...? What i really mean is can someone explain it...
6
by: active | last post by:
I did the following and then wondered it's good practice. Me.CreateGraphics.DrawImage(Img, 0, 0) I'm thinking about disposing the Graphics object. A couple of lines after this I exit the sub...
4
by: vijay_3491 | last post by:
Hi, How to write a CreateGraphics method for a class similar to form.CreateGraphics()? Pls help. Thanks in Advance.
3
by: bromptonville-un | last post by:
Hello, I'm an amateur in VB6, and I just switched to VB.Net (2003) . However, I've never used graphicals functions in neither those language... (Last time I drew something was in VB6). I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.