spaceandtime
spaceandtime

Reputation: 35

VB.NET How do I pass parameters to a class?

Relatively new to coding and have taken up lots of small projects to help learn the basics, and I have now set myself a challenge of a "bigger" one. Essentially I want to recreate the Message Box but with my own styling and customisable elements.

I have got the basics in a class and created it, however I want the class to have two options.

1) load all the details from an XML file for the message, I have done this and that works.

2) I want it to be like the standard message box where you can pass in parameters.

My question is, How can I achieve number 2.

I have tried adding details into the Show/Load subs but no luck, the only way around it I can see is with properties but that would take too long.

I want to be something like the below.

classname.show("message","tittle",icon,"buttons",imagefile,"caption")

However alot of my code is done in the load method as opposed to show, so it needs to be visible / accessible there.

Any help / advice would be appreciated.

Upvotes: 2

Views: 431

Answers (1)

Heinzi
Heinzi

Reputation: 172448

Properties are definitely the way to go. It also makes sense: Conceptually, the message being shown is a property of the message box.

Your Show method would look like this:

Public Shared Show(message As String, title As String, ...)
    Dim box as New MyMessageBoxWindow()
    box.Message = message
    box.Title = title
    ...
    box.ShowDialog()
End Sub

In the Load method of MyMessageBoxWindow, you access these properties and configure the UI elements.

Upvotes: 1

Related Questions