B4J Tutorial [BANanoWebix] Lesson 29 MessageBoxes

Ola

Message boxes provides alerts, confirmation and the normal modal dialog that one can create..



Here we have notifications, alerts, confirmations. We have created buttons on a form so that when they are clicked, the normal message boxes appear.

B4X:
Dim form1 As WixForm
    'initialize form and make it accept names with dots (.)
    form1.Initialize("form1").SetScroll(False)
    form1.SetWidth(350).SetMargin(3)
    '
    form1.Form.CreateButton("").SetLabel("Success").SetClick(BANano.CallBack(Me,"success_click", Null)).AddToRows(form1.Form)
    form1.Form.CreateButton("").SetLabel("Error").SetClick(BANano.CallBack(Me,"error_click", Null)).AddToRows(form1.Form)
    form1.Form.CreateButton("").SetLabel("Default").SetClick(BANano.CallBack(Me,"default_click", Null)).AddToRows(form1.Form)
    form1.Form.CreateButton("").SetLabel("Debug").SetClick(BANano.CallBack(Me,"debug_click", Null)).AddToRows(form1.Form)
    form1.Form.CreateButton("").SetLabel("Alert").SetClick(BANano.CallBack(Me,"alert_click", Null)).AddToRows(form1.Form)
    form1.Form.CreateButton("").SetLabel("Confirm").SetClick(BANano.CallBack(Me,"confirm_click", Null)).AddToRows(form1.Form)
    form1.Form.CreateButton("").SetLabel("Confirm Warning").SetClick(BANano.CallBack(Me,"confirmwarning_click", Null)).AddToRows(form1.Form)
    form1.Form.CreateButton("").SetLabel("Alert Error").SetClick(BANano.CallBack(Me,"alerterror_click", Null)).AddToRows(form1.Form)
    form1.Form.CreateButton("").SetLabel("Modal Box").SetClick(BANano.CallBack(Me,"modalbox_click", Null)).AddToRows(form1.Form)

So each button has a callback function to activate the message box.

The modal box returns the index number of the button being clicked. We have added 3 buttons to it and specified our own titles for the buttons.

B4X:
Sub modalbox_click
    Dim result As Object
    Dim cb As BANanoObject = BANano.callback(Me, "modalresult", Array(result))
    '
    Dim mb As WixMessageBox
    mb.Initialize("mb").SetTitle("Custom title").AddButton("Yes").AddButton("No").AddButton("Maybe")
    mb.SetWidth(400).SetText("Any html content here").SetCallBack(cb)
    '
    pg.ModalBox(mb.Item)
End Sub

And we trap the result of the modal with its callback.

B4X:
Sub modalresult(result As Object)
    pg.Message(result)   
End Sub

Also the other confirm dialog, we used custom labels..

B4X:
Sub confirmwarning_click
    Dim result As Boolean = False
    Dim cb As BANanoObject = BANano.CallBack(Me,"confirmed",Array(result))
    '
    Dim cw As WixMessageBox
    cw.Initialize("cw").SetTypeConfirmWarning(True).SetOK("Warning").SetCANCEL("Stop it!").SetTitle("Confirm Warning").SetText("I dunno!")
    cw.SetCallBack(cb)
    pg.Confirm1(cw.Item)
End Sub

For the other message boxes, its simple as..

B4X:
Sub alert_click
    pg.Alert("Alert!")
End Sub

Sub success_click
    pg.Message_Success("Success!")
End Sub

Sub error_click
    pg.Message_Error("Error!")
End Sub

Sub default_click
    pg.Message("Default")
End Sub

Sub debug_click
    pg.Message_Debug("Debug")
End Sub

For the confirm button we have used .Confirm1, there is also .Confirm method that uses the default properties..

B4X:
Sub confirm_click
    Dim result As Boolean = False
    Dim cb As BANanoObject = BANano.CallBack(Me,"confirmed",Array(result))
    pg.Confirm(cb, "Confirm", "Can you confirm?")
End Sub
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…