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

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

请各位前辈给个思路啊,我不知道该怎么写
...全文
293 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
jhdxhj 2011-09-27
  • 打赏
  • 举报
回复
MARK
刘星宏 2011-09-27
  • 打赏
  • 举报
回复
顶一个。 学习中
ljp12008 2011-06-01
  • 打赏
  • 举报
回复
[Quote=引用 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;
……
[/Quote]

谢谢,我试试哈
xuexiaodong2009 2011-06-01
  • 打赏
  • 举报
回复
[Quote=引用 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……
[/Quote]可以试试
bdmh 2011-06-01
  • 打赏
  • 举报
回复
一个简单写的,效果自己调整

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();
}
}
}
mjlmirror27 2011-06-01
  • 打赏
  • 举报
回复
1.DrawRect
2.timer
3.formsizechange
4.TranslateTransform
ljp12008 2011-06-01
  • 打赏
  • 举报
回复
求教求教求教!!!!!!!

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧