Using notepad to write winform applets is simple or complicated?

Source: Internet
Author: User

Today, I began to sort out random files on my computer and found that many small files I used to train my hands are very interesting. There is such a program in it. When there was an activity in the department, we needed to draw a lottery for the audience. At that time, Hu designed one with flash. I thought I wanted to write one as interesting as I thought, however, after I restored it, I had not installed vs, but only one.. NET Framework. I have always liked using notepad to write some simple data structures and algorithm questions. However, the winform program has not been tried yet, but I think it should be okay. So I completed the program one afternoon. At that time, I was very happy, so I still remember it, but I didn't record it at that time. As a result, I tried it for a long time to generate a background program without a DOS window.

I am not a masochistic. Instead, I use NotePad to write programs. I just think that sometimes vs is not necessary to cut down the ant, and I like to study how vs achieves some unexpected functions. I can only do some superficial exploration.

The function of the program is very simple, just to draw a lottery for 14 rows and 30 columns of seats. The host clicks start or stop to extract several lucky viewers. Because this is just a simulation, I simply call threading. timer then uses a random number to extract the image. There may be "lucky" for multiple times ":). The main problem is the compilation of winform programs. windows. forms namespace, declare the control variables to be used in the class, initialize the control in the constructor, and then add the control to the container. Actually, I don't know how to make the statement correctly. Let's look at the code. Basic knowledge seems to have to be enhanced.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Drawing;
using System.Drawing.Drawing2D;

public class Lottery : Form
{
    private Panel panel1;
    private Label lblRow;
    private Label lblSeat;
    private Label numFront;
    private Label numRear;
    private Button btnStart;
    private readonly int interval = 25;  //timer的触发时段
    private System.Threading.Timer timer = null;

    private bool flag=true;
    
    public Lottery()
    {
       panel1 =new Panel();
       lblRow = new Label();    
       numFront = new Label();	
       lblSeat = new Label();
       numRear = new Label();
       btnStart=new Button();
       this.panel1.SuspendLayout();
       this.SuspendLayout();
       this.AutoSize =true;
       panel1.BackColor = System.Drawing.Color.Transparent;
       this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
       panel1.Controls.Add(lblRow);
       panel1.Controls.Add(numFront);
       panel1.Controls.Add(lblSeat);
       panel1.Controls.Add(numRear);
       panel1.Controls.Add(btnStart);
       
       this.Controls.Add(panel1);
       lblRow.Text="排";
       lblRow.Location = new Point(0,20);
       lblRow.Size = new Size(20,20);
       numFront.Text="*";
       numFront.Location = new Point(20,20); 
       numFront.Size = new Size(20,20);   
       lblSeat.Text="座";  
       lblSeat.Location = new Point(40,20); 
       lblSeat.Size = new Size(20,20);
       numRear.Text="*";
       numRear.Location = new Point(60,20);
       numRear.Size = new Size(20,20);
       btnStart.Text = "Start";
       btnStart.Location = new Point(100,60);
       btnStart.Size = new Size(60,30);
       btnStart.Click+=new System.EventHandler(this.btnStart_Click);
    }
    
    public void btnStart_Click(object sender,System.EventArgs e)
    {
        if(btnStart.Text.Equals("Start"))
        {
              Start();
              btnStart.Text = "Pause";
        }
        else
        {
             Stop();
             btnStart.Text ="Start";
        }   
    }
     
    public void Start()
    {      
         timer  = new System.Threading.Timer(new TimerCallback(Walke), null, 100, interval);             
    }

    public void Walke(object o)
    {
         int tmp;
         Random r = new Random();
         tmp = r.Next(14);
         numFront.Text = tmp.ToString();
         tmp = r.Next(30);
         numRear.Text = tmp.ToString();
    }

    public void Stop()
    {
         timer.Dispose();
    }

    [STAThread]
    public static void Main(string[] args)
    {
          Application.Run(new Lottery());
    }
}

There is also an important compilation command:

Delete the DOS interface when editing the form.

CSC/T: winexe program. CS

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.