问题描述:
我用C#编写了一个windows窗体应用程序,绘制一个象温度计和输液瓶那样的图象,请问需要用什么绘制?
问题解答:
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace 长方形
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Rectangle : System.Windows.Forms.Form
{
private Brush bgBrush;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Rectangle()
{
// SetStyle(ControlStyles.Opaque,true);
bgBrush=new SolidBrush(Color.Firebrick);//设置窗体初始背景颜色
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(584, 342);
this.Name = "Form1";
this.Text = "长方形";
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Rectangal());
}
protected override void OnPaint(PaintEventArgs paintEvent)
{
Graphics e=paintEvent.Graphics;//获取用于绘制的图形
e.SmoothingMode=SmoothingMode.AntiAlias;
e.FillRectangle(bgBrush,ClientRectangle);//ClientRectangle用于获取表示控件的工作区矩形
e.FillRectangle(new SolidBrush(Color.FromArgb(180,Color.Blue)),ClientRectangle);//设置工作区颜色
//--------------选择不同的画笔进行作图----------------
HatchBrush hb=new HatchBrush(HatchStyle.BackwardDiagonal,Color.Red,Color.PowderBlue);
e.FillRectangle(hb,250,100,150,50);
Brush br=new SolidBrush(Color.Green);
e.FillRectangle(br,250,220,200,50);
Pen pn=new Pen(Color.Yellow,2);
e.DrawRectangle(pn,250,10,100,50);
}
}
}
gdi +
你要什么样的效果啊?
要是 固定的 图 就把图直接用
Bitmap myBitmap = new Bitmap("ff.bmp");
Graphics myGraphics = panel1.CreateGraphics();
myGraphics.DrawImage(myBitmap, 1, 1);
myGraphics.DrawImage(secondBitmap, 150, 10);
要不是现成的图 就 myGraphics。drawline...什么的 画
在paint 事件里就能 不停重画 保持刷新了
有这个第三方控件
DotnetCharting
你到网上搜一下子,如果下不到我可以传给你
System.Drawing
GDI+啊