仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 608|回复: 8
打印 上一主题 下一主题

[学习教程] ASP.NET网页设计利用C#编写LED款式时钟控件

[复制链接]
精灵巫婆 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-16 22:34:33 | 只看该作者 回帖奖励 |正序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
听03很多师兄说主讲老师杭城方讲课很差就连旁听也没有去了)控件|时钟运转效果:http://blog.csdn.net/images/blog_csdn_net/johnsuna/ClockControl.jpg右下角图片

//--------------------------(如转载,请保存版权信息)-------------------------//
//SevenSegmentClockStyle.cs朱继山a3news(AT)hotmail.com--//
//-----------------------------http://www.brawdraw.com----------------------//
//--------------------未经籍面允许,请勿用于贸易用处---------------------//

usingSystem;
namespaceBrawDraw.Com.PhotoFrame.Net.PublicFunctions.Clock
{
///<summary>
///ClocksStyle.时钟的款式界说
///</summary>
publicenumSevenSegmentClockStyle
{
DateOnly,//只显现日期
TimeOnly,//只显现工夫
DateAndTime//显现日期和工夫
}
}

//--------------------------(如转载,请保存版权信息)-------------------------//
//SevenSegmentClock.cs朱继山a3news(AT)hotmail.com-------//
//-----------------------------http://www.brawdraw.com----------------------//
//--------------------未经籍面允许,请勿用于贸易用处---------------------//
usingSystem;
usingSystem.Drawing;
usingSystem.Drawing.Drawing2D;
usingSystem.Globalization;
usingSystem.Windows.Forms;
usingBrawDraw.Com.PhotoFrame.Net.PublicFunctions;
usingSystem.ComponentModel;
namespaceBrawDraw.Com.PhotoFrame.Net.PublicFunctions.Clock
{
//这是控件的关头代码
publicclassSevenSegmentClock:UserControl
{
DateTime_dateTime;
//默许利用同时绘制日期和工夫
SevenSegmentClockStyle_clockStyle=SevenSegmentClockStyle.DateAndTime;
Color_clockColor=Color.Black;
//是不是绘制暗影(即残影),以摸拟真似的LED时钟
bool_isDrawShadow=true;
Timer_timer=null;
//是不是主动更新工夫
bool_isTimerEnable=false;
Graphicsg=null;
Bitmapm_Bitmap=null;
publicboolIsDrawShadow
{
get{returnthis._isDrawShadow;}
set
{
this._isDrawShadow=value;
this.Invalidate();
}
}
[Browsable(false)]
publicSystem.Windows.Forms.TimerTimer
{
get{returnthis._timer;}
set
{
this._timer=value;
if(_timer!=null)
{
_timer.Tick+=newEventHandler(TimerOnTick);
}
}
}
publicboolIsTimerEnable
{
get{returnthis._isTimerEnable;}
set
{
if(value==true)
{
if(this._timer==null)
{
_timer=newTimer();
_timer.Tick+=newEventHandler(TimerOnTick);
_timer.Interval=1000;
_timer.Enabled=true;
}
}
else
{
if(this._timer!=null)
{
_timer.Enabled=false;
}
}
this._isTimerEnable=value;
}
}
publicvoidStart()
{
this.IsTimerEnable=true;
this.Refresh();
}
publicvoidStop()
{
this.IsTimerEnable=false;
}
publicSystem.DateTimeDateTime
{
get{returnthis._dateTime;}
set{this._dateTime=value;}
}
//LED笔墨的色彩
publicSystem.Drawing.ColorClockColor
{
get{returnthis._clockColor;}
set
{
this._clockColor=value;
this.Invalidate();
}
}
publicSevenSegmentClockStyleSevenSegmentClockStyle
{
get{returnthis._clockStyle;}
set
{
this._clockStyle=value;
this.Invalidate();
}
}
publicSevenSegmentClock()
{
Text="Seven-SegmentClock";
//利用双缓冲,撑持通明绘制
SetStyle(ControlStyles.UserPaint|ControlStyles.DoubleBuffer|ControlStyles.AllPaintingInWmPaint
|ControlStyles.ResizeRedraw|ControlStyles.SupportsTransparentBackColor,true);
this.UpdateStyles();
Init();
_dateTime=DateTime.Now;
}
//初始化
privatevoidInit()
{
m_Bitmap=newBitmap(this.Width,this.Height);
g=Graphics.FromImage(m_Bitmap);
g.CompositingQuality=CompositingQuality.HighQuality;
g.TextRenderingHint=System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;

//g.InterpolationMode=InterpolationMode.HighQualityBicubic;
g.SmoothingMode=SmoothingMode.HighQuality;
//g.TextRenderingHint=System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
}
voidTimerOnTick(objectobj,EventArgsea)
{
DateTimedtNow=DateTime.Now;
dtNow=newDateTime(dtNow.Year,dtNow.Month,dtNow.Day,dtNow.Hour,dtNow.Minute,dtNow.Second);
if(dtNow!=_dateTime)
{
_dateTime=dtNow;
Invalidate();
}
}
protectedoverridevoidOnPaint(PaintEventArgse)
{
m_Bitmap=DrawClock();
Graphicsgg=e.Graphics;
gg.CompositingQuality=CompositingQuality.HighQuality;
gg.DrawImageUnscaled(m_Bitmap,0,0);
//g.Dispose();
}
publicBitmapDrawClock()
{
returnthis.DrawClock(this.ClientRectangle);
}
privatevoidSevenSegmentClock_Resize(objectsender,System.EventArgse)
{
Init();
this.Refresh();
}
privatevoidInitializeComponent()
{
//
//SevenSegmentClock
//
this.Name="SevenSegmentClock";
this.Size=newSystem.Drawing.Size(448,64);
this.Resize+=newSystem.EventHandler(this.SevenSegmentClock_Resize);
}
int_clockStringWidth;
int_clockStringHeight;
publicintClockStringWidth
{
get
{
return_clockStringWidth;
}
}

publicintClockStringHeight
{
get
{
return_clockStringHeight;
}
}
//绘制时钟
publicBitmapDrawClock(RectangledestRect)
{
m_Bitmap=newBitmap(destRect.Width,destRect.Height);
//m_Bitmap=newBitmap(destRect.X+this.Width,destRect.Y+this.Height);
Graphicsgrfx=Graphics.FromImage(m_Bitmap);
//设置画图面板的绘制质量等
grfx.CompositingQuality=CompositingQuality.HighQuality;
grfx.TextRenderingHint=System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
grfx.SmoothingMode=SmoothingMode.HighQuality;
SevenSegmentDisplayssd=newSevenSegmentDisplay(grfx);
ssd.IsDrawShadow=this._isDrawShadow;
GraphiCSStategs=grfx.Save();
grfx.TranslateTransform(destRect.X,destRect.Y);
stringstrTime=string.Empty;
if(this._clockStyle==SevenSegmentClockStyle.TimeOnly)
{
strTime=_dateTime.ToString("T",DateTimeFormatInfo.InvariantInfo);
}
elseif(this._clockStyle==SevenSegmentClockStyle.DateOnly)
{
//设置日期格局
strTime=_dateTime.ToString("yyyy-MM-dd",DateTimeFormatInfo.InvariantInfo);
}
else
{
strTime=_dateTime.ToString("yyyy-MM-dd",DateTimeFormatInfo.InvariantInfo)+""+_dateTime.ToString("T",DateTimeFormatInfo.InvariantInfo);
}
SizeFsizef=ssd.MeasureString(strTime,Font);
floatfScale=Math.Min(destRect.Width/sizef.Width,destRect.Height/sizef.Height);
Fontfont=newFont(Font.FontFamily,fScale*Font.SizeInPoints);
sizef=ssd.MeasureString(strTime,font);
_clockStringWidth=(int)sizef.Width;
_clockStringHeight=(int)sizef.Height;
ssd.DrawString(strTime,font,newSolidBrush(this._clockColor),
(destRect.Width-sizef.Width)/2,
(destRect.Height-sizef.Height)/2);
grfx.Restore(gs);
returnm_Bitmap;
}
}
}

//--------------------------(如转载,请保存版权信息)-------------------------//
//SevenSegmentDisplay.cs2001byCharlesPetzold//
//------------------------改编:朱继山a3news(AT)hotmail.com-----------//
usingSystem;
usingSystem.Drawing;
usingSystem.Windows.Forms;
namespaceBrawDraw.Com.PhotoFrame.Net.PublicFunctions.Clock
{
//字符绘制的算法
classSevenSegmentDisplay
{
Graphicsgrfx;
Brush_brush=Brushes.Black;
bool_isDrawShadow=true;
Color_shadowColor=Color.FromArgb(60,Color.White);
Brush_shadowBrush=null;
//Indicateswhatsegmentsareilluminatedforall10digits
staticbyte[,]bySegment={
{1,1,1,0,1,1,1},//0
{0,0,1,0,0,1,0},//1
{1,0,1,1,1,0,1},//2
{1,0,1,1,0,1,1},//3
{0,1,1,1,0,1,0},//4
{1,1,0,1,0,1,1},//5
{1,1,0,1,1,1,1},//6
{1,0,1,0,0,1,0},//7
{1,1,1,1,1,1,1},//8
{1,1,1,1,0,1,1}//9
};
//Pointsthatdefineeachofthesevensegments
readonlyPoint[][]apt=newPoint[7][];
publicboolIsDrawShadow
{
get{returnthis._isDrawShadow;}
set{this._isDrawShadow=value;}
}
publicSevenSegmentDisplay(Graphicsgrfx)
{
this.grfx=grfx;
//InitializejaggedPointarray.
apt[0]=newPoint[]{
newPoint(3,2),newPoint(39,2),
newPoint(31,10),newPoint(11,10)
};
apt[1]=newPoint[]{
newPoint(2,3),newPoint(10,11),
newPoint(10,31),newPoint(2,35)
};
apt[2]=newPoint[]{
newPoint(40,3),newPoint(40,35),
newPoint(32,31),newPoint(32,11)
};
apt[3]=newPoint[]{
newPoint(3,36),newPoint(11,32),
newPoint(31,32),newPoint(39,36),
newPoint(31,40),newPoint(11,40)
};
apt[4]=newPoint[]{
newPoint(2,37),newPoint(10,41),
newPoint(10,61),newPoint(2,69)
};
apt[5]=newPoint[]{
newPoint(40,37),newPoint(40,69),
newPoint(32,61),newPoint(32,41)
};
apt[6]=newPoint[]{
newPoint(11,62),newPoint(31,62),
newPoint(39,70),newPoint(3,70)
};
}
publicSizeFMeasureString(stringstr,Fontfont)
{
SizeFsizef=newSizeF(0,grfx.DpiX*font.SizeInPoints/72);
for(inti=0;i<str.Length;i++)
{
if(Char.IsDigit(str[i]))
{
sizef.Width+=42*grfx.DpiX*font.SizeInPoints/72/72;
}
elseif(str[i]==-)
{
sizef.Width+=42*grfx.DpiX*font.SizeInPoints/72/72;
}
elseif(str[i]==:)
{
sizef.Width+=20*grfx.DpiX*font.SizeInPoints/72/72;
}
elseif(str[i]==)
{
sizef.Width+=36*grfx.DpiX*font.SizeInPoints/72/72;
}
}
returnsizef;
}
publicvoidDrawString(stringstr,Fontfont,Brushbrush,floatx,floaty)
{
this._brush=brush;
this._shadowBrush=newSolidBrush(Color.FromArgb(40,((SolidBrush)this._brush).Color));
for(inti=0;i<str.Length;i++)
{
if(Char.IsDigit(str[i]))
{
x=Number(str[i]-0,font,brush,x,y);
}
elseif(str[i]==-)
{
x=MinusSign(font,brush,x,y);
}
elseif(str[i]==:)
{
x=Colon(font,brush,x,y);
}
elseif(str[i]==)
{
x=DrawSpace(font,brush,x,y);
}
}
}
privatefloatNumber(intnum,Fontfont,Brushbrush,floatx,floaty)
{
for(inti=0;i<apt.Length;i++)
{
if(_isDrawShadow)
{
Fill(apt[i],font,_shadowBrush,x,y);
}
if(bySegment[num,i]==1)
{
Fill(apt[i],font,brush,x,y);
}
}
returnx+42*grfx.DpiX*font.SizeInPoints/72/72;
}
privatefloatMinusSign(Fontfont,Brushbrush,floatx,floaty)
{
Fill(apt[3],font,brush,x,y);
returnx+42*grfx.DpiX*font.SizeInPoints/72/72;
}
privatefloatDrawSpace(Fontfont,Brushbrush,floatx,floaty)
{
returnx+36*grfx.DpiX*font.SizeInPoints/72/72;
}
privatefloatColon(Fontfont,Brushbrush,floatx,floaty)
{
Point[][]apt=newPoint[2][];
apt[0]=newPoint[]{
newPoint(4,12),newPoint(16,12),
newPoint(16,24),newPoint(4,24)
};
apt[1]=newPoint[]{
newPoint(4,50),newPoint(16,50),
newPoint(16,62),newPoint(4,62)
};
for(inti=0;i<apt.Length;i++)
{
Fill(apt[i],font,brush,x,y);
}
returnx+20*grfx.DpiX*font.SizeInPoints/72/72;
}
privatevoidFill(Point[]apt,Fontfont,Brushbrush,floatx,floaty)
{
PointF[]aptf=newPointF[apt.Length];
for(inti=0;i<apt.Length;i++)
{
aptf[i].X=x+apt[i].X*grfx.DpiX*font.SizeInPoints/72/72;
aptf[i].Y=y+apt[i].Y*grfx.DpiY*font.SizeInPoints/72/72;
}
grfx.FillPolygon(brush,aptf);
}
}
}
兄弟们,想来你们都看过了昨天的比赛了。我现在的痛苦状跟当时应该差不多。希望本版.net老师不吝赐教,为小弟这一批迷途的羊羔指一条阳光之道!您也知道:学习技术如果只有一个人摸索,那是一件多么痛苦的事情!还有,如果万辛能得名师或长者指点,那又是多么一件幸福和快乐的事情!
蒙在股里 该用户已被删除
9#
发表于 2015-3-22 03:09:08 | 只看该作者
如今主流的Web服务器软件主要由IIS或Apache组成。IIS支持ASP且只能运行在Windows平台下,Apache支持PHP,CGI,JSP且可运行于多种平台,虽然Apache是世界使用排名第一的Web服务器平台。
金色的骷髅 该用户已被删除
8#
发表于 2015-3-15 19:08:04 | 只看该作者
Asp.net脚本的出现,为ASP空间带来了更高的稳定性,同时也为程序员建站提供更高环境!
灵魂腐蚀 该用户已被删除
7#
发表于 2015-3-8 01:07:20 | 只看该作者
ASP.Net摆脱了以前ASP使用脚本语言来编程的缺点,理论上可以使用任何编程语言包括C++,VB,JS等等,当然,最合适的编程语言还是MS为.NetFrmaework专门推出的C(读csharp)。
飘灵儿 该用户已被删除
6#
发表于 2015-2-25 18:47:53 | 只看该作者
是指转换后的Servlet程序代码的行数。这给调试代码带来一定困难。所以,在排除错误时,可以采取分段排除的方法(在可能出错的代码前后输出一些字符串,用字符串是否被输出来确定代码段从哪里开始出错)。
柔情似水 该用户已被删除
5#
发表于 2015-2-8 14:34:02 | 只看该作者
众所周知,Windows以易用而出名,也因此占据不少的服务器市场。
不帅 该用户已被删除
地板
发表于 2015-2-2 22:23:06 | 只看该作者
虽然在形式上JSP和ASP或PHP看上去很相似——都可以被内嵌在HTML代码中。但是,它的执行方式和ASP或PHP完全不同。在JSP被执行的时候,JSP文件被JSP解释器(JSPParser)转换成Servlet代码,然后Servlet代码被Java编译器编译成.class字节文件,这样就由生成的Servlet来对客户端应答。所以,JSP可以看做是Servlet的脚本语言(ScriptLanguage)版。
飘飘悠悠 该用户已被删除
板凳
发表于 2015-1-25 14:17:44 | 只看该作者
这也就是最近几年来随着各种新的后台技术的诞生,CGI应用在Internet上越来越少的原因。CGI方式不适合大访问量的应用。
兰色精灵 该用户已被删除
沙发
发表于 2015-1-19 17:12:32 | 只看该作者
代码逻辑混乱,难于管理:由于ASP是脚本语言混合html编程,所以你很难看清代码的逻辑关系,并且随着程序的复杂性增加,使得代码的管理十分困难,甚至超出一个程序员所能达到的管理能力,从而造成出错或这样那样的问题。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-9-28 19:15

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表