Didnt seem to do the trick.
the following is what i have attempted (still flickers) :
-------------------------pong.cs---------------------------------
using System ;
using System.Windows.Forms ;
class Paddle : System.Windows.Forms.UserControl
{
public int oldpos ;
public bool moving ;
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e) ;
e.Graphics.FillRectangle( System.Drawing.Brushes.Green , 0 , 0 ,
Width , Height ) ;
}
/* i would have preferred to do it this way but also flickered.........
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e) ;
p = new System.Drawing.Point(e.X , e.Y) ;
moving = true ;
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e) ;
if (!moving) return ;
Top += e.Y - p.Y ;
p.Y = e.Y ;
}
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e) ;
moving = false ;
}
protected override void OnMouseLeave(EventArgs e)
{
base.OnMouseLeave(e) ;
moving = false ;
}
*/
}
class Pong : System.Windows.Forms.Form
{
const int UpdateTimeMS = 200 ;
Paddle left ;
Paddle right ;
public void OnTimedEvent(object o, System.Timers.ElapsedEventArgs args)
{
}
private void left_MouseDown(object sender ,
System.Windows.Forms.MouseEventArgs e)
{
left.moving = true ;
}
private void left_MouseUp(object sender ,
System.Windows.Forms.MouseEventArgs e)
{
left.moving = false ;
}
private void left_MouseMove(object sender ,
System.Windows.Forms.MouseEventArgs e)
{
if (left.moving)
{
left.Location = new System.Drawing.Point ( left.Location.X ,
left.Location.Y +
e.Y - left.oldpos );
left.oldpos = e.Y ;
}
}
Pong()
{
Text = "Ping Pong" ;
this.Show() ;
left = new Paddle() ;
left.Name = "Left" ;
left.ForeColor = System.Drawing.Color.Red ;
left.Location = new System.Drawing.Point( 20 , Height / 2 - 25 ) ;
left.Size = new System.Drawing.Size( 10 , 50 ) ;
left.MouseUp += new
System.Windows.Forms.MouseEventHandler(left_MouseUp) ;
left.MouseDown += new
System.Windows.Forms.MouseEventHandler(left_MouseDown) ;
left.MouseMove += new
System.Windows.Forms.MouseEventHandler(left_MouseMove) ;
right = new Paddle() ;
right.Name = "Right" ;
right.ForeColor = System.Drawing.Color.Red ;
right.Location = new System.Drawing.Point( Width - 30 , Height / 2 -
25 ) ;
right.Size = new System.Drawing.Size( 10 , 50 ) ;
Controls.Add(left) ;
Controls.Add(right) ;
}
static void Main()
{
Pong game = new Pong() ;
Application.Run( game ) ;
}
}
Bruce Benton said:
Here is some sample code that will accomplish what you asked in C#. It
sounds like you are doing everything except maybe calling the refresh()
method on the button after moving it.
If you want to drag content between control look into the DoDragDrop
method. If you are trying to manage docking behavior then check out the
docking properties on teh contorl object.
// Place this code in the InitializeComponent method
this.button1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.button1_MouseDown);
this.button1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.button1_MouseUp);
this.button1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.button1_MouseMove);
// Place this code wher eyou have your function declarations for the form
class. The MoveFlag variable is a global variable that I declared at the top
of the class