elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Introducción a la Factorización De Semiprimos (RSA)


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  ¿Cómo puedo insertar un listbox en un messagebox? VB.NET 2010
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: ¿Cómo puedo insertar un listbox en un messagebox? VB.NET 2010  (Leído 1,820 veces)
Yaldabaot

Desconectado Desconectado

Mensajes: 186


Ver Perfil
¿Cómo puedo insertar un listbox en un messagebox? VB.NET 2010
« en: 27 Noviembre 2014, 19:38 pm »

Hola, mi pregunta es la siguiente necesito meter un listbox DENTRO de un messagebox, no quiero meter el contenido, quiero meter todo el listbox en el messagebox con su contenido

¿Se podría hacerlo?.

Gracias



En línea

Nunca me contestan -_-
Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.709



Ver Perfil
Re: ¿Cómo puedo insertar un listbox en un messagebox? VB.NET 2010
« Respuesta #1 en: 27 Noviembre 2014, 22:41 pm »

Un MessageBox no es más que un diálogo, y como tal puedes hallar el handle (hwnd) de su ventana principal, redimensionar la ventana y enumerar sus controles para quizás hacer lo mismo y dejar espacio para tu nuevo control, por ende puedes posicionar "X" control relativamente en el rectangle de dicho dialog.

Pero esa idea es una locura, lo mejor es que hagas un nuevo Form y lo personalices de forma manual con el aspecto típico de un MessageBox (hay muchos ejemplos en Google) y allí añadas los controles que desees, y luego utilices ese Form como un Dialog, ya que un MessageBox puede ser cambiado o extendido, sí, pero es una pesadilla ya que requiere bastante esfuerzo y mucho P/Invoking para realizar pequeñas modificaciones, de todas formas te muestro un ejemplo que desarrollé donde deberías poder encontrar todo lo necesario para tus intenciones, pero como ya dije, no te recomiendo este enfoque para tus necesidades:

Código
  1. ' ***********************************************************************
  2. ' Author   : Elektro
  3. ' Modified : 27-November-2014
  4. ' ***********************************************************************
  5. ' <copyright file="CenteredMessageBox.vb" company="Elektro Studios">
  6. '     Copyright (c) Elektro Studios. All rights reserved.
  7. ' </copyright>
  8. ' ***********************************************************************
  9.  
  10. #Region " Usage Examples "
  11.  
  12. 'Using New CenteredMessageBox(ownerForm:=Me,
  13. '                             textFont:=New Font("Lucida Console", Font.SizeInPoints, FontStyle.Bold),
  14. '                             timeOut:=2500)
  15. '
  16. '    MessageBox.Show("Text", "Title", MessageBoxButtons.OK, MessageBoxIcon.Information)
  17. '
  18. 'End Using
  19.  
  20. #End Region
  21.  
  22. #Region " Option Statements "
  23.  
  24. Option Explicit On
  25. Option Strict On
  26. Option Infer Off
  27.  
  28. #End Region
  29.  
  30. #Region " Imports "
  31.  
  32. Imports System.Drawing
  33. Imports System.Runtime.InteropServices
  34. Imports System.Text
  35. Imports System.Windows.Forms
  36. Imports System.ComponentModel
  37.  
  38. #End Region
  39.  
  40. #Region " Centered MessageBox "
  41.  
  42. Namespace Tools
  43.  
  44.    ''' <summary>
  45.    ''' A customized <see cref="MessageBox"/>.
  46.    ''' This class cannot be inherited.
  47.    ''' </summary>
  48.    Friend NotInheritable Class CenteredMessageBox : Implements IDisposable
  49.  
  50. #Region " Properties "
  51.  
  52.        ''' <summary>
  53.        ''' Gets the messagebox main window handle (hwnd).
  54.        ''' </summary>
  55.        ''' <value>The messagebox main window handle (hwnd).</value>
  56.        Friend ReadOnly Property MessageBoxWindowHandle As IntPtr
  57.            Get
  58.                Return Me.messageBoxWindowHandle1
  59.            End Get
  60.        End Property
  61.        ''' <summary>
  62.        ''' The messagebox main window handle (hwnd).
  63.        ''' </summary>
  64.        Private messageBoxWindowHandle1 As IntPtr
  65.  
  66.        ''' <summary>
  67.        ''' Gets the owner <see cref="Form"/> to center the <see cref="CenteredMessageBox"/>.
  68.        ''' </summary>
  69.        ''' <value>The owner <see cref="Form"/> to center the <see cref="CenteredMessageBox"/>.</value>
  70.        Friend ReadOnly Property OwnerForm As Form
  71.            Get
  72.                Return Me.ownerForm1
  73.            End Get
  74.        End Property
  75.        ''' <summary>
  76.        ''' The owner <see cref="Form"/> to center the <see cref="CenteredMessageBox"/>
  77.        ''' </summary>
  78.        Private ownerForm1 As Form
  79.  
  80.        ''' <summary>
  81.        ''' Gets the <see cref="Font"/> used to display the <see cref="CenteredMessageBox"/> text.
  82.        ''' </summary>
  83.        ''' <value>The <see cref="Font"/> used to display the <see cref="CenteredMessageBox"/> text.</value>
  84.        Friend ReadOnly Property Font As Font
  85.            Get
  86.                Return Me.font1
  87.            End Get
  88.        End Property
  89.        ''' <summary>
  90.        ''' The <see cref="Font"/> used to display the <see cref="CenteredMessageBox"/> text.
  91.        ''' </summary>
  92.        Private ReadOnly font1 As Font
  93.  
  94.        ''' <summary>
  95.        ''' Gets the time interval to auto-close this <see cref="CenteredMessageBox"/>, in milliseconds.
  96.        ''' Default value is '0', which means Infinite.
  97.        ''' </summary>
  98.        Friend ReadOnly Property TimeOut As Integer
  99.            Get
  100.                Return Me.timeOut1
  101.            End Get
  102.        End Property
  103.        ''' <summary>
  104.        ''' The time interval to auto-close this <see cref="CenteredMessageBox"/>, in milliseconds.
  105.        ''' Default value is '0', which means Infinite.
  106.        ''' </summary>
  107.        Private ReadOnly timeOut1 As Integer = 0
  108.  
  109. #End Region
  110.  
  111. #Region " Objects "
  112.  
  113.        ''' <summary>
  114.        ''' A <see cref="Windows.Forms.Timer"/> that keeps track of <see cref="TimeOut"/> value to close this <see cref="CenteredMessageBox"/>.
  115.        ''' </summary>
  116.        Private WithEvents timeoutTimer As Timer
  117.  
  118.        ''' <summary>
  119.        ''' Keeps track of the current amount of tries to find this <see cref="CenteredMessageBox"/> dialog.
  120.        ''' </summary>
  121.        Private tries As Integer
  122.  
  123. #End Region
  124.  
  125. #Region " P/Invoke "
  126.  
  127.        ''' <summary>
  128.        ''' Platform Invocation methods (P/Invoke), access unmanaged code.
  129.        ''' This class does not suppress stack walks for unmanaged code permission.
  130.        ''' <see cref="System.Security.SuppressUnmanagedCodeSecurityAttribute"/>  must not be applied to this class.
  131.        ''' This class is for methods that can be used anywhere because a stack walk will be performed.
  132.        ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/ms182161.aspx
  133.        ''' </summary>
  134.        Protected NotInheritable Class NativeMethods
  135.  
  136. #Region " Functions "
  137.  
  138.            ''' <summary>
  139.            ''' Retrieves the thread identifier of the calling thread.
  140.            ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/ms683183%28v=vs.85%29.aspx
  141.            ''' </summary>
  142.            ''' <returns>The thread identifier of the calling thread.</returns>
  143.            <DllImport("kernel32.dll", SetLastError:=False)>
  144.            Protected Friend Shared Function GetCurrentThreadId() As Integer
  145.            End Function
  146.  
  147.            ''' <summary>
  148.            ''' Enumerates all nonchild windows associated with a thread by passing the handle to each window,
  149.            ''' in turn, to an application-defined callback function.
  150.            ''' <see cref="EnumThreadWindows"/> continues until the last window is enumerated or the callback function returns <c>false</c>.
  151.            ''' To enumerate child windows of a particular window, use the EnumChildWindows function.
  152.            ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/ms633495%28v=vs.85%29.aspx
  153.            ''' </summary>
  154.            ''' <param name="dwThreadId">The identifier of the thread whose windows are to be enumerated.</param>
  155.            ''' <param name="lpfn">A pointer to an application-defined callback function.</param>
  156.            ''' <param name="lParam">An application-defined value to be passed to the callback function.</param>
  157.            ''' <returns>
  158.            ''' <c>true</c> if the callback function returns <c>true</c> for all windows in the thread specified by dwThreadId parameter.
  159.            ''' <c>false</c> if the callback function returns <c>false</c> on any enumerated window,
  160.            ''' or if there are no windows found in the thread specified by dwThreadId parameter.</returns>
  161.            <DllImport("user32.dll", SetLastError:=False)>
  162.            Protected Friend Shared Function EnumThreadWindows(
  163.                      ByVal dwThreadId As Integer,
  164.                      ByVal lpfn As NativeMethods.EnumThreadWndProc,
  165.                      ByVal lParam As IntPtr
  166.            ) As <MarshalAs(UnmanagedType.Bool)> Boolean
  167.            End Function
  168.  
  169.            ''' <summary>
  170.            ''' Retrieves the name of the class to which the specified window belongs.
  171.            ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/ms633582%28v=vs.85%29.aspx
  172.            ''' </summary>
  173.            ''' <param name="hWnd">A handle to the window and, indirectly, the class to which the window belongs.</param>
  174.            ''' <param name="buffer">The class name string.</param>
  175.            ''' <param name="buflen">
  176.            ''' The length of the lpClassName buffer, in characters.
  177.            ''' The buffer must be large enough to include the terminating null character;
  178.            ''' otherwise, the class name string is truncated to nMaxCount-1 characters.
  179.            ''' </param>
  180.            ''' <returns>
  181.            ''' If the function succeeds, the return value is the number of characters copied to the buffer,
  182.            ''' not including the terminating null character.
  183.            ''' If the function fails, the return value is 0.
  184.            ''' </returns>
  185.            <DllImport("user32.dll", SetLastError:=False, CharSet:=CharSet.Unicode)>
  186.            Protected Friend Shared Function GetClassName(
  187.                      ByVal hWnd As IntPtr,
  188.                      ByVal buffer As StringBuilder,
  189.                      ByVal buflen As Integer
  190.            ) As Integer
  191.            End Function
  192.  
  193.            ''' <summary>
  194.            ''' Retrieves a handle to a control in the specified dialog box.
  195.            ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/ms645481%28v=vs.85%29.aspx
  196.            ''' </summary>
  197.            ''' <param name="hWnd">A handle to the dialog box that contains the control.</param>
  198.            ''' <param name="item">The identifier of the control to be retrieved.</param>
  199.            ''' <returns>
  200.            ''' If the function succeeds, the return value is the window handle of the specified control.
  201.            ''' If the function fails, the return value is <see cref="IntPtr.Zero"/>,
  202.            ''' indicating an invalid dialog box handle or a nonexistent control
  203.            ''' </returns>
  204.            <DllImport("user32.dll", SetLastError:=False)>
  205.            Protected Friend Shared Function GetDlgItem(
  206.                      ByVal hWnd As IntPtr,
  207.                      ByVal item As Integer
  208.            ) As IntPtr
  209.            End Function
  210.  
  211.            ''' <summary>
  212.            ''' Retrieves the dimensions of the bounding rectangle of the specified window.
  213.            ''' The dimensions are given in screen coordinates that are relative to the upper-left corner of the screen.
  214.            ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/ms633519%28v=vs.85%29.aspx
  215.            ''' </summary>
  216.            ''' <param name="hWnd">A handle to the window.</param>
  217.            ''' <param name="rc">
  218.            ''' A pointer to a <see cref="RECT"/> structure that receives the screen coordinates of
  219.            ''' the upper-left and lower-right corners of the window.
  220.            ''' </param>
  221.            ''' <returns><c>true</c> if the function succeeds, <c>false</c> otherwise.</returns>
  222.            <DllImport("user32.dll", SetLastError:=False)>
  223.            Protected Friend Shared Function GetWindowRect(
  224.                      ByVal hWnd As IntPtr,
  225.                      ByRef rc As Rect
  226.            ) As <MarshalAs(UnmanagedType.Bool)> Boolean
  227.            End Function
  228.  
  229.            ''' <summary>
  230.            ''' Destroys the specified window.
  231.            ''' The function sends WM_DESTROY and WM_NCDESTROY messages to the window to deactivate it and remove the keyboard focus from it.
  232.            ''' The function also destroys the window's menu, flushes the thread message queue, destroys timers, removes clipboard ownership,
  233.            ''' and breaks the clipboard viewer chain (if the window is at the top of the viewer chain).
  234.            ''' If the specified window is a parent or owner window,
  235.            ''' DestroyWindow automatically destroys the associated child or owned windows when it destroys the parent or owner window.
  236.            ''' The function first destroys child or owned windows, and then it destroys the parent or owner window.
  237.            ''' DestroyWindow also destroys modeless dialog boxes created by the CreateDialog function.
  238.            ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/ms632682%28v=vs.85%29.aspx
  239.            ''' </summary>
  240.            ''' <param name="hwnd">Handle to the window to be destroyed.</param>
  241.            ''' <returns><c>true</c> if the function succeeds, <c>false</c> otherwise.</returns>
  242.            <DllImport("user32.dll", SetLastError:=False)>
  243.            Protected Friend Shared Function DestroyWindow(
  244.                      ByVal hwnd As IntPtr
  245.            ) As <MarshalAs(UnmanagedType.Bool)> Boolean
  246.            End Function
  247.  
  248.            ''' <summary>
  249.            ''' Changes the position and dimensions of the specified window.
  250.            ''' For a top-level window, the position and dimensions are relative to the upper-left corner of the screen.
  251.            ''' For a child window, they are relative to the upper-left corner of the parent window's client area.
  252.            ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/ms633534%28v=vs.85%29.aspx
  253.            ''' </summary>
  254.            ''' <param name="hWnd">A handle to the window.</param>
  255.            ''' <param name="x">The new position of the left side of the window.</param>
  256.            ''' <param name="y">The new position of the top of the window.</param>
  257.            ''' <param name="width">The new width of the window.</param>
  258.            ''' <param name="height">The new height of the window.</param>
  259.            ''' <param name="repaint">
  260.            ''' Indicates whether the window is to be repainted.
  261.            ''' If this parameter is TRUE, the window receives a message.
  262.            ''' If the parameter is FALSE, no repainting of any kind occurs.
  263.            ''' This applies to the client area, the nonclient area (including the title bar and scroll bars),
  264.            ''' and any part of the parent window uncovered as a result of moving a child window.
  265.            ''' </param>
  266.            ''' <returns><c>true</c> if the function succeeds, <c>false</c> otherwise.</returns>
  267.            <DllImport("user32.dll", SetLastError:=False)>
  268.            Protected Friend Shared Function MoveWindow(
  269.                      ByVal hWnd As IntPtr,
  270.                      ByVal x As Integer,
  271.                      ByVal y As Integer,
  272.                      ByVal width As Integer,
  273.                      ByVal height As Integer,
  274.                      ByVal repaint As Boolean
  275.            ) As <MarshalAs(UnmanagedType.Bool)> Boolean
  276.            End Function
  277.  
  278.            ''' <summary>
  279.            ''' Changes the size, position, and Z order of a child, pop-up, or top-level window.
  280.            ''' These windows are ordered according to their appearance on the screen.
  281.            ''' The topmost window receives the highest rank and is the first window in the Z order.
  282.            ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/ms633545%28v=vs.85%29.aspx
  283.            ''' </summary>
  284.            ''' <param name="hWnd">A handle to the window.</param>
  285.            ''' <param name="hWndInsertAfter">A handle to the window to precede the positioned window in the Z order.</param>
  286.            ''' <param name="x">The new position of the left side of the window, in client coordinates.</param>
  287.            ''' <param name="y">The new position of the top of the window, in client coordinates.</param>
  288.            ''' <param name="cx">The new width of the window, in pixels.</param>
  289.            ''' <param name="cy">The new height of the window, in pixels.</param>
  290.            ''' <param name="uFlags">The window sizing and positioning flags.</param>
  291.            ''' <returns><c>true</c> if the function succeeds, <c>false</c> otherwise.</returns>
  292.            <DllImport("user32.dll", SetLastError:=True)> _
  293.            Protected Friend Shared Function SetWindowPos(
  294.                      ByVal hWnd As IntPtr,
  295.                      ByVal hWndInsertAfter As IntPtr,
  296.                      ByVal x As Integer,
  297.                      ByVal y As Integer,
  298.                      ByVal cx As Integer,
  299.                      ByVal cy As Integer,
  300.                      ByVal uFlags As SetWindowPosFlags
  301.            ) As <MarshalAs(UnmanagedType.Bool)> Boolean
  302.            End Function
  303.  
  304.            ''' <summary>
  305.            ''' Sends the specified message to a window or windows.
  306.            ''' The <see cref="SendMessage"/> function calls the window procedure for the specified window and
  307.            ''' does not return until the window procedure has processed the message.
  308.            ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644950%28v=vs.85%29.aspx
  309.            ''' </summary>
  310.            ''' <param name="hWnd">A handle to the window whose window procedure will receive the message.</param>
  311.            ''' <param name="msg">The windows message to be sent.</param>
  312.            ''' <param name="wParam">Additional message-specific information.</param>
  313.            ''' <param name="lParam">Additional message-specific information.</param>
  314.            ''' <returns>The result of the message processing; it depends on the message sent.</returns>
  315.            <DllImport("user32.dll", SetLastError:=False)>
  316.            Protected Friend Shared Function SendMessage(
  317.                      ByVal hWnd As IntPtr,
  318.                      ByVal msg As WindowsMessages,
  319.                      ByVal wParam As IntPtr,
  320.                      ByVal lParam As IntPtr
  321.            ) As IntPtr
  322.            End Function
  323.  
  324. #End Region
  325.  
  326. #Region " Callbacks "
  327.  
  328.            ''' <summary>
  329.            ''' An application-defined callback function used with the <see cref="EnumThreadWindows"/> function.
  330.            ''' It receives the window handles associated with a thread.
  331.            ''' The WNDENUMPROC type defines a pointer to this callback function.
  332.            ''' <see cref="EnumThreadWndProc"/> is a placeholder for the application-defined function name
  333.            ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/ms633496%28v=vs.85%29.aspx
  334.            ''' </summary>
  335.            ''' <param name="hWnd">A handle to a window associated with the thread specified in the <see cref="EnumThreadWindows"/> function.</param>
  336.            ''' <param name="lParam">The application-defined value given in the <see cref="EnumThreadWindows"/> function.</param>
  337.            ''' <returns>
  338.            ''' To continue enumeration, the callback function must return <c>true</c>;
  339.            ''' To stop enumeration, it must return <c>false</c>.
  340.            ''' </returns>
  341.            Protected Friend Delegate Function EnumThreadWndProc(
  342.                      ByVal hWnd As IntPtr,
  343.                      ByVal lParam As IntPtr
  344.            ) As Boolean
  345.  
  346. #End Region
  347.  
  348. #Region " Enumerations "
  349.  
  350.            ''' <summary>
  351.            ''' Specifies a System-Defined Message.
  352.            ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644927%28v=vs.85%29.aspx#system_defined
  353.            ''' </summary>
  354.            <Description("Enum used for 'SendMessage' function.")>
  355.            Protected Friend Enum WindowsMessages As Integer
  356.  
  357.                ' **************************************
  358.                ' NOTE:
  359.                ' This enumeration is partially defined.
  360.                ' **************************************
  361.  
  362.                ''' <summary>
  363.                ''' Sets the font that a control is to use when drawing text.
  364.                ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/ms632642%28v=vs.85%29.aspx
  365.                ''' </summary>
  366.                WM_SETFONT = &H30
  367.  
  368.                ''' <summary>
  369.                ''' Retrieves the font with which the control is currently drawing its text.
  370.                ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/ms632624%28v=vs.85%29.aspx
  371.                ''' </summary>
  372.                WM_GETFONT = &H31
  373.  
  374.            End Enum
  375.  
  376.            ''' <summary>
  377.            ''' Specifies the window sizing and positioning flags.
  378.            ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/ms633545%28v=vs.85%29.aspx
  379.            ''' </summary>
  380.            <FlagsAttribute>
  381.            <Description("Enum used for 'SetWindowPos' function.")>
  382.            Protected Friend Enum SetWindowPosFlags As UInteger
  383.  
  384.                ' **************************************
  385.                ' NOTE:
  386.                ' This enumeration is partially defined.
  387.                ' **************************************
  388.  
  389.                ''' <summary>
  390.                ''' Indicates any flag.
  391.                ''' </summary>
  392.                None = &H0UI
  393.  
  394.            End Enum
  395.  
  396. #End Region
  397.  
  398. #Region " Structures "
  399.  
  400.            ''' <summary>
  401.            ''' Defines the coordinates of the upper-left and lower-right corners of a rectangle.
  402.            ''' MSDN Documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/dd162897%28v=vs.85%29.aspx
  403.            ''' </summary>
  404.            <Description("Structure used for 'GetWindowRect' function.")>
  405.            Protected Friend Structure Rect
  406.  
  407.                ''' <summary>
  408.                ''' The x-coordinate of the upper-left corner of the rectangle.
  409.                ''' </summary>
  410.                Friend Left As Integer
  411.  
  412.                ''' <summary>
  413.                ''' The y-coordinate of the upper-left corner of the rectangle.
  414.                ''' </summary>
  415.                Friend Top As Integer
  416.  
  417.                ''' <summary>
  418.                ''' The x-coordinate of the lower-right corner of the rectangle.
  419.                ''' </summary>
  420.                Friend Right As Integer
  421.  
  422.                ''' <summary>
  423.                ''' The y-coordinate of the lower-right corner of the rectangle.
  424.                ''' </summary>
  425.                Friend Bottom As Integer
  426.  
  427.            End Structure
  428.  
  429. #End Region
  430.  
  431.        End Class
  432.  
  433. #End Region
  434.  
  435. #Region " Constructors "
  436.  
  437.        ''' <summary>
  438.        ''' Initializes a new instance of the <see cref="CenteredMessageBox"/> class.
  439.        ''' </summary>
  440.        ''' <param name="ownerForm">The form that owns this <see cref="CenteredMessageBox"/>.</param>
  441.        ''' <param name="TextFont">The <see cref="Font"/> used to display the text of this <see cref="CenteredMessageBox"/>.</param>
  442.        ''' <param name="TimeOut">
  443.        ''' The time interval to auto-close this <see cref="CenteredMessageBox"/>, in milliseconds;
  444.        ''' Default value is '0', which means Infinite.
  445.        ''' </param>
  446.        Public Sub New(ByVal ownerForm As Form,
  447.                       Optional textFont As Font = Nothing,
  448.                       Optional timeOut As Integer = 0I)
  449.  
  450.            Me.ownerForm1 = ownerForm
  451.            Me.font1 = textFont
  452.            Me.timeOut1 = timeOut
  453.            Me.ownerForm1.BeginInvoke(New MethodInvoker(AddressOf Me.FindDialog))
  454.  
  455.        End Sub
  456.  
  457.        ''' <summary>
  458.        ''' Prevents a default instance of the <see cref="CenteredMessageBox"/> class from being created.
  459.        ''' </summary>
  460.        Private Sub New()
  461.        End Sub
  462.  
  463. #End Region
  464.  
  465. #Region " Private Methods "
  466.  
  467.        ''' <summary>
  468.        ''' Finds the <see cref="CenteredMessageBox"/> dialog window.
  469.        ''' </summary>
  470.        Private Sub FindDialog()
  471.  
  472.            ' Enumerate windows to find the message box
  473.            If Me.tries < 0 Then
  474.                Return
  475.            End If
  476.  
  477.            Dim callback As New NativeMethods.EnumThreadWndProc(AddressOf Me.CheckWindow)
  478.  
  479.            If NativeMethods.EnumThreadWindows(NativeMethods.GetCurrentThreadId(), callback, IntPtr.Zero) Then
  480.  
  481.                If Threading.Interlocked.Increment(Me.tries) < 10 Then
  482.                    Me.ownerForm1.BeginInvoke(New MethodInvoker(AddressOf Me.FindDialog))
  483.                End If
  484.  
  485.            End If
  486.  
  487.            If Me.timeOut1 > 0 Then
  488.  
  489.                Me.timeoutTimer = New Timer With
  490.                                  {
  491.                                      .Interval = Me.timeOut1,
  492.                                      .Enabled = True
  493.                                  }
  494.  
  495.                Me.timeoutTimer.Start()
  496.  
  497.            End If
  498.  
  499.        End Sub
  500.  
  501.        ''' <summary>
  502.        ''' Checks whether the specified window is our <see cref="CenteredMessageBox"/> dialog.
  503.        ''' </summary>
  504.        ''' <param name="hWnd">A handle to the window to check.</param>
  505.        ''' <param name="lParam">The application-defined value given in the <see cref="NativeMethods.EnumThreadWindows"/> function.</param>
  506.        ''' <returns>
  507.        ''' <c>true</c> the specified window is our <see cref="CenteredMessageBox"/> dialog, <c>false</c> otherwise.
  508.        ''' </returns>
  509.        Private Function CheckWindow(ByVal hWnd As IntPtr,
  510.                                     ByVal lParam As IntPtr) As Boolean
  511.  
  512.            ' Checks if <hWnd> is a dialog
  513.            Dim sb As New StringBuilder(260)
  514.            NativeMethods.GetClassName(hWnd, sb, sb.Capacity)
  515.            If sb.ToString() <> "#32770" Then
  516.                Return True
  517.            End If
  518.  
  519.            ' Get the control that displays the text.
  520.            Dim hText As IntPtr = NativeMethods.GetDlgItem(hWnd, &HFFFFI)
  521.            Me.messageBoxWindowHandle1 = hWnd
  522.  
  523.            ' Get the dialog Rect.
  524.            Dim frmRect As New Rectangle(Me.ownerForm1.Location, Me.ownerForm1.Size)
  525.            Dim dlgRect As NativeMethods.Rect
  526.            NativeMethods.GetWindowRect(hWnd, dlgRect)
  527.  
  528.            ' Set the custom Font (if any).
  529.            If hText <> IntPtr.Zero Then
  530.  
  531.                Me.SetFont(font:=Me.font1,
  532.                           hwnd:=hText,
  533.                           rect:=frmRect)
  534.  
  535.            End If
  536.  
  537.            ' Center the dialog window in the specified Form.
  538.            Me.CenterDialog(hwnd:=hWnd,
  539.                            dialogRect:=dlgRect,
  540.                            formRect:=frmRect)
  541.  
  542.            ' Stop the EnumThreadWndProc callback by sending False.
  543.            Return False
  544.  
  545.        End Function
  546.  
  547.        ''' <summary>
  548.        ''' Sets the font of this <see cref="CenteredMessageBox"/> window.
  549.        ''' </summary>
  550.        ''' <param name="font">The <see cref="Font"/> used to display the <see cref="CenteredMessageBox"/> text.</param>
  551.        ''' <param name="hwnd">A handle to the <see cref="CenteredMessageBox"/> window.</param>
  552.        ''' <param name="rect">A <see cref="Rectangle"/> to positionate the text.</param>
  553.        Private Sub SetFont(ByVal font As Font,
  554.                            ByVal hwnd As IntPtr,
  555.                            ByVal rect As Rectangle)
  556.  
  557.            Select Case font IsNot Nothing
  558.  
  559.                Case True
  560.                    ' Set the text position.
  561.                    NativeMethods.SetWindowPos(hWnd:=hwnd,
  562.                                               hWndInsertAfter:=IntPtr.Zero,
  563.                                               x:=65,
  564.                                               y:=35,
  565.                                               cx:=rect.Width,
  566.                                               cy:=font.Height,
  567.                                               uFlags:=NativeMethods.SetWindowPosFlags.None)
  568.  
  569.                    ' Set the font.
  570.                    NativeMethods.SendMessage(hWnd:=hwnd,
  571.                                              msg:=NativeMethods.WindowsMessages.WM_SETFONT,
  572.                                              wParam:=font.ToHfont,
  573.                                              lParam:=New IntPtr(1))
  574.  
  575.                Case Else
  576.                    ' Do Nothing.
  577.  
  578.                    ' Get the dialog font.
  579.                    ' dim fnt as Font = Font.FromHfont(NativeMethods.SendMessage(hWnd:=hwnd,
  580.                    '                                                            msg:=NativeMethods.WindowsMessages.WM_GETFONT,
  581.                    '                                                            wParam:=IntPtr.Zero,
  582.                    '                                                            lParam:=IntPtr.Zero))
  583.  
  584.            End Select
  585.  
  586.        End Sub
  587.  
  588.        ''' <summary>
  589.        ''' Centers the <see cref="CenteredMessageBox"/> dialog in the specified <see cref="Form"/>.
  590.        ''' </summary>
  591.        ''' <param name="hwnd">A handle to the <see cref="CenteredMessageBox"/> window.</param>
  592.        ''' <param name="dialogRect">The dialog <see cref="NativeMethods.Rect"/> structure.</param>
  593.        ''' <param name="formRect">The form <see cref="Rectangle"/> structure.</param>
  594.        Private Sub CenterDialog(ByVal hwnd As IntPtr,
  595.                                 ByVal dialogRect As NativeMethods.Rect,
  596.                                 ByVal formRect As Rectangle)
  597.  
  598.            ' Resize and positionate the messagebox window.
  599.            NativeMethods.MoveWindow(hwnd,
  600.                                     x:=formRect.Left + (formRect.Width - dialogRect.Right + dialogRect.Left) \ 2I,
  601.                                     y:=formRect.Top + (formRect.Height - dialogRect.Bottom + dialogRect.Top) \ 2I,
  602.                                     width:=(dialogRect.Right - dialogRect.Left),
  603.                                     height:=(dialogRect.Bottom - dialogRect.Top),
  604.                                     repaint:=True)
  605.  
  606.        End Sub
  607.  
  608. #End Region
  609.  
  610. #Region " Event Handlers "
  611.  
  612.        ''' <summary>
  613.        ''' Handles the Tick event of the TimeoutTimer control.
  614.        ''' </summary>
  615.        ''' <param name="sender">The source of the event.</param>
  616.        ''' <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
  617.        Private Sub TimeoutTimer_Tick(ByVal sender As Object, ByVal e As EventArgs) _
  618.        Handles timeoutTimer.Tick
  619.  
  620.            NativeMethods.DestroyWindow(Me.messageBoxWindowHandle1)
  621.            Me.Dispose()
  622.  
  623.        End Sub
  624.  
  625. #End Region
  626.  
  627. #Region " IDisposable "
  628.  
  629.        ''' <summary>
  630.        ''' To detect redundant calls when disposing.
  631.        ''' </summary>
  632.        Private isDisposed As Boolean = False
  633.  
  634.        ''' <summary>
  635.        ''' Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
  636.        ''' </summary>
  637.        Public Sub Dispose() Implements IDisposable.Dispose
  638.  
  639.            Me.Dispose(isDisposing:=True)
  640.            GC.SuppressFinalize(obj:=Me)
  641.  
  642.        End Sub
  643.  
  644.        ''' <summary>
  645.        ''' Releases unmanaged and - optionally - managed resources.
  646.        ''' </summary>
  647.        ''' <param name="IsDisposing">
  648.        ''' <c>true</c> to release both managed and unmanaged resources;
  649.        ''' <c>false</c> to release only unmanaged resources.
  650.        ''' </param>
  651.        Protected Sub Dispose(ByVal isDisposing As Boolean)
  652.  
  653.            If Not Me.isDisposed Then
  654.  
  655.                If isDisposing Then
  656.  
  657.                    Me.tries = -1
  658.                    Me.ownerForm1 = Nothing
  659.  
  660.                    If Me.font1 IsNot Nothing Then
  661.                        Me.font1.Dispose()
  662.                    End If
  663.  
  664.                End If
  665.  
  666.            End If
  667.  
  668.            Me.isDisposed = True
  669.  
  670.        End Sub
  671.  
  672. #End Region
  673.  
  674.    End Class
  675.  
  676. End Namespace
  677.  
  678. #End Region


« Última modificación: 27 Noviembre 2014, 23:01 pm por Eleкtro » En línea


Yaldabaot

Desconectado Desconectado

Mensajes: 186


Ver Perfil
Re: ¿Cómo puedo insertar un listbox en un messagebox? VB.NET 2010
« Respuesta #2 en: 29 Noviembre 2014, 18:45 pm »

Gracias elektro lo probaré y te contaré que tal!!.
En línea

Nunca me contestan -_-
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines