2
Answers

Mouse and Keyboard input in a Window Application?

J Elasigue

J Elasigue

16y
5k
1

Hi, I'm trying to figure out how to get, and manipulate mouse clicks and keystrokes within a Windows Applet in order to paint something on a canvas. This is what I have so far:

using System;

using System.Windows.Forms;

using System.Drawing;

namespace WindowsApplication1

{

   public class Program : Form1

  {

      public Program()

      {

         this.Paint += new PaintEventHandler (f1_Paint);

      }

      private void f1_Paint(object sender, PaintEventArgs e)

      {

         Graphics g = e.Graphics;

         SolidBrush Back = new SolidBrush(Color.LightYellow);

         g.FillRectangle(Back, 0, 0, 350, 550);

      }

      static void Main()

      {

         Application.Run(new Program());

      }

   }

}

 

This creates a default background of light yellow with the defined borders. What I'm trying to find is:

1) How to set the form size to a defined state bigger than the background, because at the moment I'm clicking and dragging things around to make it the size I'd like it to be.

2) How to read a mouseclick and mouseheld event so that (for now) it draws a black brush type based on the x and y coordinates that I obtain from the click.

I also intend to use this base background as a sort of set border, where I'll have a predrawn object circle, where if arrow keys are pressed, it will move the circle around.

I'm also using C# Express 2005 Edition, and have very little experience programming. Thank you in advance for any help.

Answers (2)
Next Recommended Forum