?
Solved

draw curve

Posted on 2006-07-03
5
Medium Priority
?
519 Views
Last Modified: 2008-03-17
hello experts
I'm beginner in vb.net .
I want to draw a curve with a couple of points those represent a profile of oil pipeline, I  found these code from MSDN:

Dim points As Point() = { _
   New Point(0, 100), _
   New Point(50, 80), _
   New Point(100, 20), _
   New Point(150, 80), _
   New Point(200, 100)}
     
Dim pen As New Pen(Color.FromArgb(255, 0, 0, 255))
e.Graphics.DrawCurve(pen, points)

how do I use these code in my program?
what component need to these code draw curve in it?
where I declare "e" object ?
how I print the drawed curve in page A3?
is there any better way to draw curve?

please write me codes.

thanks
0
Comment
Question by:farhadtolooie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 9

Expert Comment

by:jrscherer
ID: 17035145
Hi farhadtolooie
Your code snippet above goes typically into the Paint event or DrawItem event of a Windows Control, such as a PictureBox or any other control with a visible body.
In case of a PictureBox Control which has a Paint event, the "e" object is an argument of the event subroutine. In this case it is a System.Windows.Forms.PaintEventArgs, which exposes the Graphics property.

To your questions:
how do I use these code in my program?
A: just copy it into the Paint event handler of a Picturebox, as an example.
    Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
        Dim points As Point() = { _
           New Point(0, 100), _
           New Point(50, 80), _
           New Point(100, 20), _
           New Point(150, 80), _
           New Point(200, 100)}

        Dim pen As New Pen(Color.FromArgb(255, 0, 0, 255))
        e.Graphics.DrawCurve(pen, points)
    End Sub

what component need to these code draw curve in it?
A: Any form or component which has a Paint or DrawItem argument. There are other ways too, but this should be good enough for your tests.

where I declare "e" object ?
A: see above

how I print the drawed curve in page A3?
A: make your object on which you draw the size of A3. Be aware that the monitor has a different resolution than for example a printer, so A3 is relative and depends on the output device.

is there any better way to draw curve?
A: all depends on what curve you plan to draw. DrawCurve produces a Cardinal Spline. You may want to check all the other draw methods which the Graphics method exposes. Use Help of Visual Studio to find them all.

Have fun with GDI+, Jack.net
0
 

Author Comment

by:farhadtolooie
ID: 17035246
thank you for your speed answer.
I replace poits with real points such as
Dim points As Point() = { _
           New Point(1, 800), _
           New Point(2, 780), _
           New Point(5, 900), _
           New Point(10, 1200), _
           New Point(13, 2000)}
and run the program and I saw the curve is out of my form while form was in maximum size of my monitor.
how do you solve this problem,
if I want to draw curve with axis of x and y(x-axis,y-axis) how do I it?
please write me some code

thanks
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17055365
You need to define a coordinate system that breaks the screen coordinates into quadrants.

Bob
0
 

Author Comment

by:farhadtolooie
ID: 17064095
how do I that
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 800 total points
ID: 17064974
1) You need a negative representation for the x and y axes.

2) This will divide the screen up like this:

                                        y-axis
                                        centerX
           +--------------------------------------------------+
           |  1                          2 |                           3 |
           |                                |                              |
           |                                |                              |
x-axis   |------------------------- |------------------------| centerY
           | 4                           5 |                           6 |
           |                                |                              |
           | 7                           8  |                          9 |
           +--------------------------------------------------+

3) The value for each point is:

    #1:  {0, 0}
    #2:  {centerX, 0}
    #3:  {rightX, 0}
    #4:  {leftX, centerY}
    #5:  {centerX, centerY}
    #6:  {rightX, centerY}
    #7:  {leftX, bottomY}
    #8:  {centerX, bottomY}
    #9:  {rightX, bottomY}

4) Coordinates:

     centerX = (width \ 2)
     centerY = (height \ 2)
     rightX = width
     bottomY = height

5) Draw the x-axis from #4 to #6
    Draw the y-axis from #2 to #8

6) You should be able to see the coordinate system overlaid on top of a form.

Bob
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month10 days, 12 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question