 |
| VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the VB.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

September 22nd, 2008, 07:36 PM
|
|
Authorized User
|
|
Join Date: Sep 2008
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
how do i draw an ellipse
using the methods outlined in the wrox books .. i was able to use the (Paint) event to draw an ellipse on the form.
how do i draw an ellipse (iff) the user clicks a command-button ?
actually .. i want the button click event to call a sub which draws the ellipse.
the following sudocode does not work
sub draw ( byval gr as graphics )
dim blackpen as new pen (....
dim x, y, width, height ...
gr . drawellipse (....
thanks
jerry gentry .. i am not retired, i just got so old that nobody would hire me anymore.
__________________
jerry gentry .. i am not retired .. but after 47 years of computer programming .. i got so old that nobody will hire me anymore.
|
|

September 22nd, 2008, 08:32 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
what is the gr you are passing to the sub?
probably you need to refresh it...
HTH
Gonzalo
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
|
|

September 23rd, 2008, 10:13 AM
|
|
Authorized User
|
|
Join Date: Sep 2008
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hi gonzalo.
i don't know what to pass the subroutine, or even if i need to pass it something.
i have done some vb6 programming but am new to the .net framework.
the program i want to convert can be seen on my website .. www (dot) wa0h (dot) com .. the (0) is the number zero.
the program has a picture box that can contain several images.
i don't want to draw a graphic unless the user request it .. hence drawing the picture from within a subroutine.
thanks for your time
jerry
jerry gentry .. i am not retired, i just got so old that nobody would hire me anymore.
|
|

September 23rd, 2008, 11:31 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
When you write this:
Code:
Sub draw(ByVal gr As Graphics)
you have told the programming environment to expect to receive a Graphics object. The Sub declaration doesnât actually cause a Graphics object to exist.
This Sub, when used, requires that you include a Graphics object (or at least a variable that has been declared as type Graphics. So you can do this:
Code:
Dim x As New Graphics ' With New, an actual object is created.
...
Draw(x) ' Pass the object referenced by x to the sub.
...
End Sub
Sub Draw(ByVal gr As Graphics)
...
So there is a Graphics objent created, then passed to the variable in the Draw declaration.
Or, you can do this:
Code:
Dim x As Graphics ' No New. x is typed, but no
' actual object is created yet.
...
Draw(x)
...
End Sub
Sub Draw(ByVal gr As Graphics)
gr = New Graphics ' At this point an object is created, and can be used.
...
|
|

September 23rd, 2008, 01:07 PM
|
|
Authorized User
|
|
Join Date: Sep 2008
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
thanks brian.
when i try your suggestion i get the following error message on the line .. dim x as new graphics
system drawing graphics has no constructors.
maybe i am putting the dim statement in the wrong place.
i put it in the button_click event that calls the draw sub.
jerry
|
|

September 23rd, 2008, 01:13 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
are you programming into a develop environment?? you have help for constructors, they tell you what you need to give to them to work. Graphics could be a generic namespace.. what if you put a dot after graphics?
HTH
Gonzalo
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
|
|

September 23rd, 2008, 02:00 PM
|
|
Authorized User
|
|
Join Date: Sep 2008
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hi gonzalo
i am using the vb-2008 (express) ide to learn vb.net
the (show error help) in the error box that appeared when i ran the program was no help to me.
the code in the (draw) subroutine worked when it was in the form-paint event so i don't think the problem is in the drawellipse code.
again .. i want a button click-event to call a sub which draws an ellipse .. the (drawellipse) statement works when it is in the form-paint event.
jerry
|
|

September 23rd, 2008, 02:20 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi jerry,
The following creates a Graphics from the current form so you can draw on it:
Code:
Dim myGraphics As Graphics = Graphics.FromHwnd(ActiveForm().Handle)
myGraphics.DrawEllipse(Pens.Pink, New RectangleF(30, 30, 100, 100))
You can call this code from most handlers (like a Button's Click).
May I give you some advice? If you post code, can you post as much as possible working code, rather than something like:
dim blackpen as new pen (....
If you post code that works, it's easier for people in the forums to copy and paste it in an application and find a solution to your problem.
Hope this helps,
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
|
|

September 23rd, 2008, 02:21 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
Hey there.. Yes, it work in the draw event, because you are drawing, and have a canvas to work into..
I don't have right now .net, but i can help you a little latter, but if you look carefully, you need somewhere to draw into, and you need that something to be able to refresh itself so it can draw. The only moment when vb draw something, is when the paint event is raised, that is when you show the form, or you refresh a control...
HTH
Gonzalo
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
|
|

September 23rd, 2008, 03:05 PM
|
|
Authorized User
|
|
Join Date: Sep 2008
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
thanks imar and everyone else
your suggestion worked.
regarding full code verses sudocode, i will try to remember to use full code in the future.
do i need to somehow close the topic ?
ps .. two years ago, joan and i spent a week in belgium and a week in holland .. great places for a vacation.
jerry .. wa0h
|
|
 |