自绘界面汉诺塔

这个是用Windwow From Control Library 的工程。添加了一个控件为Panel 的控件,并未这个控件添加了paint的事件。

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

namespace _20160423汉诺塔
{
    public partial class UserControl1: UserControl
    {
        private Pen myPen = new Pen(Color.Green, 10);
        private Pen myPen1 = new Pen(Color.Red);
        private SolidBrush mySolidBrush = new SolidBrush(Color.Green);
        private const int recganleHeight = 20;

        //起始点
        private int StartX = 4;
        private int StartY = 20;

        private int ColNode = 0;
        private int RowNode = 0;

        private float radio = 1.1f;//缩小比列(仅限与宽度)
        public UserControl1()
        {
            InitializeComponent();
            this.Invalidate();
        }
        private void initSize()
        { 
            //固定他的大小
            this.Width = 688;
            this.Height = 523;
        }

        private void UserControl1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            //初始化数据
            ColNode = this.Width / 3- 20;
            RowNode = this.Height -10;
            
            //画第一个钉子图

            //画横线
            
            Point RowOne1 = new Point(StartX, RowNode);
            Point RowOne2 = new Point(ColNode + StartX, RowNode);
            g.DrawLine(myPen, RowOne1, RowOne2);

            int mid = ColNode / 2 + StartX;
            //画竖线
            Point ColOne1 = new Point(mid, StartY);
            Point ColOne2 = new Point(mid, RowNode);
           g.DrawLine(myPen, ColOne1, ColOne2);


           //画第2s个钉子图

           //画横线
           int x2 = StartX + 30 + ColNode;//第二个图形地点的位置

           RowOne1 = new Point(x2, RowNode);
           RowOne2 = new Point(ColNode + x2, RowNode);
           g.DrawLine(myPen, RowOne1, RowOne2);

           mid = ColNode / 2 + x2;
           //画竖线
           ColOne1 = new Point(mid, StartY);
           ColOne2 = new Point(mid, RowNode);
           g.DrawLine(myPen, ColOne1, ColOne2);


           //画第3个钉子图
           int x3 = x2 + 30 + ColNode;
           RowOne1 = new Point(x3, RowNode);
           RowOne2 = new Point(ColNode + x3, RowNode);
           g.DrawLine(myPen, RowOne1, RowOne2);

           mid = ColNode / 2 + x3;
           //画竖线
           ColOne1 = new Point(mid, StartY);
           ColOne2 = new Point(mid, RowNode);
           g.DrawLine(myPen, ColOne1, ColOne2);



            
            //开始画累积木


           int xPlus = ColNode / 20;

            float rectangleWide = (float)ColNode / radio;
           
            for (int i = 1; i <4 ; i++)
            {

                g.DrawRectangle(myPen1, StartX + xPlus * i, RowNode - recganleHeight *i -6 , rectangleWide, recganleHeight);
                rectangleWide = rectangleWide -26;
            }  
        }
    }
}


先这样把。出来的效果是,代码中有循环在竖线中画矩形。目前的数量为 3 个。



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

代码i小学生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值