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

首頁(yè) > 編程 > .NET > 正文

c#改寫的(vb.net)模擬時(shí)鐘

2024-07-10 13:00:08
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
 

clockcontrol.cs

using system;
using system.windows.forms;
using system.drawing;
using system.drawing.drawing2d;
namespace clocktime
{
 /// <summary>
 /// clockcontrol 的摘要說(shuō)明。
 /// </summary>
 public class clockcontrol:system.windows.forms.usercontrol

 {
  private datetime dt;

  public clockcontrol()
  {
   //
   // todo: 在此處添加構(gòu)造函數(shù)邏輯
   //
   this.resizeredraw=true;
   this.enabled=false;

  }
  public datetime time
  {
   set
   {
    graphics grfx=this.creategraphics();
    pen pn=new pen(this.backcolor);
    initializecoordinates(grfx);
    if(dt.hour!=value.hour)
    {
     drawhourhand(grfx,pn);
    }
    if(dt.minute!=value.minute)
    {
     drawhourhand(grfx,pn);
     drawminutehand(grfx,pn);
 
    }
    if(dt.second!=value.second)
    {
     drawminutehand(grfx,pn);
     drawsecondhand(grfx,pn);
    }
    if(dt.millisecond!=value.millisecond)
    {
     drawsecondhand(grfx,pn);
    }
    dt=value;
    pn=new pen(forecolor);
    drawhourhand(grfx,pn);
    drawminutehand(grfx,pn);
    drawsecondhand(grfx,pn);
    grfx.dispose();
   }
   get
   {return dt;
   }
  }
  protected override  void onpaint(painteventargs e)
  {
   graphics grfx=e.graphics;
   pen pn=new pen(forecolor);
   solidbrush br=new solidbrush(forecolor);
   initializecoordinates(grfx);
   drawdots(grfx,br);
   drawhourhand(grfx,pn);
   drawsecondhand(grfx,pn);
   drawminutehand(grfx,pn);
  }
  protected virtual void initializecoordinates(graphics grfx)
  {
   if(this.width==0 || this.height==0) return;
   grfx.translatetransform(this.width/2,this.height/2);
   single finches=math.min(this.width/grfx.dpix,this.height/grfx.dpiy);
   grfx.scaletransform(finches*grfx.dpix/2000,finches*grfx.dpiy/2000);

  }
  protected virtual  void  drawdots(graphics grfx ,brush br)
  {
   int i,isize;
   for(i=0;i<=59;i++)
   {
    if(i%5==0)
    {
     isize=100;
    }
    else
     isize=30;
    grfx.fillellipse(br,0-isize/2,-900-isize/2,isize,isize);
    grfx.rotatetransform(6);

   }
  }
 protected virtual void  drawhourhand(graphics grfx,pen pn)
  {
   graphicsstate gs=grfx.save();
   grfx.rotatetransform(360.0f*time.hour/12+30.0f*time.minute/60);
   grfx.drawpolygon(pn,new point[]{new point(0,150),new point(100,0),new point(0,-600),new point(-100,0)});
   grfx.restore(gs);
  }
protected virtual void  drawminutehand(graphics grfx,pen pn)
  {
   graphicsstate gs=grfx.save();
   grfx.rotatetransform(360.0f*time.minute/60+6.0f*time.second/60);
   grfx.drawpolygon(pn,new point[]{new point(0,200),new point(50,0),new point(0,-800),new point(-50,0)});
   grfx.restore(gs);
  }
protected virtual void  drawsecondhand(graphics grfx,pen pn)
  {
   graphicsstate gs=grfx.save();
   grfx.rotatetransform(360.0f*time.second/60+6.0f*time.millisecond/1000);
   grfx.drawline(pn,0,0,0,-800);
   grfx.restore(gs);
  
  }
 }
}

form1.cs

using system;
using system.drawing;
using system.collections;
using system.componentmodel;
using system.windows.forms;
using system.data;
using clocktime;

namespace clocktime
{
 /// <summary>
 /// form1 的摘要說(shuō)明。
 /// </summary>
 public class form1 : system.windows.forms.form
 {
  private system.componentmodel.icontainer components;
  private system.windows.forms.timer tmr;
 private clocktime.clockcontrol clkctrl;
  public form1()
  {
   //
   // windows 窗體設(shè)計(jì)器支持所必需的
   //
   initializecomponent();

   //
   // todo: 在 initializecomponent 調(diào)用后添加任何構(gòu)造函數(shù)代碼
   //
  }

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

  #region windows 窗體設(shè)計(jì)器生成的代碼
  /// <summary>
  /// 設(shè)計(jì)器支持所需的方法 - 不要使用代碼編輯器修改
  /// 此方法的內(nèi)容。
  /// </summary>
  private void initializecomponent()
  {
   this.components = new system.componentmodel.container();
   this.clkctrl = new clocktime.clockcontrol();
   this.tmr = new system.windows.forms.timer(this.components);
   this.suspendlayout();
   //
   // clkctrl
   //
   this.clkctrl.backcolor = system.drawing.color.black;
   this.clkctrl.dock = system.windows.forms.dockstyle.fill;
   this.clkctrl.enabled = false;
   this.clkctrl.forecolor = system.drawing.color.white;
   this.clkctrl.location = new system.drawing.point(0, 0);
   this.clkctrl.name = "clkctrl";
   this.clkctrl.size = new system.drawing.size(292, 273);
   this.clkctrl.tabindex = 0;
   this.clkctrl.time = new system.datetime(2005, 6, 24, 10, 19, 26, 62);
   //
   // tmr
   //
   this.tmr.enabled = true;
   this.tmr.interval = 1000;
   this.tmr.tick += new system.eventhandler(this.tmr_tick);
   //
   // form1
   //
   this.autoscalebasesize = new system.drawing.size(6, 14);
   this.backcolor = system.drawing.systemcolors.window;
   this.clientsize = new system.drawing.size(292, 273);
   this.controls.add(this.clkctrl);
   this.forecolor = system.drawing.systemcolors.windowtext;
   this.name = "form1";
   this.text = "clockcontrol";
   this.resumelayout(false);

  }
  #endregion

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

  private void tmr_tick(object sender, eventargs e)
  {
  
   clkctrl.time=datetime.now;
  }
 }
}

編譯過(guò)程:

csc /t:library clockcontrol.cs

csc /t:winexe /r:clockcontrol.dll form1.cs

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 富民县| 长白| 西贡区| 故城县| 英德市| 高安市| 洛浦县| 景东| 乃东县| 清新县| 沙田区| 泗洪县| 南郑县| 肥西县| 乐昌市| 海晏县| 新巴尔虎右旗| 镇沅| 灯塔市| 和龙市| 涪陵区| 钦州市| 菏泽市| 寿宁县| 鄂伦春自治旗| 山东省| 治县。| 嵊州市| 澜沧| 浦北县| 比如县| 凤凰县| 西贡区| 乌拉特中旗| 南汇区| 平乐县| 施甸县| 南京市| 太原市| 潞西市| 特克斯县|