PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
msg box positioning-VBForums
Results 1 to 7 of 7

Thread: msg box positioning

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2006
    Posts
    55

    msg box positioning

    hi, total newbie here but when i make a command button and it pops up the msg box is always in the center, is there a way i can change the coordinates or positioning on the msgbox? Any help would be appreciated thankyou

  2. #2
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: msg box positioning

    Welcome to the forums.

    Right beneath this thread is another thread with the exact same question. (Kind of odd having the same question posted by two different people almost at the same time. )

    Basically, the easiest and quickest way is to make your own msgbox out of a standard VB form (I haven't acutally used the VB msgbox is years). You have a lot more control over every aspect of it including what you want for buttons.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  3. #3
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,426

    Re: msg box positioning

    Take a look Here

  4. #4
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: msg box positioning

    Quote Originally Posted by jcis
    Take a look Here
    LOL...I kind of figured the code would be pretty savage. Making your own is much easier and gives you a lot more flexibility.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  5. #5
    Addicted Member
    Join Date
    Nov 2005
    Posts
    152

    Re: msg box positioning

    hi all,

    i had posted same question yesterday, and i got the answer of this question

    create one Module (basMsgBoxEx.bas) as follows
    VB Code:
    1. ''''''''''''Start Of basMsgBoxEx.bas file ''''''''''
    2. ' MsgBoxEx.bas
    3. '
    4. Option Explicit
    5.  
    6. Private Const NV_CLOSEMSGBOX = &H5000&
    7. Private Const NV_MOVEMSGBOX = &H5001&
    8. Private Const HWND_TOPMOST = -1
    9. Private Const SWP_NOSIZE = &H1
    10.  
    11. Private Type RECT
    12.     Left As Long
    13.     Top As Long
    14.     Right As Long
    15.     Bottom As Long
    16. End Type
    17. Private Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long, _
    18.     ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
    19. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    20.     (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    21. Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, _
    22.     ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, _
    23.     ByVal cy As Long, ByVal wFlags As Long) As Long
    24. Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
    25. Private Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, _
    26.     ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
    27. Private Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, _
    28.     ByVal nIDEvent As Long) As Long
    29. Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    30.  
    31. Private mTitle As String
    32. Private mX As Long
    33. Private mY As Long
    34. Private mPause As Long
    35. Private mHandle As Long
    36.  
    37. Public Function MsgBoxMove(ByVal hwnd As Long, ByVal inPrompt As String, _
    38.         ByVal inTitle As String, ByVal inButtons As Long, _
    39.                ByVal inX As Long, ByVal inY As Long) As Integer
    40.      mTitle = inTitle: mX = inX:  mY = inY
    41.      SetTimer hwnd, NV_MOVEMSGBOX, 0&, AddressOf NewTimerProc
    42.      MsgBoxMove = MessageBox(hwnd, inPrompt, inTitle, inButtons)
    43. End Function
    44.  
    45. Public Function MsgBoxPause(ByVal hwnd As Long, ByVal inPrompt As String, _
    46.         ByVal inTitle As String, ByVal inButtons As Long, _
    47.         ByVal inPause As Integer) As Integer
    48.      mTitle = inTitle: mPause = inPause * 1000
    49.      SetTimer hwnd, NV_CLOSEMSGBOX, mPause, AddressOf NewTimerProc
    50.      MsgBoxPause = MessageBox(hwnd, inPrompt, inTitle, inButtons)
    51. End Function
    52.  
    53. Public Function NewTimerProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wparam As Long, _
    54.         ByVal lparam As Long) As Long
    55.     KillTimer hwnd, wparam
    56.     Select Case wparam
    57.          Case NV_CLOSEMSGBOX
    58.               ' A system class is a window class registered by the system which cannot
    59.               ' be destroyed by a processed, e.g. #32768 (a menu), #32769 (desktop
    60.               ' window), #32770 (dialog box), #32771 (task switch window).
    61.              mHandle = FindWindow("#32770", mTitle)
    62.              If mHandle <> 0 Then
    63.                   SetForegroundWindow mHandle
    64.                   SendKeys "{enter}"
    65.              End If
    66.              
    67.         Case NV_MOVEMSGBOX
    68.              mHandle = FindWindow("#32770", mTitle)
    69.              If mHandle <> 0 Then
    70.                   Dim w As Single, h As Single
    71.                   Dim mBox As RECT
    72.                   w = Screen.Width / Screen.TwipsPerPixelX
    73.                   h = Screen.Height / Screen.TwipsPerPixelY
    74.                   GetWindowRect mHandle, mBox
    75.                   If mX > (w - (mBox.Right - mBox.Left) - 1) Then mX = (w - (mBox.Right - mBox.Left) - 1)
    76.                   If mY > (h - (mBox.Bottom - mBox.Top) - 1) Then mY = (h - (mBox.Bottom - mBox.Top) - 1)
    77.                   If mX < 1 Then mX = 1: If mY < 1 Then mY = 1
    78.                     ' SWP_NOSIZE is to use current size, ignoring 3rd & 4th parameters.
    79.                   SetWindowPos mHandle, HWND_TOPMOST, mX, mY, 0, 0, SWP_NOSIZE
    80.              End If
    81.     End Select
    82. End Function
    Now use this code where you want

    suppose if you want to use the message box on your form then add this basMsgBoxEx.bas file in module and write following code.
    VB Code:
    1. mResult = MsgBoxMove(hwnd, "Message which you want to show on messagebox ", "Header of MsgBox ", vbOKOnly + vbInformation, x( Xposition), y (Yposition))

    enjoy,











    Edit: Added [vbcode][/vbcode] tags for more clarity. - Hack
    Last edited by Hack; Jan 12th, 2006 at 07:05 AM.

  6. #6
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,415

    Re: msg box positioning

    I saw This on Google by CodeGuru. I haven't tried it but I'm going to. Looks fairly short and simple and has an example project with it.

    edited:

    I tried it out. It is similar to what was already posted and there is a lot of code behind it.

    Last edited by TysonLPrice; Jan 12th, 2006 at 07:22 AM.

  7. #7
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: msg box positioning

    Even though its a little late, may be helpful. Aaron Young posted that same code on VBF 4 years before the CG article

    http://www.vbforums.com/showpost.php...58&postcount=4

    And extended by manavo11 here -
    http://www.vbforums.com/showthread.php?t=329373
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width