473,378 Members | 1,372 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.

graphics.drawstring


There is a code example in the MS Training Kit for the Framework 2.0
test that does not seem to work. The example has just three lines of
code, but does not indicate where to put the code, so I put it in the
form.load event and it generates a blank screen, but is supposed to
display "Hello World" on the form. Then I put it in the paint event
as shown below and still I get a blank form when it runs. Any ideas
what is wrong? I previously posted here and was given another way of
accomplishing the task -that is not the point as I am studying for the
exam and need to know how to make this code work, or find out if it
has an error or something missing.

Public Class Form1
Private Sub Form1_Paint(ByVal sender as Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Me.Paint

Dim g as Graphics = me.CreateGraphics
Dim f as Font = New Font("Arial", 12, FonstStyle.Bold)
g.Drawstring("Hello World", f, Brushes.Blue, 10, 10)

End Sub
End Class

Mar 3 '07 #1
4 3085
<bi*********@yahoo.comschrieb:
Private Sub Form1_Paint(ByVal sender as Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Me.Paint

Dim g as Graphics = me.CreateGraphics
='Dim g As Graphics = e.Graphics'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Mar 3 '07 #2
bi*********@yahoo.com wrote:
There is a code example in the MS Training Kit for the Framework 2.0
test that does not seem to work. The example has just three lines of
code, but does not indicate where to put the code, so I put it in the
form.load event and it generates a blank screen, but is supposed to
display "Hello World" on the form. Then I put it in the paint event
as shown below and still I get a blank form when it runs. Any ideas
what is wrong? I previously posted here and was given another way of
accomplishing the task -that is not the point as I am studying for the
exam and need to know how to make this code work, or find out if it
has an error or something missing.

Public Class Form1
Private Sub Form1_Paint(ByVal sender as Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Me.Paint

Dim g as Graphics = me.CreateGraphics
Dim f as Font = New Font("Arial", 12, FonstStyle.Bold)
g.Drawstring("Hello World", f, Brushes.Blue, 10, 10)

End Sub
End Class
The code example for Control.CreateGraphics only uses the Graphics
object to measure a string, it doesn't draw anything, so I'm not sure
that it can even be used to draw anything on the screen.

Anyhow, if you create a Graphics object this way you should call it's
Dispose method when you are done with it.

The PaintEventArgs object contains a Graphics object that you are
supposed to use in the Paint event, you shouldn't create another one.
Especially as the one provided is already clipped down to the size of
the control (or the part of the control that needs to be redrawn) so
that you won't accidentally draw outside the control.

The supplied Graphics object should not be disposed. That is done by the
code that created it.

--
Göran Andersson
_____
http://www.guffa.com
Mar 3 '07 #3
That worked. Thank you.

On Mar 3, 7:42 am, "Herfried K. Wagner [MVP]" <hirf-spam-me-
h...@gmx.atwrote:
<billsahi...@yahoo.comschrieb:
Private Sub Form1_Paint(ByVal sender as Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Dim g as Graphics = me.CreateGraphics

='Dim g As Graphics = e.Graphics'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Mar 3 '07 #4
TP
Helpful links:

When to use CreateGraphics

http://www.bobpowell.net/creategraphics.htm

MCTS Self-Paced Training Kit (Exam 70-536): Microsoft®
..NET Framework 2.0-Application Development Foundation
Comments and Corrections

http://support.microsoft.com/kb/923018

-TP

Mar 3 '07 #5

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

Similar topics

5
by: Charles A. Lackman | last post by:
Hello, I have created a complete PrintDocument and need to create an image from it. How is this done? e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality...
7
by: Michael Galvin | last post by:
I am trying to use Python to send to the printer a calender filled with a mix of text and simple graphics. I want to draw on the printed page something like a table with 6 rows and 7 columns to...
7
by: Peter Row | last post by:
Hi, I've started work on my own control some parts of which use standard controls, others I need to draw on my controls surface to get the display output I require, however.... I seem to be...
2
by: Tony Johansson | last post by:
Hello! If I use the DrawString below with object of StringFormat as the last object it works good. If I instead remove object StringFormat below as the last object of DrawString I get some rows...
6
by: Dilip | last post by:
Howdy Folks I have a display where the Graphics.DrawString function is called to display something. Since the text seems to be larger than its bounding rectangle, the call basically splits the...
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: 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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.