| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3017 人关注过本帖, 1 人收藏
标题:[求助]g.DrawLine(myPen, 3, 103, 6, 106)参数无效
取消只看楼主 加入收藏
cobby
Rank: 1
等 级:新手上路
威 望:1
帖 子:565
专家分:0
注 册:2007-7-11
收藏(1)
 问题点数:0 回复次数:7 
[求助]g.DrawLine(myPen, 3, 103, 6, 106)参数无效
g.DrawLine(myPen, 3, 103, 6, 106);
居然说我参数无效。。。慌了,请问这是怎么回事啊?
搜索更多相关主题的帖子: DrawLine myPen 参数 
2007-11-06 09:03
cobby
Rank: 1
等 级:新手上路
威 望:1
帖 子:565
专家分:0
注 册:2007-7-11
收藏
得分:0 

这句语句是放在一个循环里面的,源代码是:

for (int i = 0; i < gen; i++)
{
g.DrawLine(myPen, 3, 103, 6, 106);
}
搞笑的是,同样是画线,第一次循环i=0时运行正常,第二次循环i=1时总报错说参数无效。。。明明参数是常数。。。想不通


努力成为菜鸟!
2007-11-06 09:08
cobby
Rank: 1
等 级:新手上路
威 望:1
帖 子:565
专家分:0
注 册:2007-7-11
收藏
得分:0 

其它代码我想应该没什么问题的。。。贴一下
for (int i = 0; i < gen_GA-1; i++)
{
//绘制进化曲线
Pen myPen = new Pen(Color.Blue);
int x1, x2, y1, y2;
x1 = Convert.ToInt32(i * pictureBox3.Width / gen_GA);
y1 = pictureBox3.Height - Convert.ToInt32(history_best_fit_GA[i] * pictureBox3.Height / first_fit_GA / 2);
x2 = Convert.ToInt32((i+1) * pictureBox3.Width / gen_GA);
y2 = pictureBox3.Height - Convert.ToInt32(history_best_fit_GA[i+1] * pictureBox3.Height / first_fit_GA / 2);
g.DrawLine(myPen, x1, y1, x2, y2); //这句执行第二次时,即i=1时,x1=3,x2=6,y1=103,y2=106,于是我用常数代入,一样报参数无效的错

myPen = new Pen(Color.Red);
y1 = pictureBox3.Height - Convert.ToInt32(history_avg_fit_GA[i] * pictureBox3.Height / first_fit_GA / 2);
y2 = pictureBox3.Height - Convert.ToInt32(history_avg_fit_GA[i+1] * pictureBox3.Height / first_fit_GA / 2);
g.DrawLine(myPen, x1, y1, x2, y2);

//释放绘图资源
myPen.Dispose();
g.Dispose();
}

[此贴子已经被作者于2007-11-6 9:32:24编辑过]


努力成为菜鸟!
2007-11-06 09:30
cobby
Rank: 1
等 级:新手上路
威 望:1
帖 子:565
专家分:0
注 册:2007-7-11
收藏
得分:0 
这个错好像是挺郁闷的。。。灵异事件。。。

努力成为菜鸟!
2007-11-06 09:46
cobby
Rank: 1
等 级:新手上路
威 望:1
帖 子:565
专家分:0
注 册:2007-7-11
收藏
得分:0 
以下是引用shen521941在2007-11-6 10:13:57的发言:
灵异事件 是应为 那两个三角形的角度不一样!

不是吧,我画直线啊,没画三角形,也不涉及角度。。。


努力成为菜鸟!
2007-11-06 10:26
cobby
Rank: 1
等 级:新手上路
威 望:1
帖 子:565
专家分:0
注 册:2007-7-11
收藏
得分:0 
以下是引用jacklee在2007-11-6 10:16:21的发言:

你检查各个参数了没有?都TOSTRING()出来看一下,参数真的正确码?

都调试过了,值也看到了。。。分别是3,103,6,106,类型定死的int型,也不会出错。。。而且奇怪的是第一个i=0值运行正常,i=1时运行才出错,而两次代码又没改过。


努力成为菜鸟!
2007-11-06 10:27
cobby
Rank: 1
等 级:新手上路
威 望:1
帖 子:565
专家分:0
注 册:2007-7-11
收藏
得分:0 
有意思的是,这段程序其实是我从程序的另一个模块中copy过来的,那个模块里的这段程序运行完全正常的。。。邪门了

努力成为菜鸟!
2007-11-06 10:33
cobby
Rank: 1
等 级:新手上路
威 望:1
帖 子:565
专家分:0
注 册:2007-7-11
收藏
得分:0 

for (int i = 0; i < gen_GA-1; i++)
{
//绘制进化曲线
Pen myPen = new Pen(Color.Blue);
int x1, x2, y1, y2;
x1 = Convert.ToInt32(i * pictureBox3.Width / gen_GA);
y1 = pictureBox3.Height - Convert.ToInt32(history_best_fit_GA[i] * pictureBox3.Height / first_fit_GA / 2);
x2 = Convert.ToInt32((i+1) * pictureBox3.Width / gen_GA);
y2 = pictureBox3.Height - Convert.ToInt32(history_best_fit_GA[i+1] * pictureBox3.Height / first_fit_GA / 2);
g.DrawLine(myPen, x1, y1, x2, y2);

myPen = new Pen(Color.Red);
y1 = pictureBox3.Height - Convert.ToInt32(history_avg_fit_GA[i] * pictureBox3.Height / first_fit_GA / 2);
y2 = pictureBox3.Height - Convert.ToInt32(history_avg_fit_GA[i+1] * pictureBox3.Height / first_fit_GA / 2);
g.DrawLine(myPen, x1, y1, x2, y2);

//释放绘图资源
myPen.Dispose();
g.Dispose(); //这句错了,应该放在循环外面。
}

问题找到了。。。用红字写出了,太粗心了,谢谢各位帮忙哦!


努力成为菜鸟!
2007-11-06 10:57
快速回复:[求助]g.DrawLine(myPen, 3, 103, 6, 106)参数无效
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016672 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved