473,804 Members | 2,986 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

graphics.drawst ring


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(ByV al sender as Object, ByVal e As
System.Windows. Forms.PaintEven tArgs) Handles Me.Paint

Dim g as Graphics = me.CreateGraphi cs
Dim f as Font = New Font("Arial", 12, FonstStyle.Bold )
g.Drawstring("H ello World", f, Brushes.Blue, 10, 10)

End Sub
End Class

Mar 3 '07 #1
4 3104
<bi*********@ya hoo.comschrieb:
Private Sub Form1_Paint(ByV al sender as Object, ByVal e As
System.Windows. Forms.PaintEven tArgs) Handles Me.Paint

Dim g as Graphics = me.CreateGraphi cs
='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*********@yah oo.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(ByV al sender as Object, ByVal e As
System.Windows. Forms.PaintEven tArgs) Handles Me.Paint

Dim g as Graphics = me.CreateGraphi cs
Dim f as Font = New Font("Arial", 12, FonstStyle.Bold )
g.Drawstring("H ello World", f, Brushes.Blue, 10, 10)

End Sub
End Class
The code example for Control.CreateG raphics 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.atwrot e:
<billsahi...@ya hoo.comschrieb:
Private Sub Form1_Paint(ByV al sender as Object, ByVal e As
System.Windows. Forms.PaintEven tArgs) Handles Me.Paint
Dim g as Graphics = me.CreateGraphi cs

='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
27169
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 e.Graphics.DrawString(Line1.Text, FontLine1, TheBrush, Thelocation1, 390 + yPos, AStringFormat) e.Graphics.DrawString(Line2.Text, FontLine2, TheBrush, Thelocation2, TheHeight1 + (390 + yPos))
7
3041
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 represent a calendar. I want to place text precisely within those boxes on the printed page. I am using Python 2.4 on Windows XP I was in the past able to do this within Visual Basic using its printer object. Visual Basic's printer object uses...
7
2583
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 stupid or missing the point. I used DrawString( ) as a simple test but I cannot get it to work at all unless I handle my custom controls Paint event.
2
12674
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 that are not printed correctly. It's look like when toner is too low for the printer.This is only for some rows. Can somebody explain why this happens? What kind of StringFormat is used when this parameter is missing?
6
2685
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 string into multiple lines. Is there a way to find out into how many lines the string was split? I am asking because this string is being displayed inside an owner
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10321
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9152
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7620
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5522
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.