here you go:
using System;
using System.Drawing;
using System.Windows.Forms;
namespace StylusMove
{
/// <summary>
/// shows how to move a bmp around using the pointing device with no
flicker
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private int m_xPix, m_yPix;
private int m_dxPixHit, m_dyPixHit;
private bool m_fCapt;
private Bitmap m_bmp;
/// <summary>
/// create a default bmp to move around
/// </summary>
public Form1()
{
m_bmp = new Bitmap(this.ClientSize.Width*2,
this.ClientSize.Height*2);
Graphics g = Graphics.FromImage(m_bmp);
g.FillRectangle(new SolidBrush(Color.Purple), 0, 0,
m_bmp.Width, m_bmp.Height);
g.DrawEllipse(new Pen(Color.Yellow),
this.ClientSize.Width / 2,
this.ClientSize.Height /2,
this.ClientSize.Width,
this.ClientSize.Height);
g.Dispose();
InitializeComponent();
}
/// <summary>
/// overriding OnPaintBackground to do nothing prevents flicker!
/// </summary>
/// <param name="paintg"></param>
protected override void OnPaintBackground(PaintEventArgs paintg)
{
}
protected override void OnPaint(PaintEventArgs paintg)
{
Bitmap bmp;
Graphics gx;
int x, y;
Region rgn;
gx = paintg.Graphics;
bmp = m_bmp;
x = m_xPix;
y = m_yPix;
gx.DrawImage(bmp, x, y);
rgn = new Region(this.ClientRectangle);
rgn.Exclude(new Rectangle(x, y, bmp.Width, bmp.Height));
gx.FillRegion(new SolidBrush(Color.White), rgn);
rgn.Dispose();
}
/// <summary>
/// when someone taps and drags around, capture the mouse (to
/// keep getting mouseMove msgs). Remember the original tap
location
/// </summary>
/// <param name="mouseg"></param>
protected override void OnMouseDown(MouseEventArgs mouseg)
{
m_fCapt = true;
m_dxPixHit = mouseg.X - m_xPix;
m_dyPixHit = mouseg.Y - m_yPix;
}
/// <summary>
/// release the mouse capture when the stylus is picked up
/// </summary>
/// <param name="mouseg"></param>
protected override void OnMouseUp(MouseEventArgs mouseg)
{
m_fCapt = false;
}
/// <summary>
/// as the mouse is moving, update the position and cause a repaint
/// </summary>
/// <param name="mouseg"></param>
protected override void OnMouseMove(MouseEventArgs mouseg)
{
if (m_fCapt)
{
m_xPix = mouseg.X - m_dxPixHit;
m_yPix = mouseg.Y - m_dyPixHit;
this.Invalidate();
}
}
/// <summary>
/// exit the test app when someone presses a key
/// </summary>
/// <param name="keyg"></param>
protected override void OnKeyDown( KeyEventArgs keyg )
{
this.Close();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Text = "Form1";
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
{
Application.Run(new Form1());
}
}
}
NETCF Beta FAQ's --
http://www.gotdotnet.com/team/netcf/FAQ.aspx
This posting is provided "AS IS" with no warranties, and confers no rights.