Question Creating Custom Types

tylersuehr7

Member
Joined
Nov 24, 2013
Messages
9
Programming Experience
1-3
I am having a hard time phrasing this question, but I'll do my best to...

I am making a custom dialog box and I have a sub:
Public Sub Display(ByVal Title as String, ByVal Message as String, ByVal Type as DialogType)

End Sub

Well want I want is, when I get to the parameter, for it to pop up in the visual studio context menu (when you're typing) and say something like YesNoCancel or Yes No; and when you chose one it will hide buttons on the dialog to make it only have a Yes button or a No button etc...

Thanks and hope you can understand what I'm asking!
 
You would need to define an Enum, which is exactly what the MessageBoxButtons type is that is used by MessageBox.Show. Inside your method, you would then use a Select Case or, perhaps, If...Else If statements to determine what value you got and do whatever is appropriate.

I'd suggest that it might be a good idea to either have those values passed in to the constructor or use a Shared method rather than an instance method. Using an instance method would imply that you can create one dialogue form and then display it multiple times in different configurations. That's possible but probably not really appropriate.

Also, how are you going to determine what button the user clicked?
 
Thanks for your reply jmcilhinney, I really appreciate it! I understand what you mean by not using an instance method, that makes sense, but what is a shared method? Lol I'll have to do some research on enums but thanks for telling what they are, I mean I had no idea what the hell to even call them in order to ask my original question!

As of right now I am using a string in the display method to determine what type of dialog it should be and I have a sub I created:
Public Sub Display(ByVal Title as String, ByVal Message as String, ByVal Type as String)
    'few bits of code here
End Sub

This is the sub I made to determine what button was clicked:
Public Sub GetCommand(ByVal Command as String)
    If (Command = "OK") Then
        Me.DialogResult = DialogResult.OK
    End If
End Sub

There's a lot more to the code then that and I'd love to share all of it but my laptop doesn't have internet right now and I'm forced to type all this on my phone, lol. But any who this is on the dialog's code when a button is clicked...
Private Sub Button_Option1_Click(sender as Object, e as EventArgs) Handles Button_Option1.Click
    GetCommand(Button_Option1.Text)
End Sub
 
Last edited by a moderator:
Damn, it auto correct turned my if statement into a smiley face

If you use proper code formatting tags, which I have added to your previous post, then any nothing in your code will be interpreted as an emoticon. There's also an option in the advanced editor to turn off smileys in that post altogether.
 
Thanks for your reply jmcilhinney, I really appreciate it! I understand what you mean by not using an instance method, that makes sense, but what is a shared method?
A Shared method is one declared with the Shared keyword. By doing so, you make the method a member of the class itself, rather than any instance of the class. Consider MessageBox.Show. You don't create a MessageBox object and call Show on it. You call Show on the MessageBox class. It's a Shared method.
 
Back
Top