1 / 60

Building ActiveX Controls

Building ActiveX Controls. מרצה : דורון אמיר. MCSD Doron Amir. www.doronamir.com. Building ActiveX Controls. An ActiveX Control Exposing Properties,Methods,Events Testing a control Creating Properties pages Creating a data bound control Creating a data source control.

reyesc
Download Presentation

Building ActiveX Controls

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Building ActiveX Controls מרצה : דורון אמיר MCSD Doron Amir www.doronamir.com

  2. Building ActiveX Controls • An ActiveX Control • Exposing Properties,Methods,Events • Testing a control • Creating Properties pages • Creating a data bound control • Creating a data source control Written by: MCSD Doron Amir

  3. ActiveX Controls יישומי VB שונים ActiveX Controls אובייקט שניתן לשיבוץ בטופס או בפקד מכולה עבור דפי WEB וצפייה ע"י IE מסמכי Office Written by: MCSD Doron Amir

  4. Controls • אובייקט לשימוש חוזר המכיל קוד וממשק וויזואלי • שימוש ב Controls מקל על המפתח • ב VB יש פקדים מוכנים ב ToolBox • ניתן ליצור פקד ולהוסיפו לתיבת הכלים ToolBox • ActiveX Controls חייבים מכולה Written by: MCSD Doron Amir

  5. Control Classes כאשר יוצרים פקד אנו יוצרים מחלקה עבור אותו פקד מחלקה ליצירת פקדים מיוצגת בקובץ OCX כאשר מציבים פקד על הטופס נוצר design-time instance כאשר מריצים את היישום נוצר run-time instance Form1 run – time control Design – time control Control.ocx Written by: MCSD Doron Amir

  6. OCX File מכיל קובץ טקסט עבור הקוד וערכי המאפיינים (ctl) וקובץ ctx עבור אלמנטים גרפיים Source Code Property Values Control Class TextFile .ctl Control.OCX Graphical elements .ctx Control Class Like .frx file for forms Written by: MCSD Doron Amir

  7. OCX File ביצירת ActiveX Control ניתן להשתמש בכמה קבצי ctl אך לאחר ההידור כל הקבצים יתאחדו לקובץ OCX אחד C1.ctl MyControl.OCX C2.ctl C3.ctl Written by: MCSD Doron Amir

  8. The UserControl Object UserControl מכיל קוד + ממשק עיצוב Code ממשק עיצוב Written by: MCSD Doron Amir

  9. Add constituent controls to a UserControl פקד ה usercontrol יכול להכיל פקדים רגילים מה- ToolBox Written by: MCSD Doron Amir

  10. Timer

  11. Using Ambient Properties • ה - Containers מספקים רשימת מאפיינים אשר יכולים להשפיע ישירות על פקד ה ActiveX שנמצא בו . • BackColor הוא מאפיין Ambient. • AmbientChanged אירוע זה מופעל כאשר יש שינוי במאפיין מסוג Ambient • Ambient Object מאפשר לקרוא ערך מאפיין Ambient • Private Sub UserControl_AmbientChanged(PropertyName As String) • If PropertyName = "BackColor“ Then • UserControl.BackColor = Ambient.BackColor • End If • End Sub כאשר צבע הרקע של ה Container ישתנה גם רקע הפקד ישתנה Written by: MCSD Doron Amir

  12. Ambient Properties UserControl_AmbientChanged רקע הפקד משנה צבע כאשר משנים את צבע הרקע של הטופס רקע הפקד אינו משנה צבע כאשר משנים את צבע הרקע של הטופס Written by: MCSD Doron Amir

  13. UserControl_Resize() האירוע מופעל בעת שינוי גודל הפקד הפרש Private Sub UserControl_Resize() Text1.Width = (UserControl.ScaleWidth - 240) End Sub הקוד הנ"ל מאפשר לפקד הטקסט לשמור על פרופורציה בהתאם לרוחב מסגרת הפקד Written by: MCSD Doron Amir

  14. Add About Box הוספת דף מידע עבור הפקד Private Sub Command1_Click() frmAbout.Show vbModal Unload frmAbout Set frmAbout = Nothing End Sub Written by: MCSD Doron Amir

  15. ToolBox Bitmap בחירת תמונה עבור הפקד : bitmap חיפוש התמונה Written by: MCSD Doron Amir

  16. The ActiveX Control Interface Wizard • אשף העוזר לבנות ActiveX Control • הגדרת מאפיינים • שיטות • אירועים Written by: MCSD Doron Amir

  17. The ActiveX Control Interface Wizard Written by: MCSD Doron Amir

  18. Create Control המטרה : צור פקד המכיל 3 תיבות טקסט ופקד ניקוי עבור התיבות טקסט בעזרת האשף נגדיר מאפיינים שיאפשרו לגשת אל כל רכיבי הפקד בנפרד Private Sub Command1_Click() Text1.Text = "": Text2.Text = "": Text3.Text = "" End Sub Written by: MCSD Doron Amir

  19. תרגיל לבניית מאפיינים יצירת מאפיין בשם myColor עבור כל רכיב בנפרד Private Sub Command1_Click() UserControl11.myColor1 = vbRed UserControl11.myColor2 = vbBlue UserControl11.myColor3 = vbGreen End Sub

  20. Select Available Property Written by: MCSD Doron Amir

  21. My Custom Members בחר שמות למאפיינים ושיטות הפקד Written by: MCSD Doron Amir

  22. התאמה בין המאפיינים החדשים לרכיבי הפקד הרכיב המאפיין כינוי Written by: MCSD Doron Amir

  23. תרגיל לבניית שיטות Private Sub Command1_Click() ctlClook1.StopTimer End Sub Private Sub Command3_Click() ctlClook1.StartTimer End Sub stopTimer Method startTimer Method

  24. My Custom Members Written by: MCSD Doron Amir

  25. User Control Sub Public Sub StartTimer() Timer1.Enabled = True End Sub Public Sub StopTimer() Timer1.Enabled = False End Sub האשף הכין את השגרות יש לקודד את הפקודות הרצויות Written by: MCSD Doron Amir

  26. Mapping a Property to Multiple Control יצירת מאפיין צבע עבור מספר פקדים לא ידוע שימוש בלולאת For Each…Next Written by: MCSD Doron Amir

  27. Mapping a Property to Multiple Control Public Property Let MyColor(ByVal vNewValue As OLE_COLOR) Dim ctl As Object For Each ctl In Controls If (TypeOf ctl Is Label) Then ctl.BackColor = vNewValue End If Next End Property Written by: MCSD Doron Amir

  28. Mapping a Property to Multiple Control Private Sub Command1_Click() UserControl11.MyColor = RGB(CInt(Text1), CInt(Text2), CInt(Text3)) End Sub המרה ל RGB Written by: MCSD Doron Amir

  29. Available in the Properties window יצירת מאפיין בחלון המאפיינים עבור פקד ה ActiveX Control Written by: MCSD Doron Amir

  30. Available in the Properties window Public Property GetMyCaption() As String MyCaption = Label1.Caption End Property Public Property Let MyCaption(ByVal NewCaption As String) Label1.Caption = NewCaption PropertyChanged "MyCaption" End Property GET = עבור קריאת המאפיין LET = עבור עריכת המאפיין PropertyChanged רושם את המאפיין בחלון המאפיינים Written by: MCSD Doron Amir

  31. Storing & Retrieving Property Values המאפיין MyTextColor קיבל צבעים שונים בעת זמן עיצוב הטופס , ללא רישום+קריאת המאפיינים הצבעים הנבחרים היו משתחררים Written by: MCSD Doron Amir

  32. Storing & Retrieving Property Values Public Property Get MyTextColor() As OLE_COLOR MyTextColor = Text1.BackColor PropertyChanged "MyTextColor" End Property Public Property Let MyTextColor(ByVal vNewValue As OLE_COLOR) Text1.BackColor = vNewValue PropertyChanged "MyTextColor" End Property יצירת מאפיין MyTextColor Written by: MCSD Doron Amir

  33. Storing & Retrieving Property Values רישום : שמירת ערך המאפיין MyTextColor Private Sub UserControl_WriteProperties(PropBag As PropertyBag) PropBag.WriteProperty "MyTextColor", Text1.BackColor, &H8000000F End Sub Private Sub UserControl_ReadProperties(PropBag As PropertyBag) Text1.BackColor = PropBag.ReadProperty("MyTextColor", &H8000000F) End Sub קריאה : חשיפת ערך המאפיין MyTextColor Written by: MCSD Doron Amir

  34. Raise Event יצירת אירוע בשם AtTime קריאה לאירוע הפעלת שיגרת האירוע

  35. Raise Event הגדרת האירוע Event AtTime() Private Sub Timer1_Timer() RaiseEvent AtTime txtTime.Text = Format(Now, "HH:MM:SS") End Sub קריאה לאירוע בכל כניסה לפרוצדורת הטיימר

  36. Private Sub ctlClock1_AtTime() כניסה אל שגרת הפקד ובחירת פרוצדורת AtTime Private Sub ctlClock1_AtTime() Print Now End Sub

  37. Using the Property Page Wizard • Create the user interface • for the property page.

  38. Add-In : vb6 Property Page Wizard

  39. Select the Property Page

  40. Select Properties for Display

  41. Next..Next..Next

  42. Compile For OCX עיצוב פקד מאפייני פרוייקט

  43. Compile For OCX File  Make MyOCX.ocx שמירת הקובץ Written by: MCSD Doron Amir

  44. רישום הפקד • הידור הפקד • העתק לתיקיה System32 • פרוייקט EXE חדש • Components + Brows  Apply Written by: MCSD Doron Amir

  45. Components Written by: MCSD Doron Amir

  46. System32 Written by: MCSD Doron Amir

  47. Apply Written by: MCSD Doron Amir

  48. Creating a data bound control SQL server Written by: MCSD Doron Amir

  49. Creating a Control OCX txtFname txtLname txtEmpId Public Property Get EmpId() As String EmpId = txtEmpId.Text End Property Public Property Let EmpId(ByVal New_EmpId As String) txtEmpId.Text() = New_EmpId PropertyChanged "EmpId" End Property Code :Let/Get + Read/Write Let/Get Make …OCX • עריכת מאפיינים לכל פקד פנימי • שמירת נתונים • הידור הפקד Private Sub UserControl_ReadProperties(PropBag As PropertyBag) ………. txtEmpId.Text = PropBag.ReadProperty("EmpId", "Text3") End Sub Read/write Written by: MCSD Doron Amir

  50. Connecting DataBase • הוספת סביבת נתונים (Data Environment) • בניית קישור (Connection) • בחירת ספק (Provider) • בחירת(Server) • בחירת מסד נתונים (DataBase) התחברות למסד הנתונים Pubs Written by: MCSD Doron Amir

More Related