Rubber band

xiaoxiao2021-03-30  204

Rubber band

See: "10 basic skills of GDI programming"

Using system;

Using system.drawing;

Using system.collections;

Using system.componentmodel;

Using system.windows.forms;

Using system.Runtime.InteropServices;

Namespace gdiplus

{

///

/// Form5 μäõªõªªªμã ÷ ÷ ¡¡ £

///

Public Class Form5: System.Windows.Forms.form

{

///

// ± øðè μμè1/1/1/1æ ÷ ± Äá¿ ¡ £

///

Private system.componentmodel.Container Components = NULL;

Public Form5 ()

{

//

// windows' ° åèè1/4ææ ÷ ö§3öëù ± øðè μä

//

InitializationComponent ();

//

// Todo: ôú initializecomponent μ μ óãóíí¼/4 ó躹¹¹¹¹¹¹¹o ¯êý'âëë

//

}

///

/// çåàíëùóóõõôô¹¹¹¹ãμäõõ''''''''''¡ £

///

Protected Override Void Dispose (Bool Disposing)

{

IF (Disposing)

{

IF (Components! = NULL)

{

Components.dispose ();

}

}

Base.dispose (Disposing);

}

#region windows' ° åéè 4ææ ÷ éú3éμä'úâë

///

/// éè1/4ææ ÷ ö§3öùùðèμä · 1/2 · ¨ - 2 »ªªª¹¹¹''ë ± (à4æ ÷ þþ þä

/// 'ë · 1/2 · ¨μäúèý¡¡ £

///

Private vidinitiRizeComponent ()

{

//

// form5

//

THIS.AUTOSCALEBASESIZE = New System.drawing.size (6, 14);

THIS.CLIENTSIZE = New System.drawing.size (292, 266);

THIS.NAME = "Form5";

THIS.TEXT = "FORM5";

THISLOAD = New System.EventHandler (this.form5_load);

}

#ndregion

Private Void Form5_Load (Object Sender, System.Eventargs E)

{

}

[DLLIMPORT ("gdi32.dll")]]]]]]

Private Static Extern Bool Setrop2 (INTPTR HDC, INT NDRAWMODE);

[DLLIMPORT ("gdi32.dll")]]]]]]

Private Static Extern Bool Rectangle (INTPTR HDC, INT X1, INT Y1, INT X2, INT Y2);

Private int m_startx, m_starty;

Private int m_endx, m_endy;

PRIVATE INT M_STEP = 0;

Protected Override Void OnMouseDown (MouseEventArgs E) {

Graphics g = this.creategraphics ();

INTPTR HDC = g.getHDC ();

M_STEP = 1;

Setrop2 (HDC, 10);

IF (m_step == 1)

{

THIS.M_STARTX = E.x;

THIS.M_STARTY = E.Y;

THIS.M_ENDX = E.x;

THIS.M_ENDY = E.Y;

}

Else IF (this.m_step == 2)

{

Rectangle (HDC, this.m_startx, this.m_starty, E.x, E.Y);

Rectangle (HDC, this.m_startx, this.m_starty, E.x, E.Y);

THIS.M_STEP = 0;

}

G.releaseHDC (HDC);

//base.onmousedown (e);

}

Protected Override Void OnmouseMove (MouseEventArgs E)

{

Graphics g = this.creategraphics ();

INT prex, prey;

IF (this.m_step == 1)

{

INTPTR HDC = g.getHDC ();

Prex = this.m_endx;

PREY = this.m_endy;

Setrop2 (HDC, 10);

Rectangle (HDC, this.m_startx, this.m_starty, prex, prey);

Rectangle (HDC, this.m_startx, this.m_starty, E.x, E.Y);

THIS.M_ENDX = E.x;

THIS.M_ENDY = E.Y;

G.releaseHDC (HDC);

}

//base.onmousemove (e);

}

Protected Override Void Onpaint (Painteventargs E)

{

Graphics g = E.Graphics;

g.fillRectangle (Brushes.White, this.clientRectangle);

//base.onpaint (e);

}

}

}

See: "10 basic skills of GDI programming"

转载请注明原文地址:https://www.9cbs.com/read-130484.html

New Post(0)