09-10-12, 05:44 PM
كاتب الموضوع : samerselo
عندما تتعامل مع مايكروسوفت وورد تأتيك أوقات تحتاج لإظهار صناديق حوار للحصول على دخل من المستخدم. ورغم وجود إمكانية لإنشاء صناديق الحوار الخاصة بك إلا أنه يمكنك أيضا الاستفادة من صناديق الحوار الموجودة سلفا والتي يمكننا الوصول إليها من خلال المجموعة Dialogs في الغرض Application وهي أكثر من 200 صندوق حوار تم تقديمها على شكل تعدادات. فإذا أدرنا استدعاء صندوق حوار إنشاء مستند جديد على سبيل المثال يمكننا عمل ذلك بتمرير القيمة Word.WdWordDialog.wdDialogFileNew للدالة Application.Dialogs.Item كما في الكود التالي وللتجربة استخدم مشروعا من النوع Word 2007 Documentكود :
Dim dlg As Word.Dialog = _
Application.Dialogs.Item(Word.WdWordDialog.wdDialogFileNew)
dlg.Show()
كود :
Dim dlg As Word.Dialog = Application.Dialogs(Word.WdWordDialog.wdDialogFileOpen)
Dim dlgType As Type = GetType(Word.Dialog)
' Set the Name property of the dialog box.
dlgType.InvokeMember("Name", _
Reflection.BindingFlags.SetProperty Or _
Reflection.BindingFlags.Public Or _
Reflection.BindingFlags.Instance, _
Nothing, dlg, New Object() {"Testing"}, _
System.Globalization.CultureInfo.InvariantCulture)
dlg.Show()
كود :
' Show the Name property.
MessageBox.Show(dlgType.InvokeMember("Name", _
Reflection.BindingFlags.GetProperty Or _
Reflection.BindingFlags.Public Or _
Reflection.BindingFlags.Instance, _
Nothing, dlg, Nothing, _
System.Globalization.CultureInfo.InvariantCulture))
كود :
Friend Sub PageSetupDialogHidden()
Dim dlg As Word.Dialog = _
Application.Dialogs.Item(Word.WdWordDialog.wdDialogFilePageSetup)
' Set the properties of the dialog box.
' ControlChars.Quote() is used to represent the symbol for inches.
With dlg
.PageWidth = 3.3 & ControlChars.Quote
.PageHeight = 6 & ControlChars.Quote
.TopMargin = 0.71 & ControlChars.Quote
.BottomMargin = 0.81 & ControlChars.Quote
.LeftMargin = 0.66 & ControlChars.Quote
.RightMargin = 0.66 & ControlChars.Quote
.HeaderDistance = 0.28 & ControlChars.Quote
.Orientation = Word.WdOrientation.wdOrientPortrait
.DifferentFirstPage = False
.FirstPage = 0
.OtherPages = 0
' Apply these settings only to the current selection with this line of code:
.ApplyPropsTo = 3
' Apply the settings.
.Execute()
End With
End Sub