Results 1 to 19 of 19

Thread: [2005] custom messagebox

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    216

    [2005] custom messagebox

    Ok maybe im just being lazy. But maybe there is a cool new trick i will learn.

    I need a msgbox that basicly just asks the user 1,2,3,or4 Each one could be on a button. So no "input" would be needed.

    Then my code would do something based on what was selected.


    Dont really want to create a new form for this and have to pass values back and forth. Just wanted a simple pop up.


    Any ideas or suggestions. Or am I just better off creating a tiny form and dealing w/ passing the values back and forth.

  2. #2
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: [2005] custom messagebox

    Nope message boxes are strictly limited in terms of what they can present. It is only a few lines of code to write your own popup though.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    216

    Re: [2005] custom messagebox

    do you have an example of a simple popup then?

    or is it just building a new form and going from there?

  4. #4
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    Re: [2005] custom messagebox

    It can be done, see http://www.knowdotnet.com/articles/a...dapicalls.html (this is in C# but should be easy enough to convert).

    It might be quicker to just make a small form...

    Edit: Here's a VB example http://vbnet.mvps.org/index.html?cod...ssageboxex.htm
    Last edited by Bulldog; Mar 27th, 2009 at 03:25 PM.

  5. #5
    PowerPoster keystone_paul's Avatar
    Join Date
    Nov 2008
    Location
    UK
    Posts
    3,327

    Re: [2005] custom messagebox

    Fraid so - but all you need is a start function that accepts your four options as strings, display four buttons and set their captions, display the form as a dialog, wait for a click and then return the name of the selected item and close the form.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    216

    Re: [2005] custom messagebox

    Bulldog,

    Your right...looks simpler to create you own form...lOL

    Paul,

    I guess form time is the way to go..

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [2005] custom messagebox

    Quote Originally Posted by hockey1314 View Post
    Ok maybe im just being lazy.
    No maybe about it.

    Create your own using a form. This is something that you will, or at least theoretically you will, be able to use in a whole lot of different projects.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    216

    Re: [2005] custom messagebox

    Ok i built my own little form for this. But I am stuck.

    I pass the variables to the new little pop up form. But I am missing how to call the form as a function so i can get the result of wich radio button was selected.

    I put a comment in where i think a function would be needed to get the return but have never asked for info back from a form before. Only sent it to a new form.

    Any guidence?

    I did a simple moc up to get it working then will go for the real deal. Form 1
    Code:
    Public Class Form1
        Dim total As Integer = 3
        Dim strtxt(5) As String
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            ' This needs to be a function that then sets the restults to label2.txt
            
            Dim NewMDIChild As New Form2(total, strtxt)
            NewMDIChild.Show()
    
        End Sub
    
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Dim txt1 As String = "1st line"
            Dim txt2 As String = "2nd line"
            Dim txt3 As String = "3rd line"
            Dim txt4 As String = "4th line"
            Dim txt5 As String = "5th line"
            strtxt(0) = txt1
            strtxt(1) = txt2
            strtxt(2) = txt3
            strtxt(3) = txt4
            strtxt(4) = txt5
        End Sub
    End Class
    Form 2
    Code:
    Public Class Form2
        Dim ttl As Integer
        Dim Tstring(5) As String
    
        Public Sub New(ByVal totalvar As Integer, ByVal txtstr() As String)
            InitializeComponent()
    
            ttl = totalvar
            Tstring = txtstr
        End Sub
    
        Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
            Dim radioarray(5) As RadioButton
    
            radioarray(0) = RadioButton1
            radioarray(1) = RadioButton2
            radioarray(2) = RadioButton3
            radioarray(3) = RadioButton4
            radioarray(4) = RadioButton5
    
    
            For count As Integer = 0 To 4
                radioarray(count).Visible = False
            Next
            For count As Integer = 0 To ttl
                radioarray(count).Text = Tstring(count)
                radioarray(count).Visible = True
    
            Next
        End Sub
    End Class

  9. #9
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    Re: [2005] custom messagebox

    If for example you have a TextBox on the child form, you can interrogate the child forms controls after it is closed, like this;

    Code:
            Dim NewMDIChild As New Form2()
            NewMDIChild.ShowDialog()
            ' After the sub-form closes, the control data is still available
            MessageBox.Show(NewMDIChild.TextBox1.Text)
    Since you're showing a kind of MessageBox, then ShowDialog is appropriate.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    216

    Re: [2005] custom messagebox

    so would that be true with radio buttons too. Basiclly i want to know wich radio button they selected. Then knowing that I can grab the correct text.

  11. #11
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    Re: [2005] custom messagebox

    That's the idea, I suggest you evaluate them in the sub-form and just pass the 'conclusion' back to the main form.

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    216

    Re: [2005] custom messagebox

    Ok i gave that a shot but my message box pops back blank. So either i screwed something up assigning the info or its not getting it back when the form closes.

    Form 1

    Code:
    Public Class Form1
        Dim total As Integer = 3
        Dim strtxt(5) As String
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    
            ' This needs to be a function that then sets the restults to label2.txt
            
            Dim NewMDIChild As New Form2(total, strtxt)
            NewMDIChild.ShowDialog()
            MessageBox.Show(NewMDIChild.Label1.Text)
    
        End Sub
    
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Dim txt1 As String = "1st line"
            Dim txt2 As String = "2nd line"
            Dim txt3 As String = "3rd line"
            Dim txt4 As String = "4th line"
            Dim txt5 As String = "5th line"
            strtxt(0) = txt1
            strtxt(1) = txt2
            strtxt(2) = txt3
            strtxt(3) = txt4
            strtxt(4) = txt5
        End Sub
    End Class
    Form 2

    Code:
    Public Class Form2
        Dim ttl As Integer
        Dim Tstring(5) As String
    
        Public Sub New(ByVal totalvar As Integer, ByVal txtstr() As String)
            InitializeComponent()
    
            ttl = totalvar
            Tstring = txtstr
            Dim answer As String = ""
    
            If RadioButton1.Checked = True Then
                answer = RadioButton1.Text
            ElseIf RadioButton2.Checked = True Then
                answer = RadioButton2.Text
            ElseIf RadioButton3.Checked = True Then
                answer = RadioButton3.Text
            ElseIf RadioButton4.Checked = True Then
                answer = RadioButton4.Text
            ElseIf RadioButton5.Checked = True Then
                answer = RadioButton5.Text
            End If
    
            Label1.Text = answer
    
    
        End Sub
    
        Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
            Dim radioarray(5) As RadioButton
    
            radioarray(0) = RadioButton1
            radioarray(1) = RadioButton2
            radioarray(2) = RadioButton3
            radioarray(3) = RadioButton4
            radioarray(4) = RadioButton5
    
    
            For count As Integer = 0 To 4
                radioarray(count).Visible = False
            Next
            For count As Integer = 0 To ttl
                radioarray(count).Text = Tstring(count)
                radioarray(count).Visible = True
    
            Next
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Me.Close()
    
        End Sub
    End Class

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    216

    Re: [2005] custom messagebox

    I changed form 2 to this and it fixed it

    now is there a way to display the radio buttons in that group that does not automaticly have one selected already when they display. Basicly all of them would display unselected.



    Code:
    Public Class Form2
        Dim ttl As Integer
        Dim Tstring(5) As String
        Dim answer As String = ""
    
        Public Sub New(ByVal totalvar As Integer, ByVal txtstr() As String)
            InitializeComponent()
    
            ttl = totalvar
            Tstring = txtstr
    
        End Sub
    
        Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
            Dim radioarray(5) As RadioButton
    
            radioarray(0) = RadioButton1
            radioarray(1) = RadioButton2
            radioarray(2) = RadioButton3
            radioarray(3) = RadioButton4
            radioarray(4) = RadioButton5
    
    
            For count As Integer = 0 To 4
                radioarray(count).Visible = False
            Next
            For count As Integer = 0 To ttl
                radioarray(count).Text = Tstring(count)
                radioarray(count).Visible = True
    
            Next
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If RadioButton1.Checked = True Then
                answer = RadioButton1.Text
            ElseIf RadioButton2.Checked = True Then
                answer = RadioButton2.Text
            ElseIf RadioButton3.Checked = True Then
                answer = RadioButton3.Text
            ElseIf RadioButton4.Checked = True Then
                answer = RadioButton4.Text
            ElseIf RadioButton5.Checked = True Then
                answer = RadioButton5.Text
            End If
    
            Label1.Text = answer
            Debug.WriteLine(answer)
            Me.Close()
    
        End Sub
    End Class

  14. #14
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    Re: [2005] custom messagebox

    The idea behind RadioButtons is that one is always selected, but you can set the Checkstate of all radio buttons to be False in the designer.

    Incidentally you can do this;

    Code:
            If RadioButton1.Checked Then
                answer = RadioButton1.Text
    you dont need RadioButton1.Checked = True.

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    216

    Re: [2005] custom messagebox

    The checked state was set to false in all of my radio buttons. So does it always still have to have 1 checked by default. And that is why it is showing?

    Thanks for the tip about not needing = true.

  16. #16
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    Re: [2005] custom messagebox

    That would be normal.

  17. #17
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    Re: [2005] custom messagebox

    If you wanted that functionality, you could use CheckBoxes instead.

  18. #18

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    216

    Re: [2005] custom messagebox

    not a big deal just an anoyance.

    Thanks for your help.

  19. #19
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,950

    Re: [2005] custom messagebox

    If you put four checkboxes down, you can do handle the events so that only one is ever checked, but they can all be un-checked.

    There's probably a more compact way of doing this, but this what I mean;
    Code:
       Private Sub CheckBox6_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox6.CheckedChanged
            If CheckBox6.Checked Then
                CheckBox3.Checked = False
                CheckBox4.Checked = False
                CheckBox5.Checked = False
            End If
        End Sub
        Private Sub CheckBox5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox5.CheckedChanged
            If CheckBox5.Checked Then
                CheckBox3.Checked = False
                CheckBox4.Checked = False
                CheckBox6.Checked = False
            End If
        End Sub
        Private Sub CheckBox4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox4.CheckedChanged
            If CheckBox4.Checked Then
                CheckBox3.Checked = False
                CheckBox5.Checked = False
                CheckBox6.Checked = False
            End If
        End Sub
        Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged
            If CheckBox3.Checked Then
                CheckBox4.Checked = False
                CheckBox5.Checked = False
                CheckBox6.Checked = False
            End If
        End Sub

Posting Permissions

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



Click Here to Expand Forum to Full Width