C#用panel绘制柱状图问题
下面是我的代码,是按照课本上的敲的,可是运行后窗体中什么都没有。求问大神是怎么回事呢?谢谢啦!privatevoidshowPic(){acecon=newOleDbCo...
下面是我的代码,是按照课本上的敲的,可是运行后窗体中什么都没有。求问大神是怎么回事呢?谢谢啦!
private void showPic()
{
acecon = new OleDbConnection(aceStr);//实例化数据库连接对象
acecon.Open();
using (comm = new OleDbCommand("select top 3 * from stuScore order by 成绩 desc", acecon))
{
OleDbDataReader dr = comm.ExecuteReader();
Bitmap bitM = new Bitmap(this.panel1.Width, this.panel1.Height);//创建画布
Graphics g = Graphics.FromImage(bitM);
g.Clear(Color.White);//设置画布背景
for(int j = 0; j < 4; j++)//开始读取数据库中的数据并绘图
{
if (dr.Read())
{
int x, y, w, h;
g.DrawString(dr[0].ToString(), new Font("宋体", 8, FontStyle.Regular), new SolidBrush(Color.Black), 76 + 40 * j, this.panel1.Height - 16);
//绘制文字
x = 78 + 40 * j;
//x坐标
y = this.panel1.Height - 20 - Convert.ToInt32((Convert.ToDouble(Convert.ToDouble(dr[1].ToString()) * 20 / 100)));
w = 24;
h = Convert.ToInt32(Convert.ToDouble(dr[1].ToString())* 20 / 100);
g.FillRectangle(new SolidBrush(Color.FromArgb(56, 129, 78)), x, y, w, h);
}
}
this.panel1.BackgroundImage = bitM;
}
} 展开
private void showPic()
{
acecon = new OleDbConnection(aceStr);//实例化数据库连接对象
acecon.Open();
using (comm = new OleDbCommand("select top 3 * from stuScore order by 成绩 desc", acecon))
{
OleDbDataReader dr = comm.ExecuteReader();
Bitmap bitM = new Bitmap(this.panel1.Width, this.panel1.Height);//创建画布
Graphics g = Graphics.FromImage(bitM);
g.Clear(Color.White);//设置画布背景
for(int j = 0; j < 4; j++)//开始读取数据库中的数据并绘图
{
if (dr.Read())
{
int x, y, w, h;
g.DrawString(dr[0].ToString(), new Font("宋体", 8, FontStyle.Regular), new SolidBrush(Color.Black), 76 + 40 * j, this.panel1.Height - 16);
//绘制文字
x = 78 + 40 * j;
//x坐标
y = this.panel1.Height - 20 - Convert.ToInt32((Convert.ToDouble(Convert.ToDouble(dr[1].ToString()) * 20 / 100)));
w = 24;
h = Convert.ToInt32(Convert.ToDouble(dr[1].ToString())* 20 / 100);
g.FillRectangle(new SolidBrush(Color.FromArgb(56, 129, 78)), x, y, w, h);
}
}
this.panel1.BackgroundImage = bitM;
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询