Using system;
Using system. diagnostics;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. text;
Using system. Windows. forms;
Using bitmaptest. properties;
Namespace bitmaptest
{
Public partial class form1: Form
{
Public form1 ()
{
Initializecomponent ();
}
Bitmap mybitmap;
Int cmd = 0;
Private void form1_load (Object sender, eventargs E)
{
Picturebox1.image = resources. bfq0002;
Mybitmap = (Bitmap) picturebox1.image;
}
/// <Summary>
/// Color (MOVE)
/// </Summary>
Private void picturebox#mousemove (Object sender, mouseeventargs E)
{
Int mousex = E. X;
Int Mousey = E. Y;
Txtpoint. Text = "(" + mousex + "," + Mousey + ")";
If (rbtmutil. Checked)
{
// Color
Try
{
Color pixelcolor = mybitmap. getpixel (mousex, Mousey );
Colorbox. backcolor = pixelcolor;
Txtcolorvalue. Text = system. Drawing. colortranslator. tohtml (pixelcolor );
}
Catch
{}
}
// Command
Switch (CMD)
{
Case 1: // draw a line
Solidbrush pixelbrush = new solidbrush (color. Red );
Graphics G = graphics. fromimage (mybitmap );
G. fillrectangle (pixelbrush, mousex, Mousey, 2, 2 );
Picturebox1.image = mybitmap;
Break;
Case 2:
Break;
Default:
Break;
}
}
/// <Summary>
/// Paint brush
/// </Summary>
Private void btnpen#click (Object sender, eventargs E)
{
If (cmd = 1)
{
Cmd = 0;
Btnpen1.image = resources.png _05252;
This. tooltip1.settooltip (this. btnpen1, "click to use paint brush ");
}
Else
{
Cmd = 1;
Btnpen1.image = resources.png _05253;
This. tooltip1.settooltip (this. btnpen1, "click to disable the paint brush ");
}
}
/// <Summary>
/// Restore
/// </Summary>
Private void button#click (Object sender, eventargs E)
{
Picturebox1.image = resources. bfq0002;
Mybitmap = (Bitmap) picturebox1.image;
}
/// <Summary>
/// Select the mouse color (click)
/// </Summary>
Private void picturebox#mousedown (Object sender, mouseeventargs E)
{
// Color
Try
{
Color pixelcolor = mybitmap. getpixel (E. X, E. y );
Colorbox. backcolor = pixelcolor;
Txtcolorvalue. Text = system. Drawing. colortranslator. tohtml (pixelcolor );
}
Catch
{}
}
}
}
By: http://www.cnblogs.com/tuyile006/archive/2008/03/07/1094359.html