基本信息
源码名称:C# 通过代码 绘图(小乌龟) 示例源码
源码大小:0.05M
文件格式:.rar
开发语言:C#
更新时间:2018-01-06
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍

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;

namespace photoForm
{
    public partial class Form1 : Form
    {
        Graphics g;
        Brush brush;
        Brush brush1;
        Brush brush2;
        Brush brush3;
        Pen pen;

        int offsetx = 200, offsety = 100;
        int offsetx1 = 200, offsety1 = 100;

        int leg = 5;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {


            brush = new SolidBrush(Color.Green);
            brush1 = new SolidBrush(Color.Gold);
            brush2 = new SolidBrush(Color.Blue);
            brush3 = new SolidBrush(Color.Red);

            pen = new Pen(Color.Red, 3);

            g = this.CreateGraphics();

        }

        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            leg = -leg;
            int legup = leg;
            int legdown = -leg;
            g.FillEllipse(brush1, offsetx 140   legdown, offsety 85,5,5);
            g.FillEllipse(brush1, offsetx 145 legdown, offsety 85, 5, 5);
            g.FillEllipse(brush2, offsetx1 0 legdown, offsety1 30, 700, 400);
            g.FillEllipse(brush3, offsetx 100, offsety 100, 100, 100);
            g.FillEllipse(brush, offsetx 100 legdown, offsety 100, 20, 20);
            g.FillEllipse(brush, offsetx 100 legup, offsety 180, 20, 20);
            g.FillEllipse(brush, offsetx 180 legup, offsety 100, 20, 20);
            g.FillEllipse(brush, offsetx 180 legdown, offsety 180, 20, 20);
            g.DrawClosedCurve(pen, new Point[] { new Point(offsetx 130, offsety 100), new Point(offsetx 170, offsety 100), new Point(offsetx 150, offsety 70) });
            g.DrawCurve(pen, new Point[] { new Point(offsetx 140, offsety 200), new Point(offsetx 160, offsety 200), new Point(offsetx 150 leg*4, offsety 230), new Point(offsetx 140, offsety 200) });
            
           
  
            
        }

        private void Form1_Click(object sender, EventArgs e)
        {
            this.Invalidate();
            offsetx1 = 0; offsety1 = 0;
        
            offsetx = 5; offsety = 2;
        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            this.Invalidate();
            //e.KeyCode==

            switch (e.KeyCode)
            {
                case Keys.A:
                    offsetx -= 5; 
                    break;

                case Keys.D:
                    offsetx = 5;
                    break;
                case Keys.S:
                    offsety -= 5;
                    break;
                case Keys.W:
                    offsety = 5;
                    break;


            }

        }
    }
}