none
未能找到类型或命名空间名“Form1” RRS feed

  • 问题

  • MainForm.cs
    
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    //using example3.RandomHelp;
    namespace example3
    {
      public partial class MainForm : Form
      {
        Timer timer = new Timer();
        int zheng;
        int shi;
          
        public MainForm()
        {
          InitializeComponent();
          button1.Click+=button1_Click;
         button2.Click+=button2_Click;
           
          // if (textBox3.Text != null)
          // {
           //  string m = textBox3.Text;
            
        }
      
        void timer_Tick(object sender, EventArgs e)
        {
          //throw new NotImplementedException();
        //  radioButton2_Click(null,null);
         //  double r = (example3.RandomHelp.GetIntRandomNumber(int.Parse(textBox1.Text), int.Parse(textBox2.Text)));
        //  string s = r.ToString();
        //   label4.Text = s;
          if (zheng == 1)
          {
            int r = (example3.RandomHelp.GetIntRandomNumber(int.Parse(textBox1.Text), int.Parse(textBox2.Text)));
            string s = r.ToString();
            label4.Text = s;
          }
           if (shi == 2)
          {
            double r = (example3.RandomHelp.GetDoubleRandomNumber(int.Parse(textBox1.Text), int.Parse(textBox2.Text)));
              string s = r.ToString();
              label4.Text = s;
           }
        }
        //整数
        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
          RadioButton r = sender as RadioButton;
          if (r.Checked == true)
          {
            zheng = 1;
          }
        }
        //实数
        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
          RadioButton r = sender as RadioButton;
          if (r.Checked == true)
          {
            shi = 2;
          }
        }
        //开始
        private void button1_Click(object sender, EventArgs e)
        {
          timer.Interval = int.Parse(textBox3.Text);
          //timer.Interval = 500;
          timer.Tick += timer_Tick; 
          timer.Start();
            
        }
        //停止
        private void button2_Click(object sender, EventArgs e)
        {
          timer.Stop();
        }
        
      }
    }
    RandomHelp.cs
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    //using System.Windows.Forms.Timer;
      
    namespace example3
    {
      class RandomHelp
      {
        public static int GetIntRandomNumber(int min,int max)
        {
          Random r=new Random();
          int ran=r.Next(min, max + 1);
      
        return ran;
        }
        //很不错的算法
        public static double GetDoubleRandomNumber(int min,int max)
        {
          Random r = new Random();
     //很不错的算法    
          double m=r.NextDouble() * max;
          double n = r.NextDouble() * min;
           
          if(m-n>2.0)
          return m;
          else
          return n+3.0;
        }
      }
    }


    Program.cs
    
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    //using example3.RandomHelp;
    
    namespace WindowsFormsApp1
    {
        static class Program
        {
            /// <summary>
            /// 应用程序的主入口点。
            /// </summary>
            [STAThread]
            static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
            }
        }
    }

    怎么未能找到类型或命名空间名“Form1”,最后一张图片中显示。。。

    2017年5月23日 13:00

全部回复

  • 这一句

    Application.Run(new Form1());

    改成

    Application.Run(new example3.MainForm ());


    专注于.NET ERP/CRM开发框架,C/S架构,SQL Server + ORM(LLBL Gen Pro) + Infragistics WinForms

    2017年5月24日 0:46
  • 后来的界面设置成这样子,有错误么?

    这个程序是得出Random随机值,怎样才能正常显示呢?

    我加了Timer和otton1 botton2、textBox1 textBox2 textBox3、label4、radioButton1、radioButton2,要怎样子呢?

    2017年5月24日 10:34
  • 不明白你的需求,上面的编译错误可以了之后,没看出代码中的逻辑问题,随机数没有产生,还是有什么线程操作异常?

    专注于.NET ERP/CRM开发框架,C/S架构,SQL Server + ORM(LLBL Gen Pro) + Infragistics WinForms

    2017年5月25日 0:37