




下載本文檔
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
第C#實(shí)現(xiàn)鐘表程序設(shè)計(jì)本文實(shí)例為大家分享了C#實(shí)現(xiàn)鐘表程序設(shè)計(jì)的具體代碼,供大家參考,具體內(nèi)容如下
工作空間:
代碼如下:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usingSystem.Diagnostics;
namespace鐘表
publicpartialclassfrmMain:Form
{
boolflsMouseDown=false;
PointfDownPosition;
publicfrmMain()
{
InitializeComponent();
}
privatevoidctsmiExit_Click(objectsender,EventArgse)
{
this.Close();
}
privatevoidfrmMain_MouseDown(objectsender,MouseEventArgse)
{
if(e.Button==MouseButtons.Left)
{
flsMouseDown=true;
fDownPosition=e.Location;
//Debug.WriteLine(e.Location);
}
}
privatevoidfrmMain_MouseMove(objectsender,MouseEventArgse)
{
if(flsMouseDown)
{
this.Left=this.Location.X+(e.X-fDownPosition.X);
this.Top=this.Location.Y+(e.Y-fDownPosition.Y);
}
}
privatevoidfrmMain_Mouseup(objectsender,MouseEventArgse)
{
flsMouseDown=false;
}
privatevoidtmrMain_Tick(objectsender,EventArgse)
{
this.Refresh();//調(diào)用窗體的Paint事件,根據(jù)調(diào)制的時(shí)間來(lái)刷新paint時(shí)間
}
privatevoidfDrawDot(GraphicsaGraphics,doubleaValue,intaRadius)//畫出表盤刻度
{
doublelAngle=((360-aValue*6)+90)*Math.PI/180;//根據(jù)角度繪畫
PointlPoint=newPoint((int)(200+180*Math.Cos(lAngle)),//刻度所在的為值
(int)(200-180*Math.Sin(lAngle)));
aGraphics.FillEllipse(Brushes.Black,newRectangle(lPoint.X-aRadius,//FillEllipse為內(nèi)部填充顏色方法,Rectangle為繪畫圓,前倆為圓心坐標(biāo),后倆為寬和高
lPoint.Y-aRadius,2*aRadius,2*aRadius));
}
privatevoidfDrawLine(GraphicsaGraphics,doubleaValue,doubleaLength,PenaPen)//畫出時(shí),分,秒的線
{//aValue為角度值,小時(shí)12個(gè)刻度每個(gè)占30°,分和秒60個(gè)刻度每個(gè)站6°avalue按照的是一個(gè)圓分成60個(gè)換成角度乘于6
//aLength是指針的長(zhǎng)度
doublelAngle=((360-aValue*6)+90)*Math.PI/180;//角度轉(zhuǎn)化為數(shù)值
PointlPoint=newPoint((int)(200+aLength*Math.Cos(lAngle)),//指針線的終點(diǎn),坐標(biāo)x,y通過(guò)直角三角求得
(int)(200-aLength*Math.Sin(lAngle)));
aGraphics.DrawLine(aPen,newPoint(200,200),lPoint);//繪制倆點(diǎn)連成一條直線,起點(diǎn)相同都為(200,200)
}
privatevoidfrmMain_Paint(objectsender,PaintEventArgse)
{
e.Graphics.SmoothingMode=System.Drawing.Drawing2D.SmoothingMode.HighQuality;//使指針轉(zhuǎn)動(dòng)顯得平滑
e.Graphics.DrawImage(this.BackgroundImage,0,0,400,400);//規(guī)定表盤的大小和位置
for(inti=0;ii++)
if(i%5==0)fDrawDot(e.Graphics,i,6);//繪制鐘表刻度,大點(diǎn)和小點(diǎn)
elsefDrawDot(e.Graphics,i,2);
DateTimedt=DateTime.Now;//獲取時(shí)間
PenpSecond=newPen(Color.Black,2);
PenpMinute=newPen(Color.Red,2);
PenpHour=newPen(Color.Blue,4);
fDrawLine(e.Graphics,((dt.Hour%12)+dt.Minute/60.0)*5,100,pHour);//繪畫時(shí),分,秒指針
fDrawLine(e.Graphics,dt.Minute+dt.Second/60.0,160,pMinute);
fDrawLine(e.Graphics,dt.Second+dt.Millisecond/1000.0,170,pSecond);
}
Form1.Designer.cs
需添加:(以下代碼)
this.DoubleBuffered=true;
this.Deactivate+=newSystem.EventHandler(this.ctsmiExit_Click);
this.Paint+=newSystem.Windows.Forms.PaintEventHandler(this.frmMain_Paint);
this.MouseDown+=newSystem.Windows.Forms.MouseEventHandler(this.frmMain_MouseDown);
this.MouseMove+
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 穩(wěn)固家庭忠誠(chéng)義務(wù)履行書
- 《嚴(yán)重心律失?!氛n件
- 復(fù)用器械清洗流程標(biāo)準(zhǔn)化管理
- 《溶液的性質(zhì)》課件
- 酒店安全培訓(xùn)體系與實(shí)施規(guī)范
- 《國(guó)際貿(mào)易專業(yè)術(shù)語(yǔ)》課件
- 天臺(tái)抽蓄500千伏送出工程報(bào)告書
- 樂(lè)高幼兒課件教案
- 開發(fā)培訓(xùn)交流會(huì)
- 《李芳人物畫B》課件
- 第二章 中國(guó)的自然環(huán)境《第四節(jié) 自然災(zāi)害》課件
- 有機(jī)合成工作總結(jié)模板
- 2024年上海市高考英語(yǔ)完形填空試題真題匯編(含答案詳解)
- 湯顯祖《牡丹亭·游園》品讀課件
- 物業(yè)安全生產(chǎn)培訓(xùn)
- 第17課《老師 我想對(duì)您說(shuō)》課件
- 人工智能在影視后期制作中的應(yīng)用
- 論實(shí)驗(yàn)動(dòng)物生物安全制度法治化完善
- Unit 4 Space Exploration Reading and Thinking 說(shuō)課課件-2022-2023學(xué)年高中英語(yǔ)人教版(2019)高中英語(yǔ)必修第三冊(cè)
- 網(wǎng)絡(luò)設(shè)備巡檢表
- 持續(xù)性姿勢(shì)知覺(jué)性頭暈PPPD課件
評(píng)論
0/150
提交評(píng)論