如果我单击表单上的退出按钮,是否退出脚本?

时间:2018-12-12 06:11:23

标签: powershell

我在while($ true)循环内运行选择日期日历功能。因此,它不断运行。

但是,如果用户单击表单上的退出按钮(不在对话框中),我想杀死它。我该怎么办?

Query:["DELETE FROM old_post WHERE id = ?"], Params:[(1)]
Query:["delete from post where id=? and version=?"], Params:[(1, 1)]

2 个答案:

答案 0 :(得分:0)

您不需要

 while($true) {}

只要写

[void][System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")
Function Pick-Date {
  $Cal = New-Object System.Windows.Forms.MonthCalendar
  $Cal.ShowWeekNumbers = $true
  $Cal.MaxSelectionCount = 1
  $Cal.Dock = 'Fill'
  $Form = New-Object Windows.Forms.Form
  $Form.text = "Colocar fecha que desea enviar. Y presiona Enter"
  $Form.Size = New-Object Drawing.Size @(656,620)
  $btnSelect = New-Object System.Windows.Forms.Button
  $btnSelect.Size = "100,100"
  $btnSelect.add_Click({ $Form.close() })
  $btnSelect.Location = New-Object System.Drawing.Point(530,480)
  $btnSelect.Text="ENTER"
  $Form.Controls.Add($btnSelect )
  $Form.AcceptButton = $btnSelect
  $Form.Controls.Add($Cal)
  $Form.Add_Shown({$Form.Activate()})
  [void]$Form.ShowDialog()
  return (Get-Date($Cal.SelectionStart))
}

$fecha = Pick-Date
write-host $fecha

除非您希望即使用户输入了单击日期也打开日历表单?当用户单击退出或输入日期时,以上版本将关闭。

答案 1 :(得分:0)

您可以在FormClosing事件中检查关闭表单的原因,并设置脚本范围的变量以防止重新打开:

{
    "name": "my-app",
    "version": "0.0.1",
    "private": true,
    "scripts": {
        "start": "node node_modules/react-native/local-cli/cli.js start",
        "test": "jest"
    },
    "dependencies": {
        "@ptomasroos/react-native-multi-slider": "0.0.12",
        "firebase": "^5.1.0",
        "javascript-time-ago": "^1.0.30",
        "mobx": "^4.1.1",
        "mobx-react": "^5.0.0",
        "native-base": "^2.8.1",
        "prop-types": "^15.6.2",
        "protobufjs": "^6.8.8",
        "react": "16.2.0",
        "react-native": "^0.57.7",
        "react-native-actionsheet": "^2.3.0",
        "react-native-aws3": "0.0.8",
        "react-native-axios": "^0.17.1",
        "react-native-billing": "^2.9.1",
        "react-native-card-stack-swiper": "^1.0.5",
        "react-native-collapsible": "^0.10.0",
        "react-native-cookies": "^3.2.0",
        "react-native-datepicker": "^1.6.0",
        "react-native-dropdownalert": "^3.5.0",
        "react-native-elements": "^0.19.0",
        "react-native-event-listeners": "^1.0.3",
        "react-native-expandable-section-flatlist": "^1.0.3",
        "react-native-fbsdk": "^0.8.0",
        "react-native-fcm": "^16.0.0",
        "react-native-floating-action": "^1.10.1",
        "react-native-geocoding": "^0.3.0",
        "react-native-gifted-chat": "^0.4.3",
        "react-native-google-places-autocomplete": "^1.3.6",
        "react-native-hide-show-password-input": "^1.0.7",
        "react-native-image-crop-picker": "^0.19.3",
        "react-native-image-picker": "^0.26.10",
        "react-native-image-placeholder": "^1.0.14",
        "react-native-instagram-login": "^1.0.7",
        "react-native-keyboard-aware-scroll-view": "^0.4.4",
        "react-native-keyboard-aware-scrollview": "^2.0.0",
        "react-native-keyboard-spacer": "^0.4.1",
        "react-native-linear-gradient": "^2.4.0",
        "react-native-linkedin": "^1.3.1",
        "react-native-localization": "^2.0.0",
        "react-native-material-bottom-navigation": "^0.9.0",
        "react-native-modal-datetime-picker": "^6.0.0",
        "react-native-open-settings": "^1.0.1",
        "react-native-pages": "^0.7.0",
        "react-native-permissions": "^1.1.1",
        "react-native-picker-select": "^5.1.0",
        "react-native-popup-menu": "^0.12.4",
        "react-native-pulse": "^1.0.6",
        "react-native-scrollable-tab-view": "^0.8.0",
        "react-native-share": "^1.0.26",
        "react-native-simple-toast": "0.0.8",
        "react-native-snap-carousel": "^3.7.2",
        "react-native-splash-screen": "^3.1.1",
        "react-native-star-rating": "^1.0.9",
        "react-native-swipe-cards": "^0.1.1",
        "react-native-swipe-list-view": "^1.0.7",
        "react-native-swipeable-flat-list": "0.0.5",
        "react-native-swipeout": "^2.3.3",
        "react-native-switch": "^1.4.0",
        "react-native-twitter-signin": "https://github.com/GoldenOwlAsia/react-native-twitter-signin.git#master",
        "react-native-view-more-text": "^2.0.1",
        "react-native-viewpager": "^0.2.13",
        "react-navigation": "^1.0.3",
        "rn-viewpager": "^1.2.9"
    },
    "devDependencies": {
        "@babel/plugin-proposal-decorators": "^7.2.0",
        "babel-jest": "22.2.2",
        "babel-preset-react-native": "4.0.0",
        "jest": "22.2.2",
        "react-test-renderer": "16.2.0"
    },
    "jest": {
        "preset": "react-native",
        "transform": {
            "^.+\\.js$": "<rootDir>/node_modules/react-native/jest/preprocessor.js"
        }
    }
}