提前体验Windows10的计算器

Win10 Build 9926引入了新版Modern计算器,新计算器采用全新设计的UI,整体上更倾向于扁平,与Win10搭配起来倒也相得益彰。

没有升级到win10就不能使用Modern计算器了嘛?

NO…初二在家也是无聊,没有去所谓的走亲戚,既然无聊,就仿Win10写一个计算器吧。

Windows的计算器不是一般的强大,今天只完成了简单的标准模式(标准模式也不是完整),主要还是体验一下Modern的设计风格。

绘出所有的素材。

由于VB的局限性,,使用Command的按钮并不美观,于是,将所有的按钮图片化,并使用Image显示出来。

此处用到了2个 控件组和N个image控件,两个Text控件。

功能:

· 简单的计算

· 最小化

· 窗口移动

素材:

固定好各个键的位置后:

上源码,由于使用了拼音变量命名,还是比较理解的:

Option Explicit' Copyright (c) 2015,烟台大学计算机学院' All right reserved.' 作者:邵帅' 文件:工程1.vbp' 完成时间:2015年2月20日' 版本号:v1.0Dim shu1 As Single, shu2 As Single, suanfu1 As StringDim shu3 As StringPrivate Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPrivate Declare Function ReleaseCapture Lib "user32" () As LongPrivate Const WM_SYSCOMMAND = &H112Private Const SC_MOVE = &HF010&Private Const HTCAPTIO = 2Private Sub dengyu_Click()shu2 = Val(Text1.Text)Select Case suanfu1Case "+"Text1.Text = shu1 + shu2Case "-"Text1.Text = shu1 – shu2Case "*"Text1.Text = shu1 * shu2Case "/"If shu2 = 0 ThenText1.Text = "除数不能为零"'MsgBox "分母不能为零!", 1 + 32 + 0, "错误" '错误提示框图下所示ElseText1.Text = shu1 / shu2End IfEnd Selectshuruk.Text = ""End SubPrivate Sub dian_Click()Text1.Text = Text1.Text + "."If (InStr(Text1.Text, ".") = 1) Then '第一位不能为小数 Text1.Text = ""End IfIf InStr(Text1.Text, ".") < Len(Text1.Text) Then'防止出现两个小数点 Text1.Text = Left(Text1.Text, Len(Text1.Text) – 1)End IfEnd SubPrivate Sub end_Click()EndEnd SubPrivate Sub Label1_Click()If Me.WindowState = 0 Then Me.WindowState = 1End IfEnd SubPrivate Sub labFormTitle_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)ReleaseCapture 'WM_SYS向窗体发送一个移动窗体命令Call SendMessage(Me.hwnd, WM_SYSCOMMAND, SC_MOVE + HTCAPTIO, 0)'SC_MOVE+ HTCAPTIO表示单击左键移动窗体End SubPrivate Sub fuhao_Click()If Left(Text1.Text, 1) <> "-" ThenText1.Text = "-" & Text1.TextElseText1.Text = Right(Text1.Text, Len(Text1.Text) – 1)End IfEnd SubPrivate Sub genhao_Click()Text1.Text = Sqr(Text1.Text)End SubPrivate Sub qingchu_Click()Text1.Text = "" '清除shuruk.Text = ""End SubPrivate Sub shuzi_Click(Index As Integer)'Text1.Text = ""Select Case IndexCase 0Text1.Text = Text1.Text + "0"Case 1Text1.Text = Text1.Text + "1"Case 2Text1.Text = Text1.Text + "2"Case 3Text1.Text = Text1.Text + "3"Case 4Text1.Text = Text1.Text + "4"Case 5Text1.Text = Text1.Text + "5"Case 6Text1.Text = Text1.Text + "6"Case 7Text1.Text = Text1.Text + "7"Case 8Text1.Text = Text1.Text + "8"Case 9Text1.Text = Text1.Text + "9"End SelectEnd SubPrivate Sub suanfu_Click(Index As Integer)shu1 = Val(Text1.Text)shu3 = CStr(shu1)Select Case IndexCase 0suanfu1 = "+"Case 1suanfu1 = "-"Case 2suanfu1 = "*"Case 3suanfu1 = "/"End Selectshuruk.Text = shu3 + suanfu1Text1.Text = ""End SubPrivate Sub tuige_Click()If Text1.Text = "" ThenExit SubEnd IfText1.Text = Left(Text1.Text, Len(Text1.Text) – 1)End SubPrivate Sub xianshi_Click()End Sub运行截图:

下载:Modern计算器

接受失败等于回归真实的自我,接受失败等于打破完美的面具,

提前体验Windows10的计算器

相关文章:

你感兴趣的文章:

标签云: