| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2291 人关注过本帖
标题:求大神帮忙解答问题,C#编程画圆,出现下列问题,怎么破?
只看楼主 加入收藏
mjh113439122
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2015-10-6
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:5 
求大神帮忙解答问题,C#编程画圆,出现下列问题,怎么破?
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            class hanshu
            {
                public double F(int x)
                {
                    const double a1=30.58;
                    const double b1=-110.7;
                    const double c1=27.96;
                    double f=a1*Math.Exp(-((x-b1)/c1)*((x-b1)/c1));
                }
            }
           
                    

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
           
           
  
           
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
           
        
        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {
           
        }

        private void button1_Click(object sender, EventArgs e)
        {
             hanshu qiangdu1=new hanshu();
             int x=Convert.ToInt32(textBox1.Text);
             double r1=qiangdu1.F(x);


             hanshu qiangdu2=new hanshu();
             int m=Convert.ToInt32(textBox2.Text);
             double r2=qiangdu1.F(m);


             hanshu qiangdu3=new hanshu();
             int n=Convert.ToInt32(textBox3.Text);
             double r3=qiangdu1.F(n);
     
            
            
            
            Graphics gra = this.pictureBox1.CreateGraphics();
            Pen pen = new Pen(Color.Pink);
            gra.DrawEllipse(pen, 10, 10, Convert.ToInt32(r1), Convert.ToInt32(r1));
            gra.DrawEllipse(pen, 20, 10,Convert.ToInt32(r2), Convert.ToInt32(r2));
            gra.DrawEllipse(pen, 10, 20,Convert.ToInt32(r3), Convert.ToInt32(r3));

        }
    }
}

错误    应输入 class、delegate、enum、interface 或 struct
错误    应输入类型、命名空间定义或文件尾   
错误    “WindowsFormsApplication1.Form1.hanshu.F(int)”: 并非所有的代码路径都返回值
搜索更多相关主题的帖子: public private double 
2015-10-06 18:08
yhlvht
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:36
帖 子:707
专家分:4405
注 册:2011-9-30
收藏
得分:20 
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            hanshu qiangdu1 = new hanshu();
            int x = Convert.ToInt32(textBox1.Text);
            double r1 = qiangdu1.F(x);

            hanshu qiangdu2 = new hanshu();
            int m = Convert.ToInt32(textBox2.Text);
            double r2 = qiangdu1.F(m);

            hanshu qiangdu3 = new hanshu();
            int n = Convert.ToInt32(textBox3.Text);
            double r3 = qiangdu1.F(n);

            Graphics gra = this.pictureBox1.CreateGraphics();
            Pen pen = new Pen(Color.Pink);
            gra.DrawEllipse(pen, 10, 10, Convert.ToInt32(r1), Convert.ToInt32(r1));
            gra.DrawEllipse(pen, 20, 10, Convert.ToInt32(r2), Convert.ToInt32(r2));
            gra.DrawEllipse(pen, 10, 20, Convert.ToInt32(r3), Convert.ToInt32(r3));
        }
    }

    class hanshu
    {
        public double F(int x)
        {
            const double a1 = 30.58;
            const double b1 = -110.7;
            const double c1 = 27.96;
            double f = a1 * Math.Exp(-((x - b1) / c1) * ((x - b1) / c1));
            return f;
        }
    }
}
2015-10-06 23:55
mjh113439122
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2015-10-6
收藏
得分:0 
画不出来圆是为什么那?
2015-10-07 12:40
tlliqi
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:204
帖 子:15453
专家分:65956
注 册:2006-4-27
收藏
得分:0 
回复 3楼 mjh113439122
试试楼上的
2015-10-07 18:29
mjh113439122
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2015-10-6
收藏
得分:0 
试了,还是不行
WindowsFormsApplication1.rar (797 Bytes)
2015-10-07 18:33
yhlvht
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:36
帖 子:707
专家分:4405
注 册:2011-9-30
收藏
得分:0 
这个程序一共画了三个椭圆,坐标分别是picturebox1相对左上角坐标的10,10    20,10   10,20
正常画出来三个椭圆是相交的,DrawEllipse方法的第4,5个参数分别表示宽和高,因为传入的参数分别都为r1,r2,r3,宽高一样,所以画出来是圆形
但是hanshu类的F方法,也就是计算宽高的这个方法,那个公式没看明白,经测试,传入的大多数字,计算后宽高(半径)几乎都小于0或接近0,所以看不到
你在三个textbox内都输入-100,即传入-100参数给F方法,能得到宽高(半径)为26.41401931439983,可以看到画出来的圆(仅测试而已)
2015-10-07 23:41
快速回复:求大神帮忙解答问题,C#编程画圆,出现下列问题,怎么破?
数据加载中...
 
   



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

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