PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
[RESOLVED] showdialog-VBForums
Results 1 to 2 of 2

Thread: [RESOLVED] showdialog

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Posts
    669

    Resolved [RESOLVED] showdialog

    hi

    i have below code. I want that only close button should be enabled. Secondly i should not be able to move Dialog

    Public Sub CreateMyForm()
    Dim form1 As Form = New Form()
    Dim button1 As Button = New Button()
    Dim button2 As Button = New Button()
    button1.Text = "OK"
    button1.Location = New Point(10, 10)
    button2.Text = "Cancel"
    button2.Location = New Point(button1.Left, button1.Height + button1.Top + 10)
    form1.Text = "My Dialog Box"
    form1.HelpButton = True
    form1.FormBorderStyle = FormBorderStyle.FixedDialog
    form1.AcceptButton = button1
    form1.CancelButton = button2
    form1.StartPosition = FormStartPosition.CenterScreen
    form1.Controls.Add(button1)
    form1.Controls.Add(button2)
    form1.ShowDialog()
    End Sub
    Thanks

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,739

    Re: showdialog

    Don't build the form in code. Is that how you usually create forms? Add a new form to your project, open it in the designer and then design it like any other form. In code, you create an instance of that form and display it.

    For instance, if you want your form to behave something like the InputBox function, you would add a TextBox and two Buttons to your form in the designer and configure them as appropriate. You might add a Label too. You would set the DialogResult property of the two Buttons to OK and Cancel respectively. You would set Enabled to False for the OK Button and then handle the TextChanged event of the TextBox and do this sort of thing:
    vb.net Code:
    1. okButton.Enabled = (inputTextBox.TextLength > 0)
    Now the OK Button will be enabled if and only if there is text in the TextBox. You would add a property to expose the entered text like so:
    vb.net Code:
    1. Public Property InputText As String
    2.     Get
    3.         Return inputTextBox.Text
    4.     End Get
    5.     Set
    6.         inputTextBox.Text = value
    7.     End Set
    8. End Property
    If you don't want to be able to set default text then you can make that property read-only. You would then use that form in code something like this:
    vb.net Code:
    1. Using dialogue As New InputForm
    2.     If dialogue.ShowDialog() = DialogResult.OK Then
    3.         Dim inputText = dialogue.InputText
    4.  
    5.         'Use inputText here.
    6.     End If
    7. End Using
    Not being able to move the dialogue is something else entirely. To learn about that, follow the CodeBank link in my signature below and check out my thread on creating an Immovable Form.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width