Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Building ActiveX Controls מרצה : דורון אמיר MCSD Doron Amir www.doronamir.com."— 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 שונים עבור דפי 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 Control.ocx Design – time control run – time control Form1 Written by: MCSD Doron Amir

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

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

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

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

10 Timer

11 Using Ambient Properties Written by: MCSD Doron Amir ה - 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 ישתנה גם רקע הפקד ישתנה

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

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

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 Written by: MCSD Doron Amir אשף העוזר לבנות ActiveX Control הגדרת מאפיינים שיטות אירועים

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

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

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

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 תרגיל לבניית שיטות stopTimer Method startTimer Method Private Sub Command1_Click() ctlClook1.StopTimer End Sub Private Sub Command3_Click() ctlClook1.StartTimer End Sub

24 My Custom Members Written by: MCSD Doron Amir

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

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

27 Mapping a Property to Multiple Control Written by: MCSD Doron Amir 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

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

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

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

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

32 Storing & Retrieving Property Values Written by: MCSD Doron Amir 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

33 Storing & Retrieving Property Values Written by: MCSD Doron Amir 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 קריאה : חשיפת ערך המאפיין MyTextColor

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 Written by: MCSD Doron Amir File  Make MyOCX.ocx שמירת הקובץ

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

45 Components

46 System32

47 Apply

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

49 Creating a Control OCX Written by: MCSD Doron Amir txtFname txtLname txtEmpId Code :Let/Get + Read/Write 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 Private Sub UserControl_ReadProperties(PropBag As PropertyBag) ………. txtEmpId.Text = PropBag.ReadProperty("EmpId", "Text3") End Sub Make …OCX עריכת מאפיינים לכל פקד פנימי שמירת נתונים הידור הפקד Read/write Let/Get

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

51 הוספת סביבת נתונים (Data Environment) Written by: MCSD Doron Amir 1.Right Click 2.Add 3.More ActiveX Designers 4.Data Environment

52 Written by: MCSD Doron Amir בניית קישור (Connection)

53 בחירת ספק (Provider) Written by: MCSD Doron Amir

54 בחירת + (Server) מסד נתונים (DataBase) Written by: MCSD Doron Amir

55 Add Command Written by: MCSD Doron Amir Right Click Properties

56 Edit Command Written by: MCSD Doron Amir 1.התאמת Command לקישור הנתונים 2.עריכת משפט בחירה SQL

57 Microsoft DataRepeater Control 6.0 הוספת פקד repeater Written by: MCSD Doron Amir

58 RepeaterControlName שיבוץ הפקד שיצרנו בפקד ה- Repeater Written by: MCSD Doron Amir

59 DataSource & DataMember התאמת מסד הנתונים + שליחת השאילתה Written by: MCSD Doron Amir

60 MCSD Doron Amir www.doronamir.com Building ActiveX Controls


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

Similar presentations


Ads by Google