التحكم بحجم ومكان صندوق الرسالة
صفحة 1 من اصل 1
التحكم بحجم ومكان صندوق الرسالة
التحكم فى حجم ومكان ظهور صندوق الرسالة
ابسط الطرق هى انشاء فورم واعدادة كصندوق رسالة
أو يمكنك انشاء Class وكتابة الكود التالى به
ابسط الطرق هى انشاء فورم واعدادة كصندوق رسالة
- الكود:
Dim F As New Form2
F.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedDialog
F.Size = New Size(100, 100)
F.Location = New Point(0, 0)
F.MessageLable="HelloWorld"
F.ShowDialog()
أو يمكنك انشاء Class وكتابة الكود التالى به
- الكود:
Imports System.Text
Imports System.ComponentModel
Imports System.Runtime.InteropServices
Public Class Nobugz
Private Shared mRect As Rectangle ' Form rectangle
Private Shared mTid As IntPtr ' UI thread ID
Private Shared mHwnd As IntPtr ' Handle of message box window
Private Shared mPos As Point ' Desired postion of message box
Public Shared Sub CenterMsgBox(ByVal frm As Form)
'--- Centers the message box about to be displayed inside form
mRect = frm.Bounds
mTid = GetCurrentThreadId()
mHwnd = IntPtr.Zero
Dim bw As New BackgroundWorker
AddHandler bw.DoWork, AddressOf FindMsgBox
AddHandler bw.RunWorkerCompleted, AddressOf CenterMsgBox
bw.RunWorkerAsync()
End Sub
Private Shared Sub FindMsgBox(ByVal sender As Object, ByVal e As DoWorkEventArgs)
'--- Try this a few times in case the message box wasn't created yet
For ix As Integer = 1 To 4
'--- Enumerate the windows in the GUI thread
EnumThreadWindows(mTid, AddressOf EnumWindow, IntPtr.Zero)
If mHwnd <> IntPtr.Zero Then Exit For
Threading.Thread.Sleep(30)
Next
End Sub
Private Shared Sub CenterMsgBox(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs)
'--- Center it if we found the message box
If mHwnd <> IntPtr.Zero Then
SetWindowPos(mHwnd, IntPtr.Zero, mPos.X, mPos.Y, 0, 0, SWP_NOSIZE)
End If
End Sub
Private Shared Function EnumWindow(ByVal hWnd As IntPtr, ByVal lp As IntPtr) As Boolean
'--- Is this the message box?
Dim sb As New StringBuilder(256)
GetClassName(hWnd, sb, sb.Capacity)
If sb.ToString() <> "#32770" Then Return True
'--- Got it, now move it where it should go
Dim rc As RECT
GetWindowRect(hWnd, rc)
mPos = New Point(mRect.Left (mRect.Width - (rc.Right - rc.Left)) \ 2, _
mRect.Top (mRect.Height - (rc.Bottom - rc.Top)) \ 2)
mHwnd = hWnd
'--- Done, stop iterating
Return False
End Function
'--- P/Invoke declarations
Private Delegate Function EnumThreadDelegate(ByVal hWnd As IntPtr, ByVal lp As IntPtr) As Boolean
Private Declare Auto Function EnumThreadWindows Lib "user32.dll" (ByVal tid As IntPtr, ByVal callback As EnumThreadDelegate, ByVal lp As IntPtr) As Boolean
Private Declare Auto Function GetClassName Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal name As StringBuilder, ByVal maxlen As Integer) As Integer
Private Declare Auto Function GetCurrentThreadId Lib "kernel32.dll" () As IntPtr
Private Declare Auto Function SetWindowPos Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal hAfter As IntPtr, _
ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal uFlags As UInteger) As Boolean
Private Declare Auto Function GetWindowRect Lib "user32.dll" (ByVal hWnd As IntPtr, ByRef lpRect As RECT) As Boolean
_
Private Structure RECT
Public Left As Integer
Public Top As Integer
Public Right As Integer
Public Bottom As Integer
End Structure
Private Const SWP_NOSIZE As Integer = 1
End Class
To use it, call Nobugz.CenterMsgBox() just before you display it. Pass a reference to the form on which you want to center it. For example:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Nobugz.CenterMsgBox(Me)
MsgBox("Howdy")
End Sub[/font][/color]
[color=#333333][font='Verdana']
صفحة 1 من اصل 1
صلاحيات هذا المنتدى:
لاتستطيع الرد على المواضيع في هذا المنتدى
» مضاد فيرس مجاني من ميكروسوفت New Antivirus From Microsoft - Free
» كيفية تثبيت Windows XP بعد تثبيت Windows7
» النسخة الاصلية لكتاب الف ليلة وليلة الممنوع ( للكبار فقط )
» http://ahlakalam.to-relax.net/t476-topic
» كتاب نادر - اعترافات جولدامائير واسرار لم تنشر عن حرب اكتوبر
» الكتاب الاسود - قصة تعذيب المسلمين فى عهد حسنى مبارك
» الكتاب النادر اول حوار صحفى مع جنى مسلم
» كتاب نهاية اسرائيل والولايات المتحدة الامريكية
» كتاب ( الحلم اليهودى والوهم الماسونى )
» Internet Download Manager 6.05 Build 2 Final
» مجموعه كتب رائعة - متنوعة
» فن الالقاء الرائع للدكتور طارق سويدان
» شرح بالصور لكيفية صنع نسخة ويندوز خاصة بك واضافه البرامج والتعريفات لها
» تحويل الملفات الى PDF بدون برامج
» Hiren's BootCD 13.1
» نزهة الألباب فيما لا يوجد فى كتاب - من كتب الثقافة الجنسية العربية
» شقائق الاترج فى رقائق الغنج - من كتب الثقافة الجنسية العربية النادرة
» الحرام - مغامرات حقيقية لأميرة سعودية
» عملية ذبح نمر وسلخ جلدة- حصرية ونادرة جداجداجدا