类传递bitmap问题~在线等待~~
小弟初学C#,用函数写的画图小程序可以运行,现转换成类模式后看不到图。。请教各位~~
//form2中:Color mycolor = Color.Red;draw_single_qx ceshi = new draw_single_qx(pictureBox1.Height, pictureBox1.Width, mydata,mycolor);ceshi.draw_start();pictureBox1.Image = ceshi.Pic_quxian; //通过测试,可以获取Pic_quxian的宽,高,但是看不到图,前面用函数时候一切正常//------------------------------------------------------------//class draw_single_qx中:Bitmap pic_quxian;Graphics pic_gpr; public draw_single_qx(double height,double length,string[,] mydata,Color mycolor) {//。。。。省略 } public Bitmap Pic_quxian { get { return pic_quxian; } set {} } public Graphics Pic_grp { get { return pic_gpr; } set { Pic_grp = value; } } public void draw_start() { pic_quxian = new Bitmap((int)pic_length, (int)pic_height); pic_gpr = Graphics.FromImage(pic_quxian); pic_gpr.Clear(Color.Black); ltx = lex = (float)(pic_length * 0.05); rtx = rex = (float)(pic_length * 0.95); lty = rty = (float)(pic_height * 0.05); ley = rey = (float)(pic_height * 0.95); //Debug.Print(ltx + "," + lty); pic_gpr.DrawLine(xuxian_pen, ltx, lty, rtx, rty); pic_gpr.DrawLine(xuxian_pen, lex, ley, rex, rey); pic_gpr.DrawLine(shixian_pen, ltx, lty, lex, ley); pic_gpr.DrawLine(shixian_pen, rtx, rty, rex, rey); }
}
}
private void toolStripComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
pe.Width = int.Parse(this.toolStripComboBox1.SelectedItem.ToString());
}
private void Form1_Load(object sender, EventArgs e)
{
int i = 0;
Type t = typeof(Color);
//用循环输出里面的值 只读公开且是静态的属性
foreach (PropertyInfo p in t.GetProperties(BindingFlags.Public | BindingFlags.Static))
{
ToolStripButton bolb = new ToolStripButton();
bolb.Click += new EventHandler(bolb_Click);
bolb.BackColor = Color.FromName(p.Name);
bolb.CheckOnClick = true;
if (i <= 75)
{
this.toolStrip2.Items.Add(bolb);
}
else
{
this.toolStrip3.Items.Add(bolb);
}
i++;
}
}
void bolb_Click(object sender, EventArgs e)
{
for (int i = 0; i < this.toolStrip2.Items.Count; i++)
{
(this.toolStrip2.Items[i] as ToolStripButton).CheckState = CheckState.Unchecked;
}
for (int i = 0; i < this.toolStrip3.Items.Count; i++)
{
(this.toolStrip3.Items[i] as ToolStripButton).CheckState = CheckState.Unchecked;
}
ToolStripButton tb = (sender as ToolStripButton);
tb.CheckState = CheckState.Checked;
this.col = tb.BackColor;
float wht = pe.Width;
pe = new Pen(tb.BackColor);
pe.Width = wht;
}
}
class Stroke
{
//颜色
Color c;
public Color C
{
get { return c; }
set { c = value; }
}
float w;
//宽度
public float W
{
get { return w; }
set { w = value; }
}
List<Point> points;
//点的集合
public List<Point> Points
{
get { return points; }
set { points = value; }
}
//定义一个绘轨迹的方法
public void DrawStroke(Graphics g)
{
for(int i = 0;i <points.Count-1;i++)
{
g.DrawLine(new Pen(c, w), points[i], points[i + 1]);
}
}
}
}