Need Big Help C# graphics and mouse events

creating a figure that moves when cliked on the mosue

Page 1 of 1

1 Replies - 2521 Views - Last Post: 11 November 2010 - 11:42 PM Rate Topic: -----

#1 oarayax   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 15-August 10

Need Big Help C# graphics and mouse events

Posted 11 November 2010 - 01:31 PM

I`ve been trying to make this rectangle in the windows form so that when i clik the button rectangle, a rectangle is draw and when with my mouse i click in that rectangle the rectangle is move to whereever my mouse moves, kind of like drawing a rectangle and moving it around with my mouse..
my code so far( this is my form.cs :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace cuadrado
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }
        bool paint = false;
        private void Form1_Load(object sender, EventArgs e)
        {


        }

        private void button1_Click(object sender, EventArgs e)
        {


        }

        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {

            paint = true;
            InitializeComponent();
            Graphics dc = this.CreateGraphics();
            this.Show();
            if (paint == true)
            {
                // se manda llamar el cuadrado de la clase cuadrado
                // y se dibuja en las pocisiones e.x , e.y 
                Pen BluePen = new Pen(Color.Blue, 3);
                dc.DrawRectangle(BluePen, e.X, e.Y, 50, 50);
            }

        }
        private void panel1_MouseUp(object sender, MouseEventArgs e)
        {
            paint = false;
        }
    }
}



Is This A Good Question/Topic? 0
  • +

Replies To: Need Big Help C# graphics and mouse events

#2 mavarazo   User is offline

  • D.I.C Head
  • member icon

Reputation: 37
  • View blog
  • Posts: 182
  • Joined: 25-October 10

Re: Need Big Help C# graphics and mouse events

Posted 11 November 2010 - 11:42 PM

And your question is?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1