B4A Library [Class] Custom MsgBox

This class will allow you to create customized non-modal message boxes, you can change colors, fonts, add bitmaps to the background, use RichStrings, etc.

Requirements:

- B4A 2.xx
- RichString Lib
- StringUtils Lib
- Add the Class module "CustomMsgBox.bas" to your project

How to use:

Initialize the class like this for example:

B4X:
Sub Globals

    Dim MyMsgBox As CustomMsgBox

End Sub

Then, create your custom message box:
B4X:
'With Icon
myMsgBox.Initialize(Activity, Me, "Default", "H", 1, 95%x, 200dip, LoadBitmap(File.DirAssets, "WarningIcon.png"))

'Without Icon
myMsgBox.Initialize(Activity, Me, "Default", "H", 1, 95%x, 200dip, Null)

'Then add text to the Title and Body of the custom msgbox
MyMsgBox.Title.Text = "Custom MsgBox v1.0"

MyMsgBox.ShowMessage("Simple box with 1 button, horizontal")

...

'This routine will get the button tapped, in this case "Default" 
'is the name of the message box, you can name yours with whatever name you like
Sub Default_Click

    Msgbox(myMsgBox.ButtonSelected, "Button Pressed")
            
End Sub

That's it!!.

All the available methods are self explanatory.

UPDATE: Added parameter to align the message

ShowMessage(BoxMessage As String, Alignment As String)

Updated to Version 1.0.4 on Feb 15, 2013.

The attached sample shows one of the many ways it can be used.

Screen shots:

6jJaIl.png]Shot 1
c0Odjl.png]Shot 2

fdE9El.png]Shot3
9Xxwel.png]Shot 4
 

Attachments

  • CustomMsgBox_Class_1.0.4.zip
    18.7 KB · Views: 1,687
Last edited:

njesus

Member
Licensed User
Longtime User
Thanks, this is great!

Do you happen to know what's the minimum api level required?
 

Mahares

Expert
Licensed User
Longtime User
@NJDUde: It looks great. particularly the custom msgbox. The height of the msgbox is defined in the MyMsgbox.initialize. What happens when the text extends beyond the height you set, does it scroll down or will you have to create a scrollview inside the inner panel?
Again thank for your highly appreciated contributions. Storm Sandy must not have hurt your brains too much.
 

NJDude

Expert
Licensed User
Longtime User
What happens when the text extends beyond the height you set, does it scroll down or will you have to create a scrollview inside the inner panel?

Yes, the text will scroll.

Storm Sandy must not have hurt your brains too much.
Let's hope this Nor'easter storm also leaves my brain untouched. :D
 
Last edited:

Harris

Expert
Licensed User
Longtime User
Good Stuff!

Found one issue:
In the Class, Private Sub PressedButton_Touch(...)

Code reads:


B4X:
If SubExists(MsgModule, MsgBoxEvent & "_Click") Then
   CallSubDelayed( Main, MsgBoxEvent & "_Click")
End If

Possibly should be:

B4X:
If SubExists(MsgModule, MsgBoxEvent & "_Click") Then
   CallSubDelayed( MsgModule, MsgBoxEvent & "_Click")
End If

Otherwise, button press always returns to MAIN module, rather than the calling module.

Thanks
 

Harris

Expert
Licensed User
Longtime User
Is it possible to ignore the PressedButton_Touch event if no longer on the button (panel) when the finger is released (mouse up event)?

Thanks
 

NJDude

Expert
Licensed User
Longtime User
Good Stuff!

Found one issue:
In the Class, Private Sub PressedButton_Touch(...)

Code reads:


B4X:
If SubExists(MsgModule, MsgBoxEvent & "_Click") Then
   CallSubDelayed( Main, MsgBoxEvent & "_Click")
End If

Possibly should be:

B4X:
If SubExists(MsgModule, MsgBoxEvent & "_Click") Then
   CallSubDelayed( MsgModule, MsgBoxEvent & "_Click")
End If

Otherwise, button press always returns to MAIN module, rather than the calling module.

Thanks

Yes, I think you are right, I just tested the code with 1 activity. I'll fix that.
 

roarnold

Active Member
Licensed User
Longtime User
Custom MsgBox

NJ Dude,

I was looking for a custom msg box in a class as I need it for other modules. When building the Class I installed the "Dim MyMsgBox As CustomMsgBox" which shows up red. I have the .xml and jar files where they need to be. Objects where they need to go.

Why is it red when placed in the Class_Globals?

THanks,
R
 

Bryan

Member
Licensed User
Longtime User
I'm not sure what the problem is or even if there is one. Looking over the
CustomMsgBox Version 1.4 code I noticed several variables(?) if that is what they are. They are red in color indicating there is a problem with them. After checking I found that they are not declared in the Class Module at all. So, where are they declared? Are they in a lib maybe that I don't have loaded?
Here is the list of the names of the red variables(?)

Delta
Rate
Scale
ButtonSize
Locate

It appears the CustomMessage box works but the above words are showing up in Red in the IDE.

Thanks,
Bryan
 
Last edited:
Top