מבוא לתכנות ב WINDOWS ד " ר אבי רוזנפלד ד " ר אריאלה ריכרדסון.

Slides:



Advertisements
Similar presentations
ממיבחניםC שאלות ++.
Advertisements

מבוא למדעי המחשב לתעשייה וניהול
Building ActiveX Controls מרצה : דורון אמיר MCSD Doron Amir
Chapter 2 –Visual Basic, Controls, and Events
תכנות תרגול 4 שבוע : לולאות while לולאות while while (condition) { loop body } במקרה של קיום התנאי מתבצע גוף הלולאה ברגע שהתנאי לא מתקיים נצא.
סוגי מידע / משתנים ד " ר אבי רוזנפלד. סוגאורךטווח Boolean1 Bit0,1 Byte1 byte0-255 Char 2 bytes תו Decimal16 bytes0 through +/-79,228,162,514,264,337,593,543,950,335.
Compunet Corporation Programming with Visual Studio.NET GUI Week 13 Tariq Aziz and Kevin Jones.
חלון הפקודות מיועד לבצע פעולה אחת בכל פעם. כיצד אפשר לבצע רשימת פקודות או אפליקציות מורכבות ?
מבוא כללי למדעי המחשב תרגול 3. לולאות while לולאות while while (condition) { loop body } במקרה של קיום התנאי מתבצע גוף הלולאה ברגע שהתנאי לא מתקיים נצא.
מבני בקרה לולאות. פקודת CASE Module Module1 Sub Main() Dim input As Char input = Console.ReadLine() Select Case (input) Case "A" Console.WriteLine("A.
11 Introduction to Programming in C - Fall 2010 – Erez Sharvit, Amir Menczel 1 Introduction to Programming in C תרגול
Adding Controls to User Forms. Adding Controls A user form isn’t much use without some controls We’re going to add controls and write code for them Note.
Structure. מה לומדים היום ? דרך לבנות מבנה נתונים בסיסי – Structure מייצר " טיפוס " חדש מתאים כאשר רוצים לאגד כמה משתנים יחד דוגמאות : עובד : שם, טלפון,
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
Visual Basic 2008 Express Edition The IDE. Visual Basic 2008 Express The Start Page Recent Projects Open an existing project Create a New Project.
Hello World In C++ and Microsoft Visual C++. Directions to begin a project 1. Go to All Programs 2. Open Visual Studio C++ 3. Click on New Project 4.
CSCI 3328 Object Oriented Programming in C# Chapter 2: Introduction to Visual C# Programming 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg,
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Assignment #1 Advanced Computer Programming.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 4 I Need a Tour Guide.
Copyright © 2001 by Wiley. All rights reserved. Chapter 2: Using Visual Basic to Create a First Project Getting Started with VB Development Environment.
Program Design and Coding
Microsoft Visual Basic 2012 CHAPTER THREE Program Design and Coding.
Microsoft Visual Basic 2010 CHAPTER THREE Program Design and Coding.
Microsoft Visual Basic 2008 CHAPTER TWELVE Cell Phone Applications and Web Services.
Class 3 Remote Instruction Computer Math EDU 556 Programming for Instruction Dr. Steve Broskoske This is an audio PowerCast. Make sure your volume is.
1 Creating Windows GUIs with Visual Studio. 2 Creating the Project New Project Visual C++ Projects Windows Forms Application Give the Project a Name and.
מבוא למדעי המחשב לתעשייה וניהול הרצאה 7. סברוטינות subroutines.
CSC 230 (Blum)1 Visual Basic 2005 Hello World Fall 2005 T. Blum.
Visual Basic Programming Introduction VB is one of the High level language VB has evolved from the BASIC language. BASIC stands for Beginners All-purpose.
CS 101 Test 2 Study Guide Acronyms RAD - Rapid Application Development IDE - Integrated Development Environment GUI - Graphical User Interface VB - Visual.
1 Advanced Computer Programming Lab Calculator Project.
1 Visual Basic Part I - A tool for customizing your program Principles of GIS
VAT Calculator program Controls Properties Code Results.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
CSC 230 (Blum)1 Visual Basic 2005 Hello World Fall 2005 T. Blum.
Introduction to VB programming Dr. John P. Abraham UTPA Chapters 2 & 3.
מבוא למדעי המחשב לתעשייה וניהול הרצאה 6. מפעל השעווה – לולאות  עד עכשיו  טיפלנו בייצור נרות מסוג אחד, במחיר אחיד  למדנו להתמודד עם טיפול במקרים שונים.
מבנה נתונים ואלגוריתמים ) לשעבר - עיבוד מידע( ד"ר אבי רוזנפלד ד"ר אריאלה ריכרדסון.
Combo Box שלושה סוגים של Combo Box: Style 0 (default) - drop-down combo box המשתמש יכול להוסיף אפשרויות לרשימה או ללחוץ על החץ לבחירה מרשימת האפשרויות.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
Visual Basic Declaring Variables Dim x as Integer = 0 In the statement above, x is being declared as an Integer (whole number) and is initialised.
Visual Basic/ Visual Studio Brandon Large. Connecting to prior knowledge In your notes write down what the two main parts of the computer are. The “software”
Visual Basic Fundamental Concepts
UNIT 1 Lesson 1 Introduction.
A variable is a name for a value stored in memory.
CSCI 3328 Object Oriented Programming in C# Chapter 2: Introduction to Visual C# Programming UTPA – Fall 2012 This set of slides is revised from lecture.
Tutorial 10 – Class Average Application Introducing the Do…Loop While and Do…Loop Until Repetition Statements Outline Test-Driving the Class Average.
Chapter 2 – Introduction to the Visual Studio .NET IDE
3.01 Apply Controls Associated With Visual Studio Form
3.01 Apply Controls Associated With Visual Studio Form
מחלקות classes.
Standard Controls.
Introduction to VB programming
البرمجة بلغة فيجول بيسيك
שפת Visual Basic מבוסס על Visual Basic. NET 2008 מרצה : קנדוב פנחס
مراحل كتابة البرنامج بلغة فيجول بيسك ستديو
Visual Basic..
Visual Basic.
Department Array in Visual Basic
حلقات التكرار.
المحاضرة الأولى Lab(1) أ.ساره الأحمدي برمجة حاسب 2.
The University of Texas – Pan American
מבוא לתכנות בWINDOWS ב#C
עקרונות בסיסיים בתכנות Visual Basic
Introduction to Programming
Understanding Buttons and TextBoxes
Overview of the IDE Visual Studio .NET is Microsoft’s Integrated Development Environment (IDE) for creating, running and debugging programs (also.
GUI Programming in Visual Studio .NET
Presentation transcript:

מבוא לתכנות ב WINDOWS ד " ר אבי רוזנפלד ד " ר אריאלה ריכרדסון

תכנות מונחה אירועים Event-driven programming הרעיון - התוכנה מחכה לקבלת " אירוע " (event) דוגמאות לאירוע לחיצה על כפתור, תזוזה של עכבר, כתיבה בתיבה, לחיצה על enter המתכנת צריך לתכנת מה יקרה לאחר קבלת ה event האירוע למעשה עשוי משני חלקים : מקום בתוכנה שבו האירוע מוזנק - נסתר מבחינתנו מקום בתוכנה שבו האירוע נלכד – בו נכתוב את הקוד לביצוע פונקציונליות רצויה בתכנות ללא אירועים ( שראינו עד עכשיו ) המתכנת היה יוצר לולאה שבה היה מזין, מנהל, מסווג ומסדר בעצמו את האירועים. תכנות מונחה אירועים אופייני ליישומים בעלי ממשק משתמש גרפי ( כמו VB, אבל גם NET., JAVA, ו #C)

תכנות בעזרת האובייקטים של VB בניית ה FORM ( הטופס ) –יצירת הטופס עם הבקרים (controls) הרצויים –יצירת המקום להתחלת האירוע הוספת הקוד כאשר ה EVENT מופעל –קוד VB רגיל, אבל כולל את האובייקטים של ה FORM

הוראות ליצירת אפליקציה Windows ב VB After pushing Start, choose Microsoft Visual Studio.Net Press New Project Button Left Pane – Choose Visual Basic Projects Right Pane – Choose Windows Application Fill in name of folder where solutions will be kept and press OK

בניית אובייקט ב VB

הטופס בעת פתיחת הפרויקט החדש מופיע טופס (Form) –לחיצה על F4, או על View/Properties נותנת חלון עם המאפיינים של הטופס מילוי של " משהו " במקום שבו כתוב Text ישנה את שם הטופס ל " משהו " ניתן לשחק גם עם גודל הטופס ע " י מתיחה... ניתן לשנות את צבע הטופס ע " י שינוי המאפיין BackColor ל Custom, ובחירת צבע כרצונכם

בניית הטופס

מילוי הטופס ניתן להוסיף לטופס בקרים ( פקדים, controls) –ההוספה נעשית ע " י פתיחת ה toolBox ( מוחבא בצד ): גרירת control לטופס או לחיצה כפולה בעזרת העכבר –ניתן לשנות את המאפיינים של ה control ממומלץ לתת שם משמעותי ל control ע " י שינוי name על מנת להקל על התכנות בהמשך דוגמאות ל controls –כפתור Button ניתן ללחוץ עליו כדי לבצע פעולה –תווית label מיועד להצגה של טקסט צבע התווית הו כמו צבע הטופס

התאמת התווית - Customizing Label בחירת התווית מתבצעת ע " י לחיצה על התווית שינוי הכיתוב שמופיע עליה ע " י שינוי המאפיין Text על מנת לשנות את צבע הרקע של התווית שנו את Backcolor על מנת לשנות את צבע הכיתוב של התווית שנו את Forecolor הזזת התווית ושינוי הגודל ע " י תפיסה עם העכבר ומשיכה ניתן גם להיעזר ב format בתפריט לשם כך מיקום טקסט במרכז ע " י המאפיין TextAlign ניתן גם לשחק עם הפונט ע " י המאפיין Font As before, Ctrl-F5 or F5 runs the program

הוספת אובייקטים תעבוד עם ה TOOLBAR והמאפיינים

מאפיינים נוספים של control.SHOW.HIDE.TEXT.ForeColor = Color.???

הצגת תמונה ( והחבאה...) דוגמא 1 ( באתר ) Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click PictureBox1.Visible = True Label1.Text = "Picture On!" Label1.TextAlign = ContentAlignment.BottomLeft Off.Visible = True End Sub Private Sub Off_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Off.Click PictureBox1.Visible = False Label1.Visible = True Label1.Text = "Picture OFF!" ' Label1.TextAlign = ContentAlignment.TopRight End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click End End Sub

דוגמא של טופס ( דוגמא 2 באתר )

תכנון הפונקציונליות במקרה של אירוע יש לייצר את קטע הקוד המתאים ע " י לחיצה כפולה על ה control נוצר קוד מתאים למשל : עבור לחיצת כפתור Private Sub Button2_Click(…) Handles Button2.Click End Sub לעדכון בעת פתיחת הטופס יש ללחוץ לחיצה כפולה על הטופס, ואז יוצר הקוד Private Sub Form1_Load(…) Handles MyBase.Load End Sub

הקוד מאחורי הטופס

קלט / פלט מחשבון לחישוב שטח מעגל ( דוגמא 3 באתר ) Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' In this program we calculate the volume of a ' cylinder by the formula PI * r ^2 * h Dim r As Single, h As Single, v As Single Const pi = r = TextBox1.Text h = TextBox2.Text v = pi * r ^ 2 * h Label4.Text = Format(v, "#.##") 'Label4.Text = v Also ok End Sub

דוגמא של טופס – קלט ופלט

שימו לב ! ב VB, קלט = FORM פלט = LABEL

הקוד מאחורי הטופס

טפסים מיוחדים שכבר מוגדרים לקלט ופלט messageBox להדפסת הודעה InputBox לקבלת קלט ניתן להשתמש בתוך main או בעת טיפול באירוע ( שקף הבא ) Module Module1 Sub Main() MsgBox("This goes out") Dim x As Integer = InputBox("please enter a number") MsgBox("You typed " & x) End Sub End Module מיוחדים ! messageBox, InputBox

MESSAGEBOX עם קלט Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim exita As String exita = MsgBox("Exit?", vbYesNo) If exita = vbYes Then End End If End Sub End Class

תרגיל יש ליצור משתנה הקולט סכום כסף. בפלט יש להציג את המספר המינימאלי של המטבעות המהוות סכום זה. למען התרגיל, נניח שיש רק מטבעות של 10 ש " ח, 1 ש " ח, ואגרות. לדוגמא ש " ח : בדוגמא זו : 3 מטבעות של 10 ש " ח, 4 מטבעות של 1 ש " ח, ו - 70 אג '.

שאלות ? איך יראה הטופס ? מה יהיו החישובים ? ( דוגמא 4 באתר...)

פתרון Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim shekel As Double = 0 Dim whole, tens, ones As Integer shekel = TextBox1.Text whole = Math.Floor(shekel) tens = whole \ 10 ones = whole Mod 10 TextBox2.Text = tens TextBox3.Text = ones TextBox4.Text = Format((shekel - whole) * 100, "##") End Sub End Class

שילוב של תנאי IF ב events דוגמא 5 באתר Public Class Form1 Dim counter As Integer = 0 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click counter += 1 If TextBox1.Text = "Avi" Then MsgBox("You got it -- " & counter) End Else MsgBox("Guess Again!") TextBox1.Clear() End If End Sub End Class

הוספת לוגיקה ב events דוגמא 6 באתר Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If TextBox1.Text = "Avi" And TextBox2.Text = "Bob" Then MsgBox("Good") End ElseIf TextBox1.Text <> "Avi" And TextBox2.Text <> "Bob" Then MsgBox("Guess Again for Both!") TextBox1.Clear() TextBox2.Clear() ElseIf TextBox2.Text <> "Bob" Then MsgBox("Guess Again for Box 2!") TextBox2.Clear() Else MsgBox("Guess Again for Box 1!") TextBox1.Clear() End If End Sub

דוגמא נוספת - MessageBox דוגמא 7 באתר Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim output As String = "" For i = 1 To 10 output = output + "Hi!" output += vbNewLine Next MsgBox(output) End Sub

ListBox דוגמא 8 באתר Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim output As String = "" For i = 1 To 10 ListBox1.Items.Add("Hi") Next End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click ListBox1.Items.Clear() End Sub

לולאות עם LISTBOX Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim output As String For i = 1 To 10 output = "" For j = 1 To 10 output += "*" Next ListBox1.Items.Add(output) Next End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click ListBox1.Items.Clear() End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim output As String For i = 1 To 10 output = "" For j = 1 To i output += "*" Next ListBox1.Items.Add(output) Next End Sub

הוספת תפריט Menu Strip

משחק ניחוש דוגמא 9 באתר Public Class Form1 Dim RandomClass As New Random() Dim num As Integer = RandomClass.Next(1, 100) Dim counter As Integer = 0 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click counter += 1 Dim guess As Integer = Val(TextBox1.Text) 'Or: Dim guess As Integer = TextBox1.Text If guess = num Then MsgBox("You got it!") End End If TextBox2.Text = num End Sub End Class

סיכום בתכנות אירועים, יש צורך לשאול : מה יהיה האירוע ( ומה יש בטופס כדי לקלוט אותו ) מה יהיה התוצאה ( ואיפה זה יופיע ) מה הקוד מאחורי התוצאה סוגי אובייקים : LABEL לפלט TextBox לקלט או פלט MesageBox, ListBox לפלט InputBox לקלט כפתור להפעיל אירוע