嘿,我是 C# 图形编程的新手。我需要知道如何在我的窗口窗体中沿角度方向移动椭圆。我已经使用我的代码成功地将我的椭圆移动到默认方向。
我的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Paddle_Test
{
public partial class Form1 : Form
{
Rectangle rec;
int wLoc=0;
int hLoc=0;
int dx=3;
int dy=3;
public Form1()
{
InitializeComponent();
rec = new Rectangle(wLoc,hLoc , 100, 10);
}
private void Form1_Load(object sender, EventArgs e)
{
this.Refresh();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.SmoothingMode = SmoothingMode.AntiAlias;
g.FillEllipse(new SolidBrush(Color.Blue), rec);
}
private void timer_Tick(object sender, EventArgs e)
{
//moving inside my timer
rec.X += dx;
rec.Y += dy;
}
}
}
简而言之,我的椭圆只是沿对角线移动!所以简单来说问题是我是否可以像 30' 或 80' 或指定角度那样移动它!