• Modern计算器—提前体验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.0
    
    Dim shu1 As Single, shu2 As Single, suanfu1 As String
    Dim shu3 As String
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
    ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function ReleaseCapture Lib "user32" () As Long
    Private Const WM_SYSCOMMAND = &H112
    Private Const SC_MOVE = &HF010&
    Private Const HTCAPTIO = 2
    
    
    Private Sub dengyu_Click()
    shu2 = Val(Text1.Text)
    Select Case suanfu1
    Case "+"
    Text1.Text = shu1 + shu2
    Case "-"
    Text1.Text = shu1 - shu2
    Case "*"
    Text1.Text = shu1 * shu2
    Case "/"
    If shu2 = 0 Then
    Text1.Text = "除数不能为零"
    'MsgBox "分母不能为零!", 1 + 32 + 0, "错误" '错误提示框图下所示
    Else
    Text1.Text = shu1 / shu2
    End If
    End Select
    shuruk.Text = ""
    End Sub
    
    Private Sub dian_Click()
    Text1.Text = Text1.Text + "."
    If (InStr(Text1.Text, ".") = 1) Then '第一位不能为小数
      Text1.Text = ""
    End If
    If InStr(Text1.Text, ".") < Len(Text1.Text) Then
    '防止出现两个小数点
      Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
    End If
    End Sub
    
    Private Sub end_Click()
    End
    End Sub
    
    Private Sub Label1_Click()
    If Me.WindowState = 0 Then
      Me.WindowState = 1
    End If
    End Sub
    
    Private 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 Sub
    Private Sub fuhao_Click()
    If Left(Text1.Text, 1) <> "-" Then
    Text1.Text = "-" & Text1.Text
    Else
    Text1.Text = Right(Text1.Text, Len(Text1.Text) - 1)
    End If
    End Sub
    
    Private Sub genhao_Click()
    Text1.Text = Sqr(Text1.Text)
    
    End Sub
    
    Private Sub qingchu_Click()
    Text1.Text = "" '清除
    shuruk.Text = ""
    End Sub
    
    Private Sub shuzi_Click(Index As Integer)
    
    'Text1.Text = ""
    Select Case Index
    Case 0
    Text1.Text = Text1.Text + "0"
    Case 1
    Text1.Text = Text1.Text + "1"
    Case 2
    Text1.Text = Text1.Text + "2"
    Case 3
    Text1.Text = Text1.Text + "3"
    Case 4
    Text1.Text = Text1.Text + "4"
    Case 5
    Text1.Text = Text1.Text + "5"
    Case 6
    Text1.Text = Text1.Text + "6"
    Case 7
    Text1.Text = Text1.Text + "7"
    Case 8
    Text1.Text = Text1.Text + "8"
    Case 9
    Text1.Text = Text1.Text + "9"
    End Select
    End Sub
    
    Private Sub suanfu_Click(Index As Integer)
    shu1 = Val(Text1.Text)
    shu3 = CStr(shu1)
    Select Case Index
    Case 0
    suanfu1 = "+"
    Case 1
    suanfu1 = "-"
    Case 2
    suanfu1 = "*"
    Case 3
    suanfu1 = "/"
    End Select
    shuruk.Text = shu3 + suanfu1
    Text1.Text = ""
    End Sub
    
    Private Sub tuige_Click()
    If Text1.Text = "" Then
    Exit Sub
    End If
    Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)
    End Sub
    
    Private Sub xianshi_Click()
    
    End Sub
    

    运行截图:

        


    下载:Modern计算器


    @ Mayuko



  • 相关阅读:
    你的灯亮着吗随笔2
    好搜--评价
    水王ID
    回溯算法
    贪心算法
    动态规划问题
    环境安装注意事项
    好用的idea插件记录
    软件工程项目冲刺阶段二:第七天
    软件工程项目冲刺阶段二:第六天
  • 原文地址:https://www.cnblogs.com/mayuko/p/4567553.html
Copyright © 2020-2023  润新知