zoukankan      html  css  js  c++  java
  • C#实现红绿灯

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

    namespace WindowsFormsApplication2
    {
    public partial class Form1 : Form
    {
    private string strColor;
    public Form1()
    {
    InitializeComponent();
    }

    private void Form1_Paint(object sender, PaintEventArgs e)
    {
    Graphics g = e.Graphics;
    g.FillRectangle(Brushes.White, this.ClientRectangle);
    //report dimensions of clipping rectangle to console
    Console.WriteLine("e.ClipRectangle = " + e.ClipRectangle);
    //draw outline
    g.FillRectangle(Brushes.Black,10,10,50,150);
    g.DrawEllipse(Pens.White,15,15,40,40);
    g.DrawEllipse(Pens.White,15,60,40,40);
    g.DrawEllipse(Pens.White,15,105,40,40);
    //use application state to draw exactly one of three lights
    switch(strColor)
    {
    case "red":
    g.FillEllipse(Brushes.Red,15,15,40,40);
    break;
    case "yellow":
    g.FillEllipse(Brushes.Yellow,15,60,40,40);
    break;
    case "green":
    g.FillEllipse(Brushes.Green,15,105,40,40);
    break;
    default:
    g.FillEllipse(Brushes.Red,15,15,40,40);
    break;
    }
    }

    private void Form1_Click(object sender, EventArgs e)
    {
    //change application state by altering value of strColor
    switch(strColor)
    {
    case "red":
    strColor = "yellow";
    break;
    case "yellow":
    strColor = "green";
    break;
    default:
    strColor = "red";
    break;
    }
    //invaliate the region containing the traffics lights
    this.Invalidate(new Rectangle(10, 10, 50, 150));
    //request an update
    this.Update();
    }
    }
    }

  • 相关阅读:
    网易前端规范
    为什么很多网页里不直接用script标签引入JS文件,而是通过函数新建script,然后添加属性,再来引入呢?
    jQuery报错:Uncaught ReferenceError: $ is not defined
    PHP获得网页源码
    JAVA获取网页源码
    ctci(1)
    Hanoi
    计算多选框打勾的数目
    ThreadLocalClient小应用
    ajax动态刷新下拉框
  • 原文地址:https://www.cnblogs.com/ttssrs/p/2396526.html
Copyright © 2011-2022 走看看