我想画一个十字架到一个图片框。在下一步中,我想根据我的数据移动十字架。 这是Thumbsticks的位置。我希望它看起来类似于下图。
这是我的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SlimDX;
using SlimDX.XInput;
namespace Controller_Test
{
public partial class Form1 : Form
{
GamepadState Controller = new GamepadState(UserIndex.One);
Graphics drawArea;
public Form1()
{
InitializeComponent();
timer1.Enabled = true;
drawArea = pictureBox1.CreateGraphics();
}
private void timer1_Tick(object sender, EventArgs e)
{
Controller.Update();
var LeftStick = Controller.LeftStick;
float LeftStickX = LeftStick.Position.X;
float LeftStickY = LeftStick.Position.Y;
Pen blackPen = new Pen(Color.Black);
// horizontal Line
drawArea.DrawLine(blackPen, x1+LeftStickX, y1-LeftStickY, x2+LeftStickX, y2-LeftStickY);
// vertical Line
drawArea.DrawLine(blackPen, x1+LeftStickX, y1-LeftStickY, x2+LeftStickX, y2-LeftStickY);
}
}
public class GamepadState
{Get Postiton......}
}
我现在的问题是,如果我每次绘制一个新的十字架时都会移动一个新的十字架,但旧的十字架仍在 Picturebox如下图所示。如果我使用pictureBox1.Invalidate():/ pictureBox1.Refresh(); Funtcion 十字架变得不可见,不再显示。计时器的间隔为1。
为了让代码工作,我可以改变什么?