g.FillRectangle(Brushes.BlueViolet,new Rectangle(x, y, between )); //画矩形
g.FillRectangle(Brushes.BlueViolet,new Rectangle(x, y, X1,X2)); //画矩形
用ASP。net做方便 用winform做烦
不会C#,用VB2008写的,转成C#即可。Public Class Form1 Private BP As Bitmap Private XX, YY As Integer Private GradPen As New Pen(Color.ForestGreen, 1) Private SF As New StringFormat Private Hline, Vline, Twidth, HeaderHeight As Integer Private Title As String Private C1 As New Collection Private Structure DYitem Dim Text As String Dim StartDay, EndDay As Integer End Structure Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If BP IsNot Nothing Then BP.Dispose() BP = New Bitmap(Panel1.Width, Panel1.Height) Hline = 18 '需要的天数,限于发帖宽度,此处演示18天 Vline = 15 '需要的行数+1 Title = "生产时间" '左上角标头文字 HeaderHeight = 20 '标头栏高度 XX = BP.Width YY = BP.Height SF.Alignment = StringAlignment.Center SF.LineAlignment = StringAlignment.Center Using G As Graphics = Graphics.FromImage(BP) Using LG As New Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(0, YY), Color.White, Color.LightGoldenrodYellow) G.FillRectangle(LG, New Rectangle(0, 0, XX - 1, YY - 1)) End Using Using LG As New Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(0, HeaderHeight), Color.SkyBlue, Color.SteelBlue) G.FillRectangle(LG, New Rectangle(0, 0, XX - 1, HeaderHeight)) End Using Dim J As Integer = 0 Twidth = 0 For I As Integer = 0 To Title.Length - 1 Twidth += New Font("宋体", 9, FontStyle.Regular, GraphicsUnit.Point).Size Next G.DrawString(Title, New Font("宋体", 9, FontStyle.Regular, GraphicsUnit.Point), Brushes.Black, New Rectangle(1, 1, Twidth * 2, HeaderHeight), SF) G.DrawString(Title, New Font("宋体", 9, FontStyle.Regular, GraphicsUnit.Point), Brushes.White, New Rectangle(0, 0, Twidth * 2, HeaderHeight), SF) For I As Integer = Twidth * 2 To XX Step Int((XX - Twidth * 2) / Hline) GradPen.DashStyle = Drawing2D.DashStyle.Dot G.DrawLine(Me.GradPen, I, 0, I, YY) J += 1 G.DrawString(J, New Font("宋体", 9, FontStyle.Regular, GraphicsUnit.Point), Brushes.Black, New Rectangle(I + 1, 1, XX / Hline, HeaderHeight), SF) G.DrawString(J, New Font("宋体", 9, FontStyle.Regular, GraphicsUnit.Point), Brushes.White, New Rectangle(I, 0, XX / Hline, HeaderHeight), SF) Next Dim tmp1 As Integer = 0 Dim DYM As DYitem Using LG2 As New Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(0, 1), Color.FromArgb(180, 62, 83, 188), Color.FromArgb(180, 62, 83, 188)) For I As Integer = HeaderHeight To YY Step Int(YY / Vline) GradPen.DashStyle = Drawing2D.DashStyle.Dot G.DrawLine(Me.GradPen, 0, I, XX, I) tmp1 += 1 If tmp1 < C1.Count Then DYM = C1(tmp1) G.DrawString(DYM.Text, New Font("宋体", 9, FontStyle.Regular, GraphicsUnit.Point), Brushes.Black, New Rectangle(0, I + 2, Twidth * 2, (YY - HeaderHeight) / Vline), SF) G.FillRectangle(LG2, New Rectangle(Twidth * 2 + Int((XX - Twidth * 2) / Hline * DYM.StartDay), (YY - HeaderHeight) / Vline / 3 + I - 2, Int(Twidth * 2 + (XX - Twidth * 2) / Hline * (DYM.EndDay - DYM.StartDay)), (YY - HeaderHeight) / Vline / 3 * 2)) End If Next End Using G.DrawRectangle(Pens.Black, New Rectangle(0, 0, XX - 1, YY - 1)) G.DrawLine(Pens.Black, 0, HeaderHeight, XX - 1, HeaderHeight) End Using Panel1.BackgroundImage = BP End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load C1.Clear() Dim DYM As DYitem Dim SourceString() As String = {"魔法长袍", "战魂真悟", "奥特之光", "定缘神剑", "如奶神掌", "天启坦克", "屁屁神功", "测试内容", "葵花宝典", "泡妞秘笈", "无相神功", "战神手套", "魔法手套"} For I As Integer = 0 To SourceString.Length - 1 DYM = New DYitem With DYM .Text = SourceString(I) .StartDay = Int(Rnd() * 5) .EndDay = Int(Rnd() * 3 + .StartDay) End With C1.Add(DYM) Next End Sub
窗体上: Panel1 Button1 贴入代码后直接F5运行即可
public class Form1 { private Bitmap BP; private int XX; private int YY; private Pen GradPen = new Pen(Color.ForestGreen, 1); private StringFormat SF = new StringFormat(); private int Hline; private int Vline; private int Twidth; private int HeaderHeight; private string Title; private Collection C1 = new Collection(); private struct DYitem { public string Text; public int StartDay; public int EndDay; }
// 这个写在Button点击事件里 { if (BP != null) BP.Dispose(); BP = new Bitmap(Panel1.Width, Panel1.Height); Hline = 18; //需要的天数,限于发帖宽度,此处演示18天 Vline = 15; //需要的行数+1 Title = "生产时间"; //左上角标头文字 HeaderHeight = 20; //标头栏高度 XX = BP.Width; YY = BP.Height; SF.Alignment = StringAlignment.Center; SF.LineAlignment = StringAlignment.Center; using (Graphics G = Graphics.FromImage(BP)) { using (Drawing2D.LinearGradientBrush LG = new Drawing2D.LinearGradientBrush(new Point(0, 0), new Point(0, YY), Color.White, Color.LightGoldenrodYellow)) { G.FillRectangle(LG, new Rectangle(0, 0, XX - 1, YY - 1)); } using (Drawing2D.LinearGradientBrush LG = new Drawing2D.LinearGradientBrush(new Point(0, 0), new Point(0, HeaderHeight), Color.SkyBlue, Color.SteelBlue)) { G.FillRectangle(LG, new Rectangle(0, 0, XX - 1, HeaderHeight)); } int J = 0; Twidth = 0; for (int I = 0; I <= Title.Length - 1; I++) { Twidth += new Font("宋体", 9, FontStyle.Regular, GraphicsUnit.Point).Size; } G.DrawString(Title, new Font("宋体", 9, FontStyle.Regular, GraphicsUnit.Point), Brushes.Black, new Rectangle(1, 1, Twidth * 2, HeaderHeight), SF); G.DrawString(Title, new Font("宋体", 9, FontStyle.Regular, GraphicsUnit.Point), Brushes.White, new Rectangle(0, 0, Twidth * 2, HeaderHeight), SF); for (int I = Twidth * 2; I <= XX; I += Conversion.Int((XX - Twidth * 2) / Hline)) { GradPen.DashStyle = Drawing2D.DashStyle.Dot; G.DrawLine(this.GradPen, I, 0, I, YY); J += 1; G.DrawString(J, new Font("宋体", 9, FontStyle.Regular, GraphicsUnit.Point), Brushes.Black, new Rectangle(I + 1, 1, XX / Hline, HeaderHeight), SF); G.DrawString(J, new Font("宋体", 9, FontStyle.Regular, GraphicsUnit.Point), Brushes.White, new Rectangle(I, 0, XX / Hline, HeaderHeight), SF); } int tmp1 = 0; DYitem DYM = default(DYitem); using (Drawing2D.LinearGradientBrush LG2 = new Drawing2D.LinearGradientBrush(new Point(0, 0), new Point(0, 1), Color.FromArgb(180, 62, 83, 188), Color.FromArgb(180, 62, 83, 188))) { for (int I = HeaderHeight; I <= YY; I += Conversion.Int(YY / Vline)) { GradPen.DashStyle = Drawing2D.DashStyle.Dot; G.DrawLine(this.GradPen, 0, I, XX, I); tmp1 += 1; if (tmp1 < C1.Count) { DYM = C1(tmp1); G.DrawString(DYM.Text, new Font("宋体", 9, FontStyle.Regular, GraphicsUnit.Point), Brushes.Black, new Rectangle(0, I + 2, Twidth * 2, (YY - HeaderHeight) / Vline), SF); G.FillRectangle(LG2, new Rectangle(Twidth * 2 + Conversion.Int((XX - Twidth * 2) / Hline * DYM.StartDay), (YY - HeaderHeight) / Vline / 3 + I - 2, Conversion.Int(Twidth * 2 + (XX - Twidth * 2) / Hline * (DYM.EndDay - DYM.StartDay)), (YY - HeaderHeight) / Vline / 3 * 2)); } } } G.DrawRectangle(Pens.Black, new Rectangle(0, 0, XX - 1, YY - 1)); G.DrawLine(Pens.Black, 0, HeaderHeight, XX - 1, HeaderHeight); } Panel1.BackgroundImage = BP; }
这种图形可使用第三方控件或用datagridview实现
http://topic.csdn.net/u/20090815/00/02b4b816-65bc-4dcf-b054-bafc3aac44cf.html
列标头就是你的 1 2 3 4 5 6 7 8 9 10....
每一行就是每一个型号,行标头上写上型号,然后再设置每一行对应的单元格的背景色就OK了~
这个方法我也想过了,不过看起来实在是......
后来有人用panel控件,画画的方式给我画了个大概的出来,不过是死的,数据变动比较困难
//画矩形
//画矩形
用winform做烦
Private BP As Bitmap
Private XX, YY As Integer
Private GradPen As New Pen(Color.ForestGreen, 1)
Private SF As New StringFormat
Private Hline, Vline, Twidth, HeaderHeight As Integer
Private Title As String
Private C1 As New Collection
Private Structure DYitem
Dim Text As String
Dim StartDay, EndDay As Integer
End Structure
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If BP IsNot Nothing Then BP.Dispose()
BP = New Bitmap(Panel1.Width, Panel1.Height)
Hline = 18 '需要的天数,限于发帖宽度,此处演示18天
Vline = 15 '需要的行数+1
Title = "生产时间" '左上角标头文字
HeaderHeight = 20 '标头栏高度
XX = BP.Width
YY = BP.Height
SF.Alignment = StringAlignment.Center
SF.LineAlignment = StringAlignment.Center
Using G As Graphics = Graphics.FromImage(BP)
Using LG As New Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(0, YY), Color.White, Color.LightGoldenrodYellow)
G.FillRectangle(LG, New Rectangle(0, 0, XX - 1, YY - 1))
End Using
Using LG As New Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(0, HeaderHeight), Color.SkyBlue, Color.SteelBlue)
G.FillRectangle(LG, New Rectangle(0, 0, XX - 1, HeaderHeight))
End Using
Dim J As Integer = 0
Twidth = 0
For I As Integer = 0 To Title.Length - 1
Twidth += New Font("宋体", 9, FontStyle.Regular, GraphicsUnit.Point).Size
Next
G.DrawString(Title, New Font("宋体", 9, FontStyle.Regular, GraphicsUnit.Point), Brushes.Black, New Rectangle(1, 1, Twidth * 2, HeaderHeight), SF)
G.DrawString(Title, New Font("宋体", 9, FontStyle.Regular, GraphicsUnit.Point), Brushes.White, New Rectangle(0, 0, Twidth * 2, HeaderHeight), SF)
For I As Integer = Twidth * 2 To XX Step Int((XX - Twidth * 2) / Hline)
GradPen.DashStyle = Drawing2D.DashStyle.Dot
G.DrawLine(Me.GradPen, I, 0, I, YY)
J += 1
G.DrawString(J, New Font("宋体", 9, FontStyle.Regular, GraphicsUnit.Point), Brushes.Black, New Rectangle(I + 1, 1, XX / Hline, HeaderHeight), SF)
G.DrawString(J, New Font("宋体", 9, FontStyle.Regular, GraphicsUnit.Point), Brushes.White, New Rectangle(I, 0, XX / Hline, HeaderHeight), SF)
Next
Dim tmp1 As Integer = 0
Dim DYM As DYitem
Using LG2 As New Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(0, 1), Color.FromArgb(180, 62, 83, 188), Color.FromArgb(180, 62, 83, 188))
For I As Integer = HeaderHeight To YY Step Int(YY / Vline)
GradPen.DashStyle = Drawing2D.DashStyle.Dot
G.DrawLine(Me.GradPen, 0, I, XX, I)
tmp1 += 1
If tmp1 < C1.Count Then
DYM = C1(tmp1)
G.DrawString(DYM.Text, New Font("宋体", 9, FontStyle.Regular, GraphicsUnit.Point), Brushes.Black, New Rectangle(0, I + 2, Twidth * 2, (YY - HeaderHeight) / Vline), SF)
G.FillRectangle(LG2, New Rectangle(Twidth * 2 + Int((XX - Twidth * 2) / Hline * DYM.StartDay), (YY - HeaderHeight) / Vline / 3 + I - 2, Int(Twidth * 2 + (XX - Twidth * 2) / Hline * (DYM.EndDay - DYM.StartDay)), (YY - HeaderHeight) / Vline / 3 * 2))
End If
Next
End Using
G.DrawRectangle(Pens.Black, New Rectangle(0, 0, XX - 1, YY - 1))
G.DrawLine(Pens.Black, 0, HeaderHeight, XX - 1, HeaderHeight)
End Using
Panel1.BackgroundImage = BP
End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
C1.Clear()
Dim DYM As DYitem
Dim SourceString() As String = {"魔法长袍", "战魂真悟", "奥特之光", "定缘神剑", "如奶神掌", "天启坦克", "屁屁神功", "测试内容", "葵花宝典", "泡妞秘笈", "无相神功", "战神手套", "魔法手套"}
For I As Integer = 0 To SourceString.Length - 1
DYM = New DYitem
With DYM
.Text = SourceString(I)
.StartDay = Int(Rnd() * 5)
.EndDay = Int(Rnd() * 3 + .StartDay)
End With
C1.Add(DYM)
Next
End Sub
Panel1
Button1
贴入代码后直接F5运行即可
{
private Bitmap BP;
private int XX;
private int YY;
private Pen GradPen = new Pen(Color.ForestGreen, 1);
private StringFormat SF = new StringFormat();
private int Hline;
private int Vline;
private int Twidth;
private int HeaderHeight;
private string Title;
private Collection C1 = new Collection();
private struct DYitem
{
public string Text;
public int StartDay;
public int EndDay;
}
// 这个写在Button点击事件里 {
if (BP != null) BP.Dispose();
BP = new Bitmap(Panel1.Width, Panel1.Height);
Hline = 18;
//需要的天数,限于发帖宽度,此处演示18天
Vline = 15;
//需要的行数+1
Title = "生产时间";
//左上角标头文字
HeaderHeight = 20;
//标头栏高度
XX = BP.Width;
YY = BP.Height;
SF.Alignment = StringAlignment.Center;
SF.LineAlignment = StringAlignment.Center;
using (Graphics G = Graphics.FromImage(BP)) {
using (Drawing2D.LinearGradientBrush LG = new Drawing2D.LinearGradientBrush(new Point(0, 0), new Point(0, YY), Color.White, Color.LightGoldenrodYellow)) {
G.FillRectangle(LG, new Rectangle(0, 0, XX - 1, YY - 1));
}
using (Drawing2D.LinearGradientBrush LG = new Drawing2D.LinearGradientBrush(new Point(0, 0), new Point(0, HeaderHeight), Color.SkyBlue, Color.SteelBlue)) {
G.FillRectangle(LG, new Rectangle(0, 0, XX - 1, HeaderHeight));
}
int J = 0;
Twidth = 0;
for (int I = 0; I <= Title.Length - 1; I++) {
Twidth += new Font("宋体", 9, FontStyle.Regular, GraphicsUnit.Point).Size;
}
G.DrawString(Title, new Font("宋体", 9, FontStyle.Regular, GraphicsUnit.Point), Brushes.Black, new Rectangle(1, 1, Twidth * 2, HeaderHeight), SF);
G.DrawString(Title, new Font("宋体", 9, FontStyle.Regular, GraphicsUnit.Point), Brushes.White, new Rectangle(0, 0, Twidth * 2, HeaderHeight), SF);
for (int I = Twidth * 2; I <= XX; I += Conversion.Int((XX - Twidth * 2) / Hline)) {
GradPen.DashStyle = Drawing2D.DashStyle.Dot;
G.DrawLine(this.GradPen, I, 0, I, YY);
J += 1;
G.DrawString(J, new Font("宋体", 9, FontStyle.Regular, GraphicsUnit.Point), Brushes.Black, new Rectangle(I + 1, 1, XX / Hline, HeaderHeight), SF);
G.DrawString(J, new Font("宋体", 9, FontStyle.Regular, GraphicsUnit.Point), Brushes.White, new Rectangle(I, 0, XX / Hline, HeaderHeight), SF);
}
int tmp1 = 0;
DYitem DYM = default(DYitem);
using (Drawing2D.LinearGradientBrush LG2 = new Drawing2D.LinearGradientBrush(new Point(0, 0), new Point(0, 1), Color.FromArgb(180, 62, 83, 188), Color.FromArgb(180, 62, 83, 188))) {
for (int I = HeaderHeight; I <= YY; I += Conversion.Int(YY / Vline)) {
GradPen.DashStyle = Drawing2D.DashStyle.Dot;
G.DrawLine(this.GradPen, 0, I, XX, I);
tmp1 += 1;
if (tmp1 < C1.Count) {
DYM = C1(tmp1);
G.DrawString(DYM.Text, new Font("宋体", 9, FontStyle.Regular, GraphicsUnit.Point), Brushes.Black, new Rectangle(0, I + 2, Twidth * 2, (YY - HeaderHeight) / Vline), SF);
G.FillRectangle(LG2, new Rectangle(Twidth * 2 + Conversion.Int((XX - Twidth * 2) / Hline * DYM.StartDay), (YY - HeaderHeight) / Vline / 3 + I - 2, Conversion.Int(Twidth * 2 + (XX - Twidth * 2) / Hline * (DYM.EndDay - DYM.StartDay)), (YY - HeaderHeight) / Vline / 3 * 2));
}
}
}
G.DrawRectangle(Pens.Black, new Rectangle(0, 0, XX - 1, YY - 1));
G.DrawLine(Pens.Black, 0, HeaderHeight, XX - 1, HeaderHeight);
}
Panel1.BackgroundImage = BP;
}
//这个写在Form_Load里
{
C1.Clear();
DYitem DYM = default(DYitem);
string[] SourceString = { "魔法长袍", "战魂真悟", "奥特之光", "定缘神剑", "如奶神掌", "天启坦克", "屁屁神功", "测试内容", "葵花宝典", "泡妞秘笈",
"无相神功", "战神手套", "魔法手套" };
for (int I = 0; I <= SourceString.Length - 1; I++) {
DYM = new DYitem();
{
DYM.Text = SourceString(I);
DYM.StartDay = Conversion.Int(VBMath.Rnd() * 5);
DYM.EndDay = Conversion.Int(VBMath.Rnd() * 3 + DYM.StartDay);
}
C1.Add(DYM);
}
}
}以上是网上在线转换来的。
首先,你画图要有画板吧?你在什么地方画东西?所以需要
Graphics,有了画板你得有笔来画线条啊 所以有了Pen恩,写什么字好看呢?狂草还是楷书?多大的字才好?我们需要一个Font你要在什么地方开始画?画多大面积?所以有了Point,Size.画出了轮廓你得上色啊?怎么上色?所以有了Brush如果你要修改一张图片怎么办?
你需要有图片先吧?
所以有了Image,但是电脑里图片有矢量,位图。
Image就成了抽象类,位图Bitmap是Image的实现类.然后把图片夹到画板上才能修改啊
Image image = Image.FromFile("C:\\1.jpg");
Graphics g = Graphics.FromImage(image);架上图片了你就可以在画板上涂改了啊我要写多几个字上去
string str = "我恨Baidu"; //写什么字?
Font font = Font("宋体",30f); //字是什么样子的?
Brush brush = Brushes.Red; //用红色涂上我的字吧;
PointF point = new PointF(10f,10f); //从什么地方开始写字捏?//横着写还是竖着写呢?
System.Drawing.StringFormat sf = new System.Drawing.StringFormat();
//还是竖着写吧
sf.FormatFlags = StringFormatFlags.DirectionVertical//开始写咯
g.DrawString(str,font,brush,point,sf);//写好了,我要把我的作品收藏起来image.Save("C:\\1.jpg"); 不过你要是能像他一样讲解下就更好了,因为我第一次用Winfrom画图,属于菜鸟级别。呵呵
我朋友的朋友给我们写的也是用这控件,和你写的大同小异
无论用什么都可以,哪怕你用的是个button都可以画上去。
或者干脆什么都不用,直接在桌面上画都可以。
{
public Rectangle Bounds //建立矩形区域
{
get {return new Rectangle(起点x,
起点y,
宽,
高
)} //这里自己设置;
}
protected override void OnPaint(PaintEventArgs e)
{
Pen pen = new Pen(Color.Black); // Color是枚举,选个颜色画矩形框;
e.Graphics.DrawRectangle(pen,Bounds)// 画框;
Brush brush = new brush(Color.XXX) //选个笔刷颜色;
e.Graphics.FillRectangle(brush,Bounds); //填充矩形;
}
}
原来拥有BackGroundImage或是Image属性的控件都可以啊,我说怎么都用这个空间呢。对了,我运行了下,开头:private Collection C1 = new Collection();
这个地方同不过,说:找不到类别或命名空间名称‘Collection’(你是否遗漏using指示词或组件参考?)
ArrayList是什么意思?范型?