Prompt Dialog in Windows Forms

前端 未结 11 1452
名媛妹妹
名媛妹妹 2020-11-30 19:47

I am using System.Windows.Forms but strangely enough don\'t have the ability to create them.

How can I get something like a javascript prompt dialog, wi

11条回答
  •  北荒
    北荒 (楼主)
    2020-11-30 20:02

    Here's an example in VB.NET

    Public Function ShowtheDialog(caption As String, text As String, selStr As String) As String
        Dim prompt As New Form()
        prompt.Width = 280
        prompt.Height = 160
        prompt.Text = caption
        Dim textLabel As New Label() With { _
             .Left = 16, _
             .Top = 20, _
             .Width = 240, _
             .Text = text _
        }
        Dim textBox As New TextBox() With { _
             .Left = 16, _
             .Top = 40, _
             .Width = 240, _
             .TabIndex = 0, _
             .TabStop = True _
        }
        Dim selLabel As New Label() With { _
             .Left = 16, _
             .Top = 66, _
             .Width = 88, _
             .Text = selStr _
        }
        Dim cmbx As New ComboBox() With { _
             .Left = 112, _
             .Top = 64, _
             .Width = 144 _
        }
        cmbx.Items.Add("Dark Grey")
        cmbx.Items.Add("Orange")
        cmbx.Items.Add("None")
        cmbx.SelectedIndex = 0
        Dim confirmation As New Button() With { _
             .Text = "In Ordnung!", _
             .Left = 16, _
             .Width = 80, _
             .Top = 88, _
             .TabIndex = 1, _
             .TabStop = True _
        }
        AddHandler confirmation.Click, Sub(sender, e) prompt.Close()
        prompt.Controls.Add(textLabel)
        prompt.Controls.Add(textBox)
        prompt.Controls.Add(selLabel)
        prompt.Controls.Add(cmbx)
        prompt.Controls.Add(confirmation)
        prompt.AcceptButton = confirmation
        prompt.StartPosition = FormStartPosition.CenterScreen
        prompt.ShowDialog()
        Return String.Format("{0};{1}", textBox.Text, cmbx.SelectedItem.ToString())
    End Function
    

提交回复
热议问题