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); } /////////////////////////////////////////////////////////////////////////////////
}
}
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); } /////////////////////////////////////////////////////////////////////////////////
}
}
里面的objBitmap对象最后是附值给窗体的背景图了吗?
{
Graphics g = this.CreateGraphics();
Pen p = new Pen(Color.Blue,1);
g.DrawLine(p, 0, 0, 100, 0);}
{
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);
}
public Form1()
{
InitializeComponent();
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
}
public TuShiHua()
{
InitializeComponent();
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
}
{
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;
}
//终点箭头画笔
Pen endPen = new Pen(Color.Blue, 5);
endPen.EndCap = LineCap.ArrowAnchor;
objGraphics.DrawLine(endPen, Width - 15, Height - 10, Width -10, Height - 10);
一个错误,不存在名称“LineCap”
真是太感谢你了。终于实现了~!
不知道该怎么谢谢你才好了。
在这里能得大家的积极帮助,真的非常感动。
呵呵~!非常谢谢哦。你太了解我咯~刚刚开始学,就是看懂程序也很费劲。
实在没有理解this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
}是什么意思啊?我的功能实现了第一步,O(∩_∩)O~以后还请多多指教哦!