我是C#新手,本来一直用c的,老师新出的题目,必须用C#搞定,baidu了半天,也没找到门路我想实现这样的功能画出x和Y的坐标图。用平滑曲线连接麻烦给我一个例子看下,最好是在FORM里的  谢谢了

解决方案 »

  1.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Drawing.Drawing2D;namespace Test
    {
        public partial class frmMain : Form
        {  
            const int DrawStep = 20;
            public frmMain()
            {
                InitializeComponent();
            }        private void Form1_Load(object sender, EventArgs e)
            {
            }
            protected override void OnPaint(PaintEventArgs e)
            {
                Pen myPen = new Pen(Color.Red, 1);
                myPen.EndCap = LineCap.ArrowAnchor;
                e.Graphics.DrawLine(myPen, 30, this.Height / 2, this.Width-30, this.Height / 2);
                e.Graphics.DrawLine(myPen, this.Width/2, this.Height-20, this.Width/2,20);
              
                int ndrawCount = Width / (2*DrawStep);
                // Create string to draw.
                 String drawString = "";
                SolidBrush drawBrush = new SolidBrush(Color.Black);            for (int i = 1; i < ndrawCount-1; ++i)
                {
                    drawString = i.ToString();
                    e.Graphics.DrawLine(myPen,
                        Width / 2 + DrawStep * i,
                        this.Height / 2,
                        Width / 2 + DrawStep * i, 
                        this.Height / 2 - 3);
                    // Create font and brush.
                    Font drawFont = new Font("Arial", 12);
                    // Create point for upper-left corner of drawing.
                    PointF drawPoint = new PointF(Width / 2 + DrawStep * i-8, this.Height / 2+1);
                    // Draw string to screen.
                    e.Graphics.DrawString(drawString, drawFont, drawBrush, drawPoint);            }
                 base.OnPaint(e);
            } 
        }由于时间仓促写了点,可以看到X轴正方向有坐标和数字标注了
      

  2.   

    参考http://bingning.net/free/source/graphics/index.html