Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET General > Custom MessageBox


Reply
 
Thread Tools Display Modes
  #1  
Old 08-10-2012, 02:56 AM
piggybank1974's Avatar
piggybank1974 piggybank1974 is offline
Ultimate Contributor
 
Join Date: Mar 2002
Location: weston-super-mare(UK)
Posts: 1,789
Default 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.
Attached Files
File Type: zip Dialogs.zip (73.9 KB, 1 views)
File Type: zip MessageBoxApp 09-08-2012.zip (104.0 KB, 1 views)
Reply With Quote
  #2  
Old 08-10-2012, 08:02 AM
AtmaWeapon's Avatar
AtmaWeapon AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,416
Default

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
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #3  
Old 08-10-2012, 01:05 PM
piggybank1974's Avatar
piggybank1974 piggybank1974 is offline
Ultimate Contributor
 
Join Date: Mar 2002
Location: weston-super-mare(UK)
Posts: 1,789
Default

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.
Reply With Quote
  #4  
Old 08-10-2012, 01:38 PM
AtmaWeapon's Avatar
AtmaWeapon AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,416
Default

Oh, that's the other part. Default instances only work within an application.

Aren't dumb cryptic features fun?
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #5  
Old 08-10-2012, 04:16 PM
piggybank1974's Avatar
piggybank1974 piggybank1974 is offline
Ultimate Contributor
 
Join Date: Mar 2002
Location: weston-super-mare(UK)
Posts: 1,789
Default

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.
Reply With Quote
  #6  
Old 08-10-2012, 09:00 PM
AtmaWeapon's Avatar
AtmaWeapon AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,416
Default

Right. The designers of C# were sane and didn't introduce the feature.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->