 |
 |

08-10-2012, 02:56 AM
|
 |
Ultimate Contributor
|
|
Join Date: Mar 2002
Location: weston-super-mare(UK)
Posts: 1,789
|
|
Custom MessageBox
|
Hi All,
I've been wanting to create a custom Messagebox, as I've found that the Windows Messagebox, does not allow Bold text etc.
Last night I created a little project ‘Messagebox 09-08-2012’ see zip.
Everything was working fine so I created a Class library ‘Dialogs’ see zip.
This allows me to use it in VB/C# projects that I have.
The problem is that overloads show does not seem to appear when it’s in the Dialog dll, although I did convert it to C# and added it to one of my project it still does not appear.
For example in the project ‘Messagebox 09-08-2012’ I do not instantiate the Messagebox class e.g.
Code:
Dim mSB As New StringBuilder
mSB.AppendLine("(1) jason \b ssdf df\b0 \par")
mSB.AppendLine("2 - sdf dfsdf sdf ds sd \par")
mSB.AppendLine("3 - 22323:")
mSB.AppendLine("4 - sdf dfsdf sdf ds sd \par")
MyDialogs.MessageBox.Show(mSB.ToString, "Caption", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, 10)
But in the Vb/C# using the Dialog Dll I have to instantiate or it will not work.
Code:
StringBuilder mSB = new StringBuilder();
mSB.AppendLine(@"(1) jason \b ssdf df\b0 \par");
mSB.AppendLine(@"2 - sdf dfsdf sdf ds sd \par");
mSB.AppendLine(@"3 - 22323:");
mSB.AppendLine(@"4 - sdf dfsdf sdf ds sd \par");
Dialogs.MyDialogs.MessageBox mDialog = new Dialogs.MyDialogs.MessageBox();
mDialog.Show(mSB.ToString(), "Caption", MessageBoxButtons.OK, MessageBoxIcon.Error, 10);
mDialog.Dispose();
I did try to change the overloads Show method to shared/static but the mybase.showdialog function will not work if you do
Code:
Public Overloads Function Show(ByVal Text As String) As System.Windows.Forms.DialogResult
mText = Text
mCaption = String.Empty
mIcon = MessageBoxIcon.None
mButtons = MessageBoxButtons.OK
mDialogResult = MyBase.ShowDialog()
MessageBeep(0)
Return mDialogResult
End Function
Any ideas I would be greatful.
|
|

08-10-2012, 08:02 AM
|
 |
Fabulous Florist
Forum Leader * Guru *
|
|
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,416
|
|
VB has a dumb feature called "Default Instances" that pretends the name of a class that represents a form is also a property that accesses that form. It looks like you aren't creating an instance, but what's really happening is Microsoft is hiding it from you because they think VB developers are stupid.
You can't really make Show() or ShowDialog() Shared because you have to have an instance of a form to show it. That doesn't mean you can't make a shared method that hides an instance. For example:
Code:
Public Shared Function ShowCustomDialog(...) As DialogResult
Dim dlg As New MyDialog(...)
' Set properties...
Return dlg.ShowDialog()
End Sub
|
|

08-10-2012, 01:05 PM
|
 |
Ultimate Contributor
|
|
Join Date: Mar 2002
Location: weston-super-mare(UK)
Posts: 1,789
|
|
|
Hi AW,
I see what you’re saying, but it looks ugly and unnatural, if I have to define a new function I might as well define a new instance, a single extra line of code is not going to make much difference!
I did use reflector to see if MessageBox could give up its secrets but showcore etc was not a lot to go on, it must use a boat load of api in the background.
The thing that does puzzle me is that in the MessageBox app it works fine!
I can call show, without creating an instance, but when it’s in a DLL forget about it, although it does not work in c# also.
|
|

08-10-2012, 01:38 PM
|
 |
Fabulous Florist
Forum Leader * Guru *
|
|
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,416
|
|
|
Oh, that's the other part. Default instances only work within an application.
Aren't dumb cryptic features fun?
|
|

08-10-2012, 04:16 PM
|
 |
Ultimate Contributor
|
|
Join Date: Mar 2002
Location: weston-super-mare(UK)
Posts: 1,789
|
|
|
Err! no,
But I converted the VB Form and Extended Richtextbox control to c# but it still did not work only in VB?
answers on a post card to C# who loves it!
Edit:
I just read an artical on default instances, now it makes sense! I'm assuming now that default instances are a VB thing, and not availabe in c# hence it did not work?
|
Last edited by piggybank1974; 08-10-2012 at 04:36 PM.
|

08-10-2012, 09:00 PM
|
 |
Fabulous Florist
Forum Leader * Guru *
|
|
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,416
|
|
Right. The designers of C# were sane and didn't introduce the feature. 
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|