using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;namespace newform
{
    public partial class TuShiHua : Form
    {
        public TuShiHua()
        {
            InitializeComponent();
        }        private void TuShiHua_Load(object sender, EventArgs e)
        {
        }        //////////////////////////////////////////////////初始化和填充图像区域,画出边框,初始标题
        private void InitializeGraph()
        {            int Width = 20;
            int Height =80;
            //根据给定的高度和宽度创建一个位图图像
            Bitmap objBitmap = new Bitmap(Width, Height);            //从指定的 objBitmap 对象创建 objGraphics 对象 (即在objBitmap对象中画图)
            Graphics objGraphics = Graphics.FromImage(objBitmap);            //根据给定颜色(LightGray)填充图像的矩形区域 (背景)
            objGraphics.DrawRectangle(new Pen(Color.Red, 1), 0, 0, Width, Height);
            objGraphics.FillRectangle(new SolidBrush(Color.Red), 1, 1, Width - 2, Height - 2);            //画X轴,pen,x1,y1,x2,y2 注意图像的原始X轴和Y轴计算是以左上角为原点,向右和向下计算的
            objGraphics.DrawLine(new Pen(new SolidBrush(Color.Red), 1), 100, Height - 100, Width - 75, Height - 100);            //画Y轴,pen,x1,y1,x2,y2
            objGraphics.DrawLine(new Pen(new SolidBrush(Color.Red), 1), 100, Height - 100, 100, 75);        }        ///////////////////////////////////////////////////////////////////////////////// 
       
    }
}

解决方案 »

  1.   

    InitializeGraph() 方法是在哪里调用的?
    里面的objBitmap对象最后是附值给窗体的背景图了吗?
      

  2.   

    private void TuShiHua_Load(object sender, EventArgs e)
      {
    Graphics g = this.CreateGraphics();      
    Pen p = new Pen(Color.Blue,1);
    g.DrawLine(p, 0, 0, 100, 0);}
      

  3.   

    你好啊~!我是新学的。不懂你说的什么意思。InitializeGraph() 方法也不知道为什么要调用~!以前是我的全部程序啊。那估计是objBitmap对象最后没有附值给窗体的背景图了吧。那怎么赋值呢?
      

  4.   

    private void Form1_Paint(object sender, PaintEventArgs e)
    {
        int Width = 20;
        int Height = 80;
        Graphics objGraphics = e.Graphics;
        objGraphics.DrawRectangle(new Pen(Color.Red, 1), 0, 0, Width, Height);
        objGraphics.FillRectangle(new SolidBrush(Color.Red), 1, 1, Width - 2, Height - 2);
        objGraphics.DrawLine(new Pen(new SolidBrush(Color.Red), 1), 100, Height - 100, Width - 75, Height - 100);
        objGraphics.DrawLine(new Pen(new SolidBrush(Color.Red), 1), 100, Height - 100, 100, 75);
    }
      

  5.   

    加上这个:
    public Form1()
    {
        InitializeComponent();
        this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
    }
      

  6.   

    估计你没懂,多写点:
    public TuShiHua()
    {
      InitializeComponent();
      this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
    }
      

  7.   

    你的绘制方法有问题,而且没有调用。改成下面这样        private void TuShiHua_Load(object sender, EventArgs e)
            {
                InitializeGraph();
            }        private void InitializeGraph()
            {            int Width = 200;
                int Height = 200;
                //根据给定的高度和宽度创建一个位图图像
                Bitmap objBitmap = new Bitmap(Width, Height);            //从指定的 objBitmap 对象创建 objGraphics 对象 (即在objBitmap对象中画图)
                Graphics objGraphics = Graphics.FromImage(objBitmap);            //根据给定颜色(LightGray)填充图像的矩形区域 (背景)
                objGraphics.DrawRectangle(new Pen(Color.Red, 1), 0, 0, Width-1, Height-1);
                objGraphics.FillRectangle(new SolidBrush(Color.Red), 1, 1, Width - 2, Height - 2);            //画X轴,pen,x1,y1,x2,y2 注意图像的原始X轴和Y轴计算是以左上角为原点,向右和向下计算的
                Pen pen = new Pen(Color.Blue,1);
                objGraphics.DrawLine(pen, 10, Height - 10, Width - 15, Height - 10);
                //终点箭头画笔
                  Pen endPen = new Pen(Color.Blue, 5);
                endPen.EndCap = LineCap.ArrowAnchor;
                objGraphics.DrawLine(endPen, Width - 15, Height - 10, Width -10, Height - 10);
                //画Y轴,pen,x1,y1,x2,y2
                objGraphics.DrawLine(pen, 10, Height - 10, 10, 15);
                //画Y终点箭头
                objGraphics.DrawLine(endPen, 10, 15, 10, 10);
                //设置背景图
                this.BackgroundImageLayout = ImageLayout.Center;
                this.BackgroundImage = objBitmap;
            }
      

  8.   


    //终点箭头画笔
                  Pen endPen = new Pen(Color.Blue, 5);
                endPen.EndCap = LineCap.ArrowAnchor;
                objGraphics.DrawLine(endPen, Width - 15, Height - 10, Width -10, Height - 10);
    一个错误,不存在名称“LineCap”
      

  9.   

    不好意思啊~!刚刚我没有引用System.Drawing.Drawing2D  所以就没有linecap方法。我刚刚开始学习c,c#。多亏你的帮助了啊~!
    真是太感谢你了。终于实现了~!
    不知道该怎么谢谢你才好了。
    在这里能得大家的积极帮助,真的非常感动。
      

  10.   


    呵呵~!非常谢谢哦。你太了解我咯~刚刚开始学,就是看懂程序也很费劲。
    实在没有理解this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
    }是什么意思啊?我的功能实现了第一步,O(∩_∩)O~以后还请多多指教哦!