473,472 Members | 1,728 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

graphics question

I am using the Microsoft Press training kit for the Framework 2.0
exam. It has the following example for putting text into a font and
drawing it. I created a new Windows Application. But where do I put
the code? The book does not say -it assumes the reader knows. I tried
the form.load event and the form.paint event, but I get an empty form
when the program runs.

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

I also tried putting the two declarations at the beginning of the
Form1 class and changed them to Private properties.

Bill

Mar 2 '07 #1
7 1565
Seems to me you could put that in the form_load event. Stick it there, then
show all of the code. Maybe your event handler isn't set up right.

Robin S.
----------------------------
<bi*********@yahoo.comwrote in message
news:11**********************@31g2000cwt.googlegro ups.com...
>I am using the Microsoft Press training kit for the Framework 2.0
exam. It has the following example for putting text into a font and
drawing it. I created a new Windows Application. But where do I put
the code? The book does not say -it assumes the reader knows. I tried
the form.load event and the form.paint event, but I get an empty form
when the program runs.

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

I also tried putting the two declarations at the beginning of the
Form1 class and changed them to Private properties.

Bill

Mar 2 '07 #2


<bi*********@yahoo.comwrote in message
news:11**********************@31g2000cwt.googlegro ups.com...
>I am using the Microsoft Press training kit for the Framework 2.0
exam. It has the following example for putting text into a font and
drawing it. I created a new Windows Application. But where do I put
the code? The book does not say -it assumes the reader knows. I tried
the form.load event and the form.paint event, but I get an empty form
when the program runs.

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

I also tried putting the two declarations at the beginning of the
Form1 class and changed them to Private properties.

Bill
That code can be put anywhere, but I would suggest changing it a little and
put it in the OnPaint overrides (or Paint event).

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)

Dim f As Font = New Font("Arial", 12, FontStyle.Bold)
e.Graphics.DrawString("something", f, Brushes.Blue, 10, 10)
End Sub
' NOTE: Above code is off top of my head, along with the OP's 'modified'
code above.
' NOTE: OP's code looks like it's the same as mine....off top of head or
typed out from book, since there is a mis-spelling.

Anywho, the sample I give doesn't require you to create a Graphics object.
The OnPaint method's PaintEventArgs parameter contains a Graphics property
so you can use that instead.

HTH,
Mythran
Mar 2 '07 #3
I am using vs2005 to generate the code for the event signature so it
should be correct. Being new to .net, I must be missing something
very basic, but what? Could I trouble you to run this code to see if
it works for you?

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("something", f, Brushes.Blue, 10, 10)
End Sub

End Class
On Mar 2, 9:26 am, "RobinS" <Rob...@NoSpam.yah.nonewrote:
Seems to me you could put that in the form_load event. Stick it there, then
show all of the code. Maybe your event handler isn't set up right.

Robin S.
Mar 2 '07 #4
Thanks. my post indicated I am working with the 70-536 exam training
kit and the code is from the book, so I really need to find out if it
works as is, or if there is an error in the book. I am thinking that
something is missing, but what?
Bill

That code can be put anywhere, but I would suggest changing it a little and
put it in the OnPaint overrides (or Paint event).

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)

Dim f As Font = New Font("Arial", 12, FontStyle.Bold)
e.Graphics.DrawString("something", f, Brushes.Blue, 10, 10)
End Sub

' NOTE: Above code is off top of my head, along with the OP's 'modified'
code above.
' NOTE: OP's code looks like it's the same as mine....off top of head or
typed out from book, since there is a mis-spelling.

Anywho, the sample I give doesn't require you to create a Graphics object.
The OnPaint method's PaintEventArgs parameter contains a Graphics property
so you can use that instead.

HTH,
Mythran- Hide quoted text -

- Show quoted text -

Mar 2 '07 #5
I do not need a workaround or alternative. Here is my complete class.
The code in the paint event is from the 536 training kit, which does
not indicate what Sub to put it in and I need to know if it works as
is, or if there is something missing, or if it should go in another
Sub.

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("something", f, Brushes.Blue, 10, 10)
End Sub
End Class
Mar 2 '07 #6
Someone answered this when you reposted the question.

Robin S.
---------------------------------
<bi*********@yahoo.comwrote in message
news:11**********************@t69g2000cwt.googlegr oups.com...
>I am using vs2005 to generate the code for the event signature so it
should be correct. Being new to .net, I must be missing something
very basic, but what? Could I trouble you to run this code to see if
it works for you?

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("something", f, Brushes.Blue, 10, 10)
End Sub

End Class
On Mar 2, 9:26 am, "RobinS" <Rob...@NoSpam.yah.nonewrote:
>Seems to me you could put that in the form_load event. Stick it there,
then
show all of the code. Maybe your event handler isn't set up right.

Robin S.

Mar 3 '07 #7


<bi*********@yahoo.comwrote in message
news:11**********************@8g2000cwh.googlegrou ps.com...
>I do not need a workaround or alternative. Here is my complete class.
The code in the paint event is from the 536 training kit, which does
not indicate what Sub to put it in and I need to know if it works as
is, or if there is something missing, or if it should go in another
Sub.

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("something", f, Brushes.Blue, 10, 10)
End Sub
End Class

It should work as is, in the Form Paint event as shown.. The problem I see,
though, is you are creating graphics IN the paint event handler. This is
not needed and is redundant because you have the graphics object for the
form as a property in the PaintEventArgs parameter passed into the same
event handler. To access this property, use e.Graphics. Trust me on this,
it is better to use it than to create a new Graphics instance every call to
the paint handler.

HTH,
Mythran
Mar 5 '07 #8

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

Similar topics

12
by: Sanjay | last post by:
hi, We are currently porting our project from VB6 to VB .NET. Earlier we used to make scale transformations on objects like pictureBox , forms etc.Now Such transformations are made on the...
13
by: Jason Swett | last post by:
I want to do graphics with C++. Surprisingly, so far nobody has been able to tell me anything helpful. How do I do it? Any input would be greatly appreciated. Jason
4
by: Martin | last post by:
I am using graphics as backgrounds for forms,buttons,labels etc. The question is: is it faster to load all graphics from files on app start or to use it embeded (places in editor during design)....
2
by: eBob.com | last post by:
This real novice VB.NET programmer wants to put a "scatterplot" (just a bunch of dots) on his form. There'll be other stuff on the form too, but it's the scatterplot which I need your help on. Is...
6
by: Chris Dunaway | last post by:
The method for printing documents in .Net can be confusing, especially for newer users. I would like to create a way to simplify this process. My idea would be implemented using a PrintDocument...
15
by: Hamed | last post by:
Have I posted the message to wrong newsgroup? Or Does the question is so much strage? Would someone please kindly direct me to a true newsgroup or resource? Best Regards Hamed
1
by: James Willmott | last post by:
If I have a question, about how to implement a graphics algorithm in C++, but not specifically related to getting the graphics on screen (that I can work out for myself). Would asking for help in...
1
by: =?Utf-8?B?QW5kcmV3?= | last post by:
Email Question: When I send an email (basically a sms to a phone) from ms outlook it works fine. When I try to send it pragmatically I get an error stating that it can’t relay for <the email...
3
by: t | last post by:
I have been learning C++ on my own. For some projects, I would like to use graphics. What is the easiest way to do this? (I am using Visual Studio Express 2005.) Separate from the ease of use...
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
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...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
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...
0
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,...
1
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.