flicker free image movements without scrollbars?

B

Brandi

Hello,
I'm a newbie in C#. I know nothing about MFC, thus I've decided to
write my application in C# (with MS Visual C# .NET).
I will write a litte photo-modification application for my PocketPC
(2002). First of all I load an Image, captured with a camera-module.
This image is probably bigger than my litte screen. I won't have
scrollbars to move the image. Instead I'll use the Pen to move the
image around. But how I've to realize this? It should be flicker free
of course!
Have I to use a Panel for my image, to do so?
I've no idea!

I look forward to hearing from YOU.

Brandi
 
M

Mark Reddick

I'm not sure if there is a better way, but I think you could use a panel.
I've used panels to make scrollable forms and for that purpose they worked
well. I used scrollbars to move the form but I image you do it with the pen
too. Size a panel to the size of your image. Then, either draw the image
directly onto the panel (override onPaint - not sure if possible with Panel)
or draw it on an image control that is on the panel and size it to the size
of the image also. Then, you just need to capture the pen movement (not sure
how, I haven't don't that yet myself - I used scrollbars) and adjust the
location of the panel as the pen is moved.

- Mark
 
M

MichaelLipp[MS]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top