using System;
using System
using System
using System
using System
using System
using System
namespace RubberBands
{
/// <summary>
/// Summary description for Form
/// </summary>
public class RubberBandForm : System
{
/// API Declarations
private struct POINTAPI {
public int x;
public int y;
}
[DllImport(
private static extern Int
int nDrawMode);
[DllImport(
private static extern bool MoveToEx(IntPtr hDC
int x
int y
POINTAPI lpPoint);
[DllImport(
private static extern bool LineTo(IntPtr hDC
int x
int y);
[DllImport(
private static extern IntPtr CreatePen(int nPenStyle
int nWidth
int crColor);
[DllImport(
private static extern IntPtr SelectObject(IntPtr hDC
IntPtr hObject);
[DllImport(
private static extern bool DeleteObject(IntPtr hObject);
private const int R
private const int R
private const int PS_DOT =
/// <summary>
/// Required designer variable
/// </summary>
private System
private System
private POINTAPI m_ptsStart = new POINTAPI();
private POINTAPI m_ptsPrevious;
public RubberBandForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//Add any initialization after the InitializeComponent() call
m_oDrawingSurface = this
}
/// <summary>
/// Clean up any resources being used
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components
}
}
base
}
protected override void OnMouseDown(MouseEventArgs e) {
// Check whether the left mouse button
// has generated the associated event
if (e
// Store the starting point for your rubber
m_ptsStart
m_ptsStart
// Store the previous end point for your rubber
m_ptsPrevious = m_ptsStart;
}
base
}
protected override void OnMouseMove(MouseEventArgs e) {
// Check if the left mouse button is pressed
if( e
// Declare local variables
// handle to an appropriate device context obtained
// from m_oDrawingSurface
IntPtr hDC;
// previous mix mode; returned from SetROP
Int
// temporary variables used for rubber
POINTAPI ptsCurrent
POINTAPI ptsOld = new POINTAPI();
// determines whether MoveToEx and LineTo calls are successful
Boolean Success;
// Store the current end point of your rubber
ptsCurrent
ptsCurrent
// Perform the requisite graphical operations
// Obtain a handle to an appropriate device context
hDC = m_oDrawingSurface
// Set the raster mode to invert the screen color
Mix = SetROP
// Move to the starting point of the rubber
Success = MoveToEx(hDC
// Erase the previous line
Success = LineTo(hDC
// Move to the starting point of the rubber
Success = MoveToEx(hDC
// Draw the new line
Success = LineTo(hDC
// Release the obtained handle to a device context
m_oDrawingSurface
// Store the current end point for the next erase operation
m_ptsPrevious = ptsCurrent;
}
base
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support
/// the contents of this method with the code editor
/// </summary>
private void InitializeComponent()
{
//
// RubberBandForm
//
this
this
this
this
this
}
#endregion
/// <summary>
/// The main entry point for the application
/// </summary>
[STAThread]
static void Main()
{
Application
}
}
}
From:http://tw.wingwit.com/Article/program/ASP/201311/21870.html