5
A
답변
6
VB.NET 용 용액 :
이 코드 @Hans 김에의 asnwer 찍은 번역된다 Winforms-How can I make MessageBox appear centered on MainForm?
Centered_MessageBox.vb
Imports System.Text
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Class Centered_MessageBox
Implements IDisposable
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
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
End If
' Got it
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)
Return False
End Function
Public Sub Dispose() Implements IDisposable.Dispose
mTries = -1
End Sub
' P/Invoke declarations
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 GetWindowRect(hWnd As IntPtr, ByRef rc As RECT) As Boolean
End Function
<DllImport("user32.dll")> _
Private 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
Private Structure RECT
Public Left As Integer
Public Top As Integer
Public Right As Integer
Public Bottom As Integer
End Structure
End Class
용도 :
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Using New Centered_MessageBox(Me)
MessageBox.Show("Test Text", "Test Title", MessageBoxButtons.OK)
End Using
End Sub
+0
[Telerik Code Converter] (http://converter.telerik.com/)를 사용하여 변환 했으므로 내기를 걸었습니다. – mbomb007
1
슬프게도 MessageBox
을 부모와 센터링 할 방법이 없습니다. 기본적으로 화면 중앙에 위치하므로 변경할 수 없습니다.
관련 문제
- 1. datetime에 도달하면 messagebox를 표시 하시겠습니까?
- 2. circumcircles의 중앙에 마커 표시
- 3. 양식 패널을 화면 중앙에 놓습니다.
- 4. 양식 내의 컨트롤을 중앙에 놓기
- 5. Win32 MessageBox를 어떻게 표시합니까?
- 6. Three.js : 씬 중앙에 오브젝트 표시
- 7. ViewTabPager의 중앙에 선택된 탭 표시
- 8. MVVM에서 Messagebox를 사용하는 방법?
- 9. flexbox를 사용하여 양식 요소 중앙에 배치
- 10. asp.net에서 MessageBox를 표시하는 방법?
- 11. VB에서 asp.net의 messageBox를 변환하십시오.
- 12. Messagebox를 수정 하시겠습니까?
- 13. ASP에 MessageBox를 표시하십시오.
- 14. SWTBot - MessageBox를 기다립니다.
- 15. BizTalk MessageBox를 검색하고 있습니까?
- 16. MessageBox를 숨길 방법이 있습니까?
- 17. MessageBox를 닫을 때
- 18. C에서 Messagebox를 사용하여 출력
- 19. VB.net에서 MessageBox를 대기시키는 방법
- 20. Monodroid에서 MessageBox를 표시하는 방법
- 21. MessageBox를 사용하여 멀티 스레드 응용 프로그램에서 예외 정보 표시
- 22. WP7에서 MessageBox를 표시 할 때 기본 사운드 끄기
- 23. golang의 터미널 화면 중앙에 텍스트 표시
- 24. 사용자 위치가 중앙에 여러개의 주석 표시
- 25. 화면 중앙에 WindowsForm 표시 (듀얼 스크린)
- 26. 로고가 중앙에 배치 된 작업 표시 줄
- 27. 이벤트 핸들러에서 messagebox를 사용하는 방법
- 28. COM 표시 DLL에 양식 표시
- 29. InstallShield 2009에서 messageBox를 표시하는 방법
- 30. wcout 대신 messagebox를 사용하는 방법
[부모 형태의 가운데 MessageBox] 가능한 중복 (http://stackoverflow.com/questions/1732443/center-messagebox-in-parent-form) – harriyott
해당 게시물에 대한 조언과 정보를 주셔서 감사합니다. 내 대답이 중복되지 않도록 편집했습니다. – ElektroStudios
http://stackoverflow.com/questions/2576156/winforms-how-can-i-make-messagebox-appear-centered-on-mainform –