473,320 Members | 1,979 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,320 software developers and data experts.

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 1559
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.