知识大全 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

相关参考

知识大全 C# GDI+编程之基础篇

C#GDI+编程之基础篇  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  一关于GDI+  从本质

知识大全 C# GDI+绘图高级编程

C#GDI+绘图高级编程  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  一般来说Windows的

知识大全 C#解决猴子吃桃子的问题

C#解决猴子吃桃子的问题!  以下文字资料是由(历史新知网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  猴子摘了一堆桃子第一天吃一半觉

知识大全 VS2005(c#)项目调试问题解决方案集锦

VS2005(c#)项目调试问题解决方案集锦  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!检测到有

知识大全 如何在作图区域接受键盘输入

      一个可行的办法是利用KeyListener监测键盘活动当检测到键盘活动的时候获得相  对应的字符并显示到作图区域合适的位置为了达到这个目的我们需要定义自己的  keyPressed()事件

安德鲁斯中数轨道作图方法

安德鲁斯中数轨道作图方法1、需要画出三个点,方可做出这一系列直线。而所画出的三个点,均处在所要预测的上升(或下降)行情起点的左侧。2、在所要预测的上升(或下降)行情起点的左侧,先选择一个典型的高点(或

菲波纳奇时间周期的作图方法

菲波纳奇时间周期的作图方法在提供有该指标的股票软件中,可通过以下方法进行作图:1、先选择行情波动中一明显的高点或低点,回车确认。2、再移动光标,选择第一个波动的高点或低点,选定后回车。3、有起点到任意

知识大全 VC++.NET中使用GDI+创建特效字体

VC++.NET中使用GDI+创建特效字体  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!来自于微软

知识大全 .Net程序开发中较为隐蔽的GDI泄露探析收藏

.Net程序开发中较为隐蔽的GDI泄露探析收藏  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  最

知识大全 .Net程序开发中一个较为隐蔽的GDI泄露探析收藏

.Net程序开发中一个较为隐蔽的GDI泄露探析收藏  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!