3

Is there an easy way to display a custom font for a MessageBox?

For "easy way" I mean using WinAPI or other techniques but not coding a entire messagebox from scratch.

I've seen lots of custom messagebox but most are just forms which don't preserve default messagebox additional parametters, other custom messagebox just has their size/bounds wrong so the "ok" button is cutted or not right alligned, and other custom messagebox has their own problems/bugs.

I hope if is possibly to add a generic parametter to instance this great custom messagebox setting the desired font:

The original code is a C# custom messagebox class of @Hans Passant which I've taken a lot time ago from here Winforms-How can I make MessageBox appear centered on MainForm? and translated it using an online translator:

' [ Centered Messagebox ]
'
' Examples :
'
' Using New MessageBox_Centered(Me)
'     MessageBox.Show("Test Text", "Test Title", MessageBoxButtons.OK)
' End Using

#Region " Centered MessageBox Class"

Imports System.Runtime.InteropServices
Imports System.Text

Class MessageBox_Centered
Implements IDisposable

' P/Invoke
Public Class NativeMethods

    Delegate Function EnumThreadWndProc(hWnd As IntPtr, lp As IntPtr) As Boolean

    <DllImport("user32.dll")> _
    Shared Function EnumThreadWindows(tid As Integer, callback As EnumThreadWndProc, lp As IntPtr) As Boolean
    End Function

    <DllImport("kernel32.dll")> _
    Shared Function GetCurrentThreadId() As Integer
    End Function

    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Unicode)> _
    Shared Function GetClassName(hWnd As IntPtr, buffer As StringBuilder, buflen As Integer) As Integer
    End Function

    <DllImport("user32.dll")> _
    Shared Function GetWindowRect(hWnd As IntPtr, ByRef rc As RECT) As Boolean
    End Function

    <DllImport("user32.dll")> _
    Shared Function MoveWindow(hWnd As IntPtr, x As Integer, y As Integer, w As Integer, h As Integer, repaint As Boolean) As Boolean
    End Function

    Structure RECT
        Public Left As Integer
        Public Top As Integer
        Public Right As Integer
        Public Bottom As Integer
    End Structure

End Class

Private mTries As Integer = 0
Private mOwner As Form

Public Sub New(owner As Form)
    mOwner = owner
    owner.BeginInvoke(New MethodInvoker(AddressOf findDialog))
End Sub

Private Sub findDialog()

    ' Enumerate windows to find the message box
    If mTries < 0 Then Return

    Dim callback As New NativeMethods.EnumThreadWndProc(AddressOf checkWindow)
    If NativeMethods.EnumThreadWindows(NativeMethods.GetCurrentThreadId(), callback, IntPtr.Zero) Then
        If System.Threading.Interlocked.Increment(mTries) < 10 Then
            mOwner.BeginInvoke(New MethodInvoker(AddressOf findDialog))
        End If
    End If

End Sub

Private Function checkWindow(hWnd As IntPtr, lp As IntPtr) As Boolean

    ' Checks if <hWnd> is a dialog
    Dim sb As New StringBuilder(260)
    NativeMethods.GetClassName(hWnd, sb, sb.Capacity)
    If sb.ToString() <> "#32770" Then Return True

    ' Got it
    Dim frmRect As New Rectangle(mOwner.Location, mOwner.Size)
    Dim dlgRect As NativeMethods.RECT
    NativeMethods.GetWindowRect(hWnd, dlgRect)
    NativeMethods.MoveWindow(hWnd, frmRect.Left + (frmRect.Width - dlgRect.Right + dlgRect.Left) \ 2, frmRect.Top + (frmRect.Height - dlgRect.Bottom + dlgRect.Top) \ 2, dlgRect.Right - dlgRect.Left, dlgRect.Bottom - dlgRect.Top, True)
    Return False

End Function

Public Sub Dispose() Implements IDisposable.Dispose
    mTries = -1
End Sub

End Class

#End Region

UPDATE:

Trying to adapt @Pete supposed solution just I can't do it.

Class MessageBox_Centered : Implements IDisposable

Public Class NativeMethods

    Delegate Function EnumThreadWndProc(hWnd As IntPtr, lp As IntPtr) As Boolean
    Delegate Function EnumWindowsProc(hWnd As IntPtr, lp As IntPtr) As Boolean

    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    Shared Function EnumThreadWindows(tid As Integer, callback As EnumThreadWndProc, lp As IntPtr) As Boolean
    End Function

    <DllImport("kernel32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    Shared Function GetCurrentThreadId() As Integer
    End Function

    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    Shared Function GetClassName(hWnd As IntPtr, buffer As StringBuilder, buflen As Integer) As Integer
    End Function

    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    Shared Function GetWindowRect(hWnd As IntPtr, ByRef rc As RECT) As Boolean
    End Function

    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    Shared Function MoveWindow(hWnd As IntPtr, x As Integer, y As Integer, w As Integer, h As Integer, repaint As Boolean) As Boolean
    End Function


    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    Shared Function GetWindowText(ByVal hwnd As IntPtr, ByVal lpString As StringBuilder, ByVal cch As Integer) As Integer
    End Function

    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    Shared Function EnumChildWindows(hwndParent As IntPtr, lpEnumFunc As EnumWindowsProc, lParam As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
    End Function

    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    Shared Function SendMessage(hWnd As IntPtr, Msg As UInt32, wParam As IntPtr, lParam As IntPtr) As IntPtr
    End Function

    Structure RECT
        Public Left As Integer
        Public Top As Integer
        Public Right As Integer
        Public Bottom As Integer
    End Structure

End Class

Private mTries As Integer = 0
Private mOwner As Form

Public Sub New(owner As Form)
    mOwner = owner
    owner.BeginInvoke(New MethodInvoker(AddressOf findDialog))
End Sub

Private Sub findDialog()

    ' Enumerate windows to find the message box
    If mTries < 0 Then Return

    Dim callback As New NativeMethods.EnumThreadWndProc(AddressOf checkWindow)
    If NativeMethods.EnumThreadWindows(NativeMethods.GetCurrentThreadId(), callback, IntPtr.Zero) Then
        If System.Threading.Interlocked.Increment(mTries) < 10 Then
            mOwner.BeginInvoke(New MethodInvoker(AddressOf findDialog))
        End If
    End If

End Sub

Private Function checkWindow(hWnd As IntPtr, lp As IntPtr) As Boolean

    ' Checks if <hWnd> is a dialog
    Dim sb As New StringBuilder(260)
    NativeMethods.GetClassName(hWnd, sb, sb.Capacity)
    If sb.ToString() <> "#32770" Then
        Return True
    End If


    ' Got it
    Dim frmRect As New Rectangle(mOwner.Location, mOwner.Size)
    Dim dlgRect As NativeMethods.RECT
    NativeMethods.GetWindowRect(hWnd, dlgRect)
    NativeMethods.MoveWindow(hWnd, frmRect.Left + (frmRect.Width - dlgRect.Right + dlgRect.Left) \ 2, frmRect.Top + (frmRect.Height - dlgRect.Bottom + dlgRect.Top) \ 2, dlgRect.Right - dlgRect.Left, dlgRect.Bottom - dlgRect.Top, True)

    ' Dim wndText As New StringBuilder()
    ' NativeMethods.GetWindowText(hWnd2, wndText, 1000)
    ' SendMessage(hWnd2, WM_SETFONT, f.ToHfont(), new IntPtr(1))

    Return False

End Function

Public Sub Dispose() Implements IDisposable.Dispose
    mTries = -1
End Sub

End Class

UPDATE 2:

This is an explanation of what I need to do.

Taking the code snippet of @Hans Passant, the centered messagebox, I need to launch it (instance it) but with a custom font.

An example could be creating a generic function into the Centered Messagebox maybe using the "new" block of the Class to pass the desired font as an argument then do the necessary things with that font to show the messagebox centered + with a custom font.

So what I need is to extend the class by adding the possibility of using custom fonts.

Community
  • 1
  • 1
ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
  • You are violating this site's license, you cannot copy somebody's answer without attribution. I already answered this question, you copied the wrong code. – Hans Passant Oct 09 '13 at 17:56
  • @Hans Passant I can't believe what you have said me, the code is a snippet that I've posted too much time ago in this question of me: stackoverflow.com/questions/15904610/show-a-messagebox-centered-in-form , the code is not mine but obviouslly I do not know which the original code is, I do not have any way to know if the code is from a StackOverflow answer or is not or who is the author to make attribution, how do you expect I need to search entire Google results to find the author of an snippet? just I can't believe this, I respect you too much but this is not serious. Forgive my English. – ElektroStudios Oct 09 '13 at 20:46
  • Linking to another post of yours where you also violated the license is not sufficient. Clearly you had no trouble finding the code originally, it is linked in that question as a duplicate. You must correct these mistakes. – Hans Passant Oct 09 '13 at 20:51
  • Oh I can understand what you are saying now, I see that I've translated code which is yours, of course you need to understand that passed much time ago when I did that question to today, I'm not able to remember you or anybody else were the author , I will agregate attribution of you of course 'cause now I know it by reading the comments of the post that i've linked. forgive my english and understand what I've said please – ElektroStudios Oct 09 '13 at 20:52
  • You should attribute code in comments, even when using it in your own personal applications. If for no other reason than to be able to go back to where you got it, if you need to. But also, if it ever gets used in any business applications (or re-posted online) it needs to be attributed as well. – Pete Oct 09 '13 at 20:56
  • @Pete thanks for your comprenssive, there is no reason to think strange things, I just putted "centered messagebox" in SO searcher when I readed Hans passant comment to try to understand what is happening and to correct my fault. If I did not copied that information when I translated the code is just because I was newbie (more newbie) without experience, you have reason with that. – ElektroStudios Oct 09 '13 at 20:58
  • 1
    I understand. It happens. Simply pointing out that it's good practice to always attribute code for your personal use because you never know when you'll need the info. I always put the URL in a comment and I've frequently found myself using those URLs to go back to the source. – Pete Oct 09 '13 at 21:03
  • @Hans Passant I will only say to you that maybe you can't know it but you are a God of programming for me, people need to respect Gods, also you have helped me much times, if I could remember that you (or anybody else) was the author of that snippet I ensure you that I would wrote the attribution of you, sorry for my faults. – ElektroStudios Oct 09 '13 at 21:27
  • You'll have to pick another one, I don't want that job. Thanks for taking care of it. – Hans Passant Oct 09 '13 at 21:28

3 Answers3

3

I already answered this question, the answer is here. You just need to tweak is slightly since you are not interested in changing the existing font:

if (hText != IntPtr.Zero) {
  // Get the current font
  IntPtr hFont = SendMessage(hText, WM_GETFONT, IntPtr.Zero, IntPtr.Zero);
  Font font = Font.FromHfont(hFont);
  mFont = new Font(new FontFamily("Arial"), font.SizeInPoints, FontStyle.Normal);
  SendMessage(hText, WM_SETFONT, mFont.ToHfont(), (IntPtr)1);
}

Only the 5th line is different. Change the font family you want. The same basic problem with this code, although not nearly as severe, the new font you pick must fit the calculated size of the static control. A calculation that was made for the original font. If your new font is "wide" then it won't fit, reducing the SizeInPoints is the only workaround.

Community
  • 1
  • 1
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Thankyou, that's why you are a God even if you won't. Finally I could merge both MessageBox Class versions to get what I need, thanks again and really sorry about the attribution. – ElektroStudios Oct 09 '13 at 22:19
  • Could you guide me in easy words how I can start trying by myself to fix the problem for big font sizes? I mean is there any P/Invoke function I could use for example to change the size of MessageBox window?, knowing that would be sufficient, thanks. – ElektroStudios Oct 09 '13 at 22:26
  • Really by any of the ways?, then to don't investigate and to don't try hard things, you are saying that the UNIQUE solution would be creating an own form to change the form size? are you saying that there is really no way to fix it using the messagebox default class?. I'm sorry for my insistence 'cause I'm glad of my faults and I can't ask you for more, but really I need to be totally secure of what I can try and what I can't. – ElektroStudios Oct 09 '13 at 22:39
  • 1
    http://meta.stackexchange.com/questions/43478/exit-strategies-for-chameleon-questions – Hans Passant Oct 13 '13 at 11:10
  • @Hand Passant no need to do that, that is too offensive for me and for all other people who ask a question. I've only asked you that if do you know a way to resize the messagebox window, I think is no necessary to create a new question just for ask something what you can answer me in only a few words in a comment 'cause what I've asked is related to your answer, and also I've accepted your answer before asking that, I think I'm not a chamaleon. – ElektroStudios Oct 13 '13 at 11:30
  • anyways I hope that if you can answer me to ensure me that does not exists any way to resize the messagebox default window, if you preffer I can create a new question but just I was looking for a "yes" or "no" from an expert like you are. – ElektroStudios Oct 13 '13 at 11:34
  • Here is my new question about this if someone could help me: http://stackoverflow.com/questions/19397549/which-is-the-mathematic-formula-to-calculate-the-size-and-positions-for-this-win – ElektroStudios Oct 16 '13 at 07:45
1

First of all, I apologize for my answer not being in VB (Update - Ran the code through a C# to VB converter). Surely you can read C# well enough to make sense of this and I will happily answer any questions you have about it.

This solution is not generic, in terms of how you go about finding the window and the static control. You'll need to adapt it to your own situation, but the important piece about how to set the font is reusable.

The Thread.Sleep() at the beginning of the thread is a little arbitrary. You'll probably want to wait a bit (a half second is surely too long), but it will take time for the message box to be displayed and the message box will block execution. So, I fire off the thread, have it wait until the message box is definitely open, and then I start looking for it.

Also, be sure to call DeleteObject() on the HFont eventually.

Public Partial Class Form1
    Inherits Form
    Private Const WM_SETFONT As UInt32 = &H30

    Private Delegate Function EnumThreadDelegate(hwnd As IntPtr, lParam As IntPtr) As Boolean
    Private Delegate Function EnumWindowsProc(hWnd As IntPtr, lParam As IntPtr) As Boolean

    <DllImport("user32.dll")> _
    Private Shared Function EnumThreadWindows(dwThreadId As UInteger, lpfn As EnumThreadDelegate, lParam As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
    End Function

    <DllImport("kernel32.dll")> _
    Private Shared Function GetCurrentThreadId() As UInteger
    End Function

    <DllImport("user32.dll", SetLastError := True, CharSet := CharSet.Auto)> _
    Private Shared Function GetClassName(hWnd As IntPtr, lpClassName As StringBuilder, nMaxCount As Integer) As Integer
    End Function

    <DllImport("user32.dll")> _
    Private Shared Function EnumChildWindows(hwndParent As IntPtr, lpEnumFunc As EnumWindowsProc, lParam As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
    End Function

    <DllImport("user32.dll", CharSet := CharSet.Auto, SetLastError := True)> _
    Private Shared Function GetWindowText(hWnd As IntPtr, lpString As StringBuilder, nMaxCount As Integer) As Integer
    End Function

    <DllImport("user32.dll", CharSet := CharSet.Auto)> _
    Private Shared Function SendMessage(hWnd As IntPtr, Msg As UInt32, wParam As IntPtr, lParam As IntPtr) As IntPtr
    End Function

    Shared threadId As UInteger = GetCurrentThreadId()

    Public Sub New()
        InitializeComponent()
    End Sub

    Private Sub button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim t As New Thread(New ThreadStart(AddressOf FixMsgBoxFont))
        t.Start()
        MessageBox.Show(Me, "MyMsg", "Test")
    End Sub

    Private Sub FixMsgBoxFont()
        Thread.Sleep(500)
        EnumThreadWindows(threadId, New EnumThreadDelegate(Function(hWnd, lParam) 
        Dim className As New StringBuilder()
        GetClassName(hWnd, className, 1000)

        ' Look for the message box window
        If className.ToString() <> "#32770" Then
            Return True
        End If

        EnumChildWindows(hWnd, New EnumWindowsProc(Function(hWnd2, lParam2) 
        Dim wndText As New StringBuilder()
        GetWindowText(hWnd2, wndText, 1000)

        ' Look for the static control with our text
        If wndText.ToString() = "MyMsg" Then
            ' Replace the font being used with 8pt Comix Sans MS
            Dim f As New Font(New FontFamily("Comic Sans MS"), 8, FontStyle.Bold, GraphicsUnit.Pixel)

            ' In real life, you'll eventually want to eventually call 
            ' the Windows API DeleteObject() on the font handle
            ' below or it will leak.
            Dim fontHandle As IntPtr = f.ToHfont()
            SendMessage(hWnd2, WM_SETFONT, f.ToHfont(), New IntPtr(1))
            Return False
        End If
        Return True

End Function), IntPtr.Zero)

        Return False

End Function), IntPtr.Zero)
    End Sub
End Class
Pete
  • 6,585
  • 5
  • 43
  • 69
  • Really thankyou, but I think that your work cannot help me too much, the reason is I have nothing to do with a complex C# code. – ElektroStudios Oct 09 '13 at 19:29
  • Trying to understand the code I think you will wait "X" amount of time (500 ms) to check one time for the messagebox to be displayed, I think this is a insecure method because what's up with really slow pc's or the big delay that happens when OS is performing big operations? the msgbox can be displayed passed 10-20 or more seconds. trying to understand more (I can't at all) I think you will get the class name of the messagebox window to retrieve the text and replace it sending a windows message, maybe this part would be reusable as you have said, but I can't find the way to adapt it in VB. thx – ElektroStudios Oct 09 '13 at 19:33
  • @ElektroHacker There you go. Now in VB. – Pete Oct 09 '13 at 19:35
  • 1
    @ElektroHacker There are alternative methods for handling that. You can run a thread that simply keeps looking until the window shows up. And if you need an example of how to do that, please post a question here on SO and I'll be happy to take a stab at that. I can't imagine it taking more than half a second for a message box to be displayed. 20 some odd years of using windows, I've NEVER seen it take that long. – Pete Oct 09 '13 at 19:37
  • (Comment deleted, I did not noticed that is no generic and works launching a new thread from a button) I can't find the way to adapt the "FixMsgBoxFont" part where I'm interested to the original custom MessageBox that I've posted, that's what I've asked for, really thank you so much for your time, I will try it by myself, and If I get it then I will mark this usefull answer. thx again and forgive my english – ElektroStudios Oct 09 '13 at 19:48
  • I don't understand your comment. The code I posted does what you originally asked. You asked if there's a way to display a message box using an alternate font that didn't require creating a new MessageBox class. I provided a working example in C# and VB. If create a VB winforms app, drop a button on it, and then paste this code in to the form class, it works. – Pete Oct 09 '13 at 20:02
  • Hello, please let me explain. I did not asked about not creating a new messagebox Class, What I do not will is to create a custom form to simulate a messagebox window. I know you did a great job and don't confuse you, I'm too grateful with that, but I clearly asked about how to integrate a font-function in that messagebox, but while I can't solve it trying to adapt the piece of code that you wrote into the Centered Messagebox of @Hans passant then I can't say this is really solved. I'm not asking you to do more of what you did, really I'm trying to do it by myself at this point,thank you again – ElektroStudios Oct 09 '13 at 21:08
  • Sorry, I'm just not understanding what you're asking for. So I guess if I can't understand what you want, I can't answer your question the way you want it answered. I'm not sure anyone is going to be able to answer it without a clearer explanation of what you want. – Pete Oct 09 '13 at 21:16
  • Then sorry for all of my language faults, I hope you can understand now what I need if you could read the last update I did in my question. while I'll be fighting with the "EnumChildWindows" API function, thanks again. – ElektroStudios Oct 09 '13 at 21:23
  • Here is my new question about this if someone could help me: http://stackoverflow.com/questions/19397549/which-is-the-mathematic-formula-to-calculate-the-size-and-positions-for-this-win – ElektroStudios Oct 16 '13 at 07:45
0

Here is the code!

It has the font-size problem which I need to resolve but by now this is solved!

' The author of this code is Hand Passant: 
' http://stackoverflow.com/questions/2259027/bold-text-in-messagebox/2259213#2259213
'
' I've just translated it to VB.NET and made very little modifications.

Imports System.Drawing
Imports System.Runtime.InteropServices
Imports System.Text
Imports System.Windows.Forms

Class CustomMessageBox : Implements IDisposable

Private mTries As Integer = 0
Private mOwner As Form
Private mFont As Font

' P/Invoke declarations
Private Const WM_SETFONT As Integer = &H30
Private Const WM_GETFONT As Integer = &H31

Private Delegate Function EnumThreadWndProc(hWnd As IntPtr, lp As IntPtr) As Boolean

<DllImport("user32.dll")> _
Private Shared Function EnumThreadWindows(tid As Integer, callback As EnumThreadWndProc, lp As IntPtr) As Boolean
End Function

<DllImport("kernel32.dll")> _
Private Shared Function GetCurrentThreadId() As Integer
End Function

<DllImport("user32.dll")> _
Private Shared Function GetClassName(hWnd As IntPtr, buffer As StringBuilder, buflen As Integer) As Integer
End Function

<DllImport("user32.dll")> _
Private Shared Function GetDlgItem(hWnd As IntPtr, item As Integer) As IntPtr
End Function

<DllImport("user32.dll")> _
Private Shared Function SendMessage(hWnd As IntPtr, msg As Integer, wp As IntPtr, lp As IntPtr) As IntPtr
End Function

<DllImport("user32.dll")> _
Shared Function GetWindowRect(hWnd As IntPtr, ByRef rc As RECT) As Boolean
End Function

<DllImport("user32.dll")> _
Shared Function MoveWindow(hWnd As IntPtr, x As Integer, y As Integer, w As Integer, h As Integer, repaint As Boolean) As Boolean
End Function

Structure RECT
    Public Left As Integer
    Public Top As Integer
    Public Right As Integer
    Public Bottom As Integer
End Structure

Public Sub New(owner As Form, Optional Custom_Font As Font = Nothing)
    mOwner = owner
    mFont = Custom_Font
    owner.BeginInvoke(New MethodInvoker(AddressOf findDialog))
End Sub

Private Sub findDialog()

    ' Enumerate windows to find the message box
    If mTries < 0 Then
        Return
    End If

    Dim callback As New EnumThreadWndProc(AddressOf checkWindow)

    If EnumThreadWindows(GetCurrentThreadId(), callback, IntPtr.Zero) Then
        If System.Threading.Interlocked.Increment(mTries) < 10 Then
            mOwner.BeginInvoke(New MethodInvoker(AddressOf findDialog))
        End If
    End If

End Sub

Private Function checkWindow(hWnd As IntPtr, lp As IntPtr) As Boolean

    ' Checks if <hWnd> is a dialog
    Dim sb As New StringBuilder(260)
    GetClassName(hWnd, sb, sb.Capacity)
    If sb.ToString() <> "#32770" Then Return True

    ' Got it, get the STATIC control that displays the text
    Dim hText As IntPtr = GetDlgItem(hWnd, &HFFFF)

    Dim frmRect As New Rectangle(mOwner.Location, mOwner.Size)
    Dim dlgRect As RECT
    GetWindowRect(hWnd, dlgRect)
    MoveWindow(hWnd, frmRect.Left + (frmRect.Width - dlgRect.Right + dlgRect.Left) \ 2, frmRect.Top + (frmRect.Height - dlgRect.Bottom + dlgRect.Top) \ 2, dlgRect.Right - dlgRect.Left, dlgRect.Bottom - dlgRect.Top, True)
    If hText <> IntPtr.Zero Then

        If mFont Is Nothing Then
            ' Get the current font
            mFont = Font.FromHfont(SendMessage(hText, WM_GETFONT, IntPtr.Zero, IntPtr.Zero))
        End If

        SendMessage(hText, WM_SETFONT, mFont.ToHfont(), New IntPtr(1))

    End If

    ' Done
    Return False

End Function

Public Sub Dispose() Implements IDisposable.Dispose
    mTries = -1
    mOwner = Nothing
    If mFont IsNot Nothing Then mFont.Dispose()
End Sub

End Class

Usage:

Using New CustomMessageBox(Me, New Font(New FontFamily("Lucida Console"), Font.SizeInPoints, FontStyle.Bold))
    MessageBox.Show("Test Text", "Test Title", MessageBoxButtons.OK)
End Using
ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
  • When i increased the font size to 14. Some lines are not visible. I have 3 lines in the Message to Show ? – Er Mayank Sep 01 '15 at 10:00