知识大全 C#中利用GDI作图解决异或问题

Posted 文字

篇首语:路曼曼其修远兮,吾将上下而求索。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 C#中利用GDI作图解决异或问题相关的知识,希望对你有一定的参考价值。

C#中利用GDI作图解决异或问题  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!

  using System;

  using System Drawing;

  using System Collections;

  using System ComponentModel;

  using System Windows Forms;

  using System Data;

  using System Runtime InteropServices;

  namespace RubberBands

  

  /// <summary>

  /// Summary description for Form

  /// </summary>

  public class RubberBandForm : System Windows Forms Form

  

  /// API Declarations

  private struct POINTAPI

  public int x;

  public int y;

  

  [DllImport( gdi DLL )]

  private static extern Int SetROP (IntPtr hDC

  int nDrawMode);

  [DllImport( gdi dll )]

  private static extern bool MoveToEx(IntPtr hDC

  int x

  int y

  POINTAPI lpPoint);

  [DllImport( gdi dll )]

  private static extern bool LineTo(IntPtr hDC

  int x

  int y);

  [DllImport( gdi dll )]

  private static extern IntPtr CreatePen(int nPenStyle

  int nWidth

  int crColor);

  [DllImport( gdi dll )]

  private static extern IntPtr SelectObject(IntPtr hDC

  IntPtr hObject);

  [DllImport( gdi dll )]

  private static extern bool DeleteObject(IntPtr hObject);

  private const int R _NOT = ;

  private const int R _XORPEN = ;

  private const int PS_DOT = ;

  /// <summary>

  /// Required designer variable

  /// </summary>

  private System ComponentModel Container ponents = null;

  private System Drawing Graphics m_oDrawingSurface;

  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 CreateGraphics();

  

  /// <summary>

  /// Clean up any resources being used

  /// </summary>

  protected override void Dispose( bool disposing )

  

  if( disposing )

  

  if (ponents != null)

  

  ponents Dispose();

  

  

  base Dispose( disposing );

  

  protected override void OnMouseDown(MouseEventArgs e)

  // Check whether the left mouse button

  // has generated the associated event

  if (e Button == MouseButtons Left)

  // Store the starting point for your rubber band line

  m_ptsStart x = e X;

  m_ptsStart y = e Y;

  // Store the previous end point for your rubber band line

  m_ptsPrevious = m_ptsStart;

  

  base OnMouseDown (e);

  

  protected override void OnMouseMove(MouseEventArgs e)

  // Check if the left mouse button is pressed

  if( e Button == MouseButtons Left)

  // Declare local variables

  // handle to an appropriate device context obtained

  // from m_oDrawingSurface

  IntPtr hDC;

  // previous mix mode; returned from SetROP

  Int Mix ;

  // temporary variables used for rubber banding logic

  POINTAPI ptsCurrent ;

  POINTAPI ptsOld = new POINTAPI();

  // determines whether MoveToEx and LineTo calls are successful

  Boolean Success;

  // Store the current end point of your rubber band line

  ptsCurrent x = e X;

  ptsCurrent y = e Y;

  // Perform the requisite graphical operations

  // Obtain a handle to an appropriate device context

  hDC = m_oDrawingSurface GetHdc();

  // Set the raster mode to invert the screen color

  Mix = SetROP (hDC R _NOT);

  // Move to the starting point of the rubber band line

  Success = MoveToEx(hDC m_ptsStart x m_ptsStart y ptsOld);

  // Erase the previous line

  Success = LineTo(hDC m_ptsPrevious x m_ptsPrevious y);

  // Move to the starting point of the rubber band line

  Success = MoveToEx(hDC m_ptsStart x m_ptsStart y ptsOld);

  // Draw the new line

  Success = LineTo(hDC ptsCurrent x ptsCurrent y);

  // Release the obtained handle to a device context

  m_oDrawingSurface ReleaseHdc(hDC);

  // Store the current end point for the next erase operation

  m_ptsPrevious = ptsCurrent;

  

  base OnMouseMove (e);

  

  #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()

  

  //

  // RubberBandForm

  //

  this AutoScaleBaseSize = new System Drawing Size( );

  this BackColor = System Drawing SystemColors Window;

  this ClientSize = new System Drawing Size( );

  this Name = RubberBandForm ;

  this Text = Using Unmanaged APIs ;

  

  #endregion

  /// <summary>

  /// The main entry point for the application

  /// </summary>

  [STAThread]

  static void Main()

  

  Application Run(new RubberBandForm());

  

  

cha138/Article/program/ASP/201311/21870

相关参考