当前位置:编程学习 > C#/ASP.NET >>

在winform中利用GDI画三角形并且移动位置的问题

题目要求是这样的,在C#的winform窗口绘制一个三角形(等边),这个三角形最初位置是左上角。然后缓慢向右下角移动,在移动过程成三角形自身也在旋转。并且每次窗口改变大小时,这个三角形都会重新回到左上角,再重复移动和旋转的动作

请各位前辈给个思路啊,我不知道该怎么写 --------------------编程问答-------------------- 学习... --------------------编程问答-------------------- 求教求教求教!!!!!!! --------------------编程问答-------------------- 1.DrawRect
2.timer
3.formsizechange
4.TranslateTransform --------------------编程问答-------------------- 一个简单写的,效果自己调整

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

namespace WindowsApplication1
{
    public partial class Form2 : Form
    {
        private Rectangle rect = new Rectangle(0,0,100,100);
        private Point[] ps = new Point[3];
        private float rotate=0;
        public Form2()
        {
            InitializeComponent();
            SetRect(0,0);
        }

        private void Form2_Paint(object sender, PaintEventArgs e)
        {
            DrawTriangle(e.Graphics);
            //e.Graphics.DrawRectangle(Pens.Blue, this.rect);
        }

        private void DrawTriangle(Graphics g)
        {
            g.TranslateTransform(rect.X, 0);
            g.RotateTransform(rotate);
            g.FillPolygon(new SolidBrush(Color.Red), ps);
        }
        private void SetRect(int x,int y)
        {
            rect.X = rect.X + x;
            rect.Y = rect.Y + y;
            rect.Width = 100;
            rect.Height = 100;
            ps[0].X = rect.X;
            ps[0].Y = rect.Bottom;
            ps[1].X = rect.X + rect.Width / 2;
            ps[1].Y = rect.Top;
            ps[2].X = rect.Right;
            ps[2].Y = rect.Bottom;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            rotate += 5f;
            SetRect(10, 10);
            this.Invalidate();
        }
    }
}
--------------------编程问答--------------------
引用 4 楼 bdmh 的回复:
一个简单写的,效果自己调整
C# code

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

namespac……
可以试试 --------------------编程问答--------------------
引用 4 楼 bdmh 的回复:
一个简单写的,效果自己调整

C# code

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


谢谢,我试试哈 --------------------编程问答-------------------- 顶一个。 学习中 --------------------编程问答-------------------- MARK
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,