国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

C#中用"橡皮條"法繪圖和重繪

2024-07-21 02:23:09
字體:
來源:轉載
供稿:網友
,歡迎訪問網頁設計愛好者web開發。前些日子在論壇上發了個帖子,100分尋求“橡皮條”法繪圖的代碼。效果不是很好,于是自己參照網友給的代碼重新寫了一個,解決了繪圖與重繪的問題。由于只寫了部分,所以功能有限,同時可能算法不是很好,希望大家指點??!窗體中僅包含一個pictruebox1,先將代碼付諸于下:
using system;
using system.drawing;
using system.collections;
using system.componentmodel;
using system.windows.forms;
using system.data;
using system.drawing.drawing2d;

namespace gdi_練習
{
/// <summary>
/// form1 的摘要說明。
/// </summary>
public class form1 : system.windows.forms.form
{
public system.windows.forms.picturebox picturebox1;
private point p1 = point.empty, p2 = point.empty;
private bool ismousedown = false, ismouseup = false;

arraylist addarray = new arraylist();
public struct sharptype
{
public string type;
public point p1, p2;
public color forecolor, backcolor;
public brush brush;
public sharptype( string type, point p1, point p2, color forecolor, color backcolor, brush brush )
{
this.type = type;
this.p1 = p1;
this.p2 = p2;
this.forecolor = forecolor;
this.backcolor = backcolor;
this.brush = brush;
}

}

/// <summary>
/// 必需的設計器變量。
/// </summary>
private system.componentmodel.container components = null;

public form1()
{
//
// windows 窗體設計器支持所必需的
//
initializecomponent();

//
// todo: 在 initializecomponent 調用后添加任何構造函數代碼
//
}

/// <summary>
/// 清理所有正在使用的資源。
/// </summary>
protected override void dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.dispose();
}
}
base.dispose( disposing );
}

#region windows 窗體設計器生成的代碼
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內容。
/// </summary>
private void initializecomponent()
{
this.picturebox1 = new system.windows.forms.picturebox();
this.suspendlayout();
//
// picturebox1
//
this.picturebox1.backcolor = system.drawing.color.white;
this.picturebox1.dock = system.windows.forms.dockstyle.fill;
this.picturebox1.location = new system.drawing.point(0, 0);
this.picturebox1.name = "picturebox1";
this.picturebox1.size = new system.drawing.size(432, 397);
this.picturebox1.tabindex = 0;
this.picturebox1.tabstop = false;
this.picturebox1.paint += new system.windows.forms.painteventhandler(this.picturebox1_paint);
this.picturebox1.mouseup += new system.windows.forms.mouseeventhandler(this.picturebox1_mouseup);
this.picturebox1.mousemove += new system.windows.forms.mouseeventhandler(this.picturebox1_mousemove);
this.picturebox1.mousedown += new system.windows.forms.mouseeventhandler(this.picturebox1_mousedown);
//
// form1
//
this.autoscalebasesize = new system.drawing.size(6, 14);
this.clientsize = new system.drawing.size(432, 397);
this.controls.add(this.picturebox1);
this.name = "form1";
this.text = "form1";
this.resumelayout(false);

}
#endregion

/// <summary>
/// 應用程序的主入口點。
/// </summary>
[stathread]
static void main()
{
application.run(new form1());
}

private void picturebox1_mousedown(object sender, system.windows.forms.mouseeventargs e)
{
if( ! ismouseup )
{
this.ismousedown = true;
this.p1 = new point( e.x, e.y );
}

}

private void picturebox1_mousemove(object sender, system.windows.forms.mouseeventargs e)
{
graphics g = this.picturebox1.creategraphics();
if( ismousedown && p2 != point.empty )
g.drawellipse( pens.white, p1.x, p1.y, math.abs( p1.x - p2.x ), math.abs( p1.y - p2.y ) );


if( ismousedown && ! ismouseup )
{
p2 = new point( e.x, e.y );
g.drawellipse( pens.black, p1.x, p1.y, math.abs( p1.x - p2.x ), math.abs( p1.y - p2.y ) );

}
foreach( sharptype type in addarray )
{
g.drawellipse( pens.black, type.p1.x, type.p1.y, math.abs( type.p1.x - type.p2.x ), math.abs( type.p1.y - type.p2.y ) );

}
g.dispose();
}

private void picturebox1_mouseup(object sender, system.windows.forms.mouseeventargs e)
{
this.ismousedown = false;
p2 = new point( e.x, e.y );
graphics g = this.picturebox1.creategraphics();
g.drawellipse( pens.black, p1.x, p1.y, math.abs( p1.x - p2.x ), math.abs( p1.y - p2.y ) );
addarray.add( new sharptype( "a", p1, p2, color.black, color.empty, brushes.black ) );
p1 = point.empty;
p2 = point.empty;
g.dispose();

}

private void picturebox1_paint(object sender, system.windows.forms.painteventargs e)
{
foreach( sharptype type in addarray )
{
e.graphics.drawellipse( pens.black, type.p1.x, type.p1.y, math.abs( type.p1.x - type.p2.x ), math.abs( type.p1.y - type.p2.y ) );

}
}



}
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 大姚县| 汪清县| 巴马| 新津县| 普兰店市| 新邵县| 阳春市| 彭泽县| 错那县| 浙江省| 天祝| 会理县| 新晃| 和田县| 武安市| 沧州市| 拜泉县| 榆树市| 隆昌县| 勃利县| 饶阳县| 广河县| 衡东县| 安新县| 涪陵区| 洪湖市| 临武县| 库伦旗| 建水县| 屏东市| 乌拉特中旗| 赣州市| 津市市| 抚松县| 牡丹江市| 桓仁| 云霄县| 稻城县| 黎平县| 安康市| 清河县|