473,781 Members | 2,280 Online
Bytes | Software Development & Data Engineering Community
+ 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.CreateGraphi cs
Dim f as Font = New Font("Arial", 12, FonstStyle.Bold )
g.Drawstring("s omething", 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 1589
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*********@ya hoo.comwrote in message
news:11******** **************@ 31g2000cwt.goog legroups.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.CreateGraphi cs
Dim f as Font = New Font("Arial", 12, FonstStyle.Bold )
g.Drawstring("s omething", 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*********@ya hoo.comwrote in message
news:11******** **************@ 31g2000cwt.goog legroups.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.CreateGraphi cs
Dim f as Font = New Font("Arial", 12, FonstStyle.Bold )
g.Drawstring("s omething", 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.Draw String("somethi ng", 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(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("s omething", 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.Draw String("somethi ng", 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(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("s omething", f, Brushes.Blue, 10, 10)
End Sub
End Class
Mar 2 '07 #6
Someone answered this when you reposted the question.

Robin S.
---------------------------------
<bi*********@ya hoo.comwrote in message
news:11******** **************@ t69g2000cwt.goo glegroups.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(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("s omething", 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*********@ya hoo.comwrote in message
news:11******** **************@ 8g2000cwh.googl egroups.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(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("s omething", 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
2389
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 graphics object of the form/pictureBox. Should It be better if make a graphics object from my pictureBox in load event handler of the form and store it as member variable of the form , make
13
2269
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
3363
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). Reason for my question is that application has 5mb, while without graphics it has cca 400kb. Graphic files (bmps) take about 200kb (in program, they are repeated many times, ie almost all labels (around 200) have same background image)). Also,...
2
1467
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 PictureBox the way to go? If so I am not finding any SIMPLE examples using PictureBox in VB.NET. If it matters ... I will eventually want to detect when the move moves over one of the dots and will want the graph to grow and shrink as the...
6
3245
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 (much like the current model), but my PrintDocument would have a Pages collection such that each time you need to have an additional page, you would just add another page to the collection and then use the page object for the actual drawing etc. ...
15
1852
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
1481
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 the implemention ( asking things like whether I should use std::vector vs std::list for example ) be off topic here? Thanks, jw.
1
1340
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 address> Try If Not strMailSv = "" Then If Not msgTo = "" Then
3
1741
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 question, what way(s) are most used? I have heard of things like qt... Would it be easier to just learn and use C# instead?
6
2683
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
9474
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,...
0
10306
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10139
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10075
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,...
1
7485
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
6727
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5373
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...
0
5504
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
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

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.