I am not able to get an xbox one controller to connect while running in winforms. All am not trying to create a game so I dont need the graphics just the input of the controller. Below is the winform application form1 that is not able to connect:
`
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace XNAInWinformDelete
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
Vector2 bSDL = GamePad.GetState(PlayerIndex.One).ThumbSticks.Left;
xyValLbl.Text = bSDL.X.ToString() + ":" + bSDL.Y.ToString();
xyValLbl.BackColor = GamePad.GetState(PlayerIndex.One).IsConnected ? System.Drawing.Color.Transparent : System.Drawing.Color.Salmon;
}
}
}
`
The code above compiles however it is not able to connect like the monogame version as implemented below.
I have been able to effectively communicate with an xbox one controller using the following code (in a monoGame using “Windows Desktop application”):
`
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
namespace Png
{
public class Game1 : Game
{
private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
public Game1()
{
_graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
IsMouseVisible = true;
}
protected override void Initialize()
{
// TODO: Add your initialization logic here
base.Initialize();
}
protected override void LoadContent()
{
_spriteBatch = new SpriteBatch(GraphicsDevice);
// TODO: use this.Content to load your game content here
}
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
// TODO: Add your update logic here
ButtonState bS = GamePad.GetState(PlayerIndex.One).Buttons.A;
int here = 123;
if (bS == ButtonState.Pressed)
here += 1;
Vector2 bSDL = GamePad.GetState(PlayerIndex.One).ThumbSticks.Left;
if(GamePad.GetState(PlayerIndex.One).IsConnected)
Console.Write(bSDL.X.ToString());
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
// TODO: Add your drawing code here
base.Draw(gameTime);
}
}
}
`
Maybe I am missing a reference or initialization procedure. Any direction would be greatly appreciated.