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

首頁 > 開發(fā) > 綜合 > 正文

C#--一直飛翔的小鳥

2024-07-21 02:17:26
字體:
來源:轉載
供稿:網(wǎng)友
 

一接觸到c#就被它的魅力所吸引,vb一樣快速開發(fā),c++一樣的間接語法,簡直就是完美的統(tǒng)一.呵呵.

所以,寫了個小程序,可以在桌面上飛來飛去,如果這個程序要是用vb6來做,一定會很麻煩,而且需要調(diào)用到api函數(shù).可是利用vs,僅僅需要動動鼠標,改改屬性即可,簡直太方便了!

首先,準備好小鳥的素材,最好gif動畫的,省卻代碼來實現(xiàn)動畫(但無法控制動畫速度了).

然后就是添加控件,2個timer用來控制方向和動畫,一個contextmenu實現(xiàn)右鍵菜單.(當然,你也可以不添加而是手寫代碼,但這樣就無法體現(xiàn)出快速開發(fā)的特性了.盡管ide自己生成的代碼很啰唆)

這里要用到三個比較重要的特性:

1.窗體的topmost實現(xiàn)動畫的最前端顯示

2.窗體的透明屬性(transparencykey)來實現(xiàn)非矩形外觀

3.窗體的背景圖片(backgroundimage)屬性來顯示小鳥

在方法的實現(xiàn)上要注意兩點:

1.小鳥飛到邊緣的轉向

2.鼠標移動無邊框窗體


好了,來看看具體代碼的實現(xiàn)吧:

//實現(xiàn)飛行轉向

private void timmove_tick(object sender, system.eventargs e)
  {
   if(this.left<=0)
   {
    this.movetoleft=false;
    this.backgroundimage=this.imagelist1.images[4];
    this.movex=5;
   }

   if(this.left>=system.windows.forms.screen.primaryscreen.workingarea.width-this.width)
   {
    this.movetoleft=true;
    this.backgroundimage=this.imagelist1.images[0]; 
    this.movex=-5;
   }
   if(this.top<=0)
   {
    this.movey=5;
   }
   if(this.top>=system.windows.forms.screen.primaryscreen.workingarea.height-this.height)
   {
    this.movey=-5;
   }
   this.left+=movex;
   this.top+=movey;
  }


//實現(xiàn)鼠標移動無邊框窗體

private void form1_mousedown(object sender, system.windows.forms.mouseeventargs e)
  {
   if(e.button==mousebuttons.left)
   {
    canmove=true;
    curx=e.x;
    cury=e.y;
   }
  }

  private void form1_mouseup(object sender, system.windows.forms.mouseeventargs e)
  {
   canmove=false;
  }

  private void form1_mousemove(object sender, system.windows.forms.mouseeventargs e)
  {
   if(canmove)
   {
    this.left = this.left + e.x - curx;
    this.top = this.top + e.y - cury;
   }
  }


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 肇庆市| 胶南市| 江西省| 巴林右旗| 航空| 二连浩特市| 水城县| 南宫市| 建瓯市| 桑日县| 广州市| 象州县| 忻城县| 铜陵市| 长海县| 河津市| 青河县| 重庆市| 志丹县| 陆河县| 开原市| 新沂市| 阳曲县| 芦溪县| 富源县| 成安县| 通渭县| 内江市| 民丰县| 奇台县| 南通市| 桐城市| 石景山区| 翁牛特旗| 叶城县| 涿鹿县| 托里县| 闻喜县| 高尔夫| 巴青县| 巴青县|