1 Scroll Bars Providing Scrollbars. 2 Objectives You will be able to: Use Windows Graphics to display tabular information on a Windows form. Add graphics.

Slides:



Advertisements
Similar presentations
How can Microsoft PowerPoint 2007 help you share information?
Advertisements

 2007 Dr. Natheer Khasawneh. Chapter 13. Graphical User Interface Concepts: Part 1.
1 Using a DataGridView. 2 The DataGridView The DataGridView is a high level control that presents data in a form similar to an Excel spreadsheet. Can.
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Excel Project 7 Using Macros and Visual Basic for Applications (VBA) with Excel.
Microsoft Office 2010 Access Chapter 1 Creating and Using a Database.
.NET Class 4 – Windows-based Application. WinForm Application Homogeny programming model. Rich class library Classes are shared by all.NET languages.
Graphical User Interface (GUI) A GUI allows user to interact with a program visually. GUIs are built from GUI components. A GUI component is an object.
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Word Project 8 Working with Macros and Visual Basic for Applications (VBA)
ShelterPoint™ Data-Entry Workflows. ShelterPoint v5.2.3.
1 Excel Lesson 3 Organizing the Worksheet Microsoft Office 2010 Introductory Pasewark & Pasewark.
DT265-2 Object Oriented Software Development 2 Lecture 3 : Windows Programming Lecturer Pat Browne
Chapter 3 Introduction to Event Handling and Windows Forms Applications.
1 Windows Printing. 2 Objectives You will be able to Output text and graphics to a printer. Print multipage documents. Use the standard Windows print.
Saving and Loading Simple Text Files A sequential file stores characters one after the other like songs on a cassette tape. New characters are added to.
Lecture 2 Managing Windows OS Introduction to.NET Framework C# & Microsoft Visual Studio.NET 2008.
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.
Microsoft Word 2010 Lesson 10. Learning Objectives 1 Understand and Use Mail Merge 2 Select and Edit a main document 3 Create a source document 4 Preview,
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
Creating a Presentation
1 CA201 Word Application Increasing Efficiency Week # 13 By Tariq Ibn Aziz Dammam Community college.
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 4 1 Microsoft Office FrontPage 2003 Tutorial 4 – Using Shared Borders and Themes.
1 Windows Graphics. 2 Objectives You will be able to Use the Windows GDI+ to draw arbitrary figures and text on a Windows form. Add a handler for the.
Defining a Website. Review…. Page Title −The text that will be displayed in the title bar of the browser window on a web page File Name −What you “call”
Chapter 12: Using Controls. Examining the IDE’s Automatically Generated Code A new Windows Forms project has been started and given the name FormWithALabelAndAButton.
Chapter 5 Menus, Common Dialog Boxes, and Methods Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
1 Working with Menus and Dialog Boxes. 2 Objectives You will be able to Create and edit menus for Windows Forms applications. Write code to handle menu.
Microsoft Windows 7 Part 1 Fundamentals of Using Windows 7.
1 Data Bound Controls II Chapter Objectives You will be able to Use a Data Source control to get data from a SQL database and make it available.
Windows Tutorial Common Objects ACOS: 1, 4. Using the Taskbar 1. Using the taskbar, you can switch between open programs and between open documents within.
Program Design and Coding
Microsoft Visual Basic 2012 CHAPTER THREE Program Design and Coding.
Microsoft Visual Basic 2010 CHAPTER THREE Program Design and Coding.
COS240 O-O Languages AUBG, COS dept Lecture 33 Title: C# vs. Java (GUI Programming) Reference: COS240 Syllabus.
Pasewark & Pasewark 1 Access Lesson 5 Creating and Modifying Reports Microsoft Office 2007: Introductory.
© 2012 The McGraw-Hill Companies, Inc. All rights reserved. word 2010 Chapter 3 Formatting Documents.
BIL528 – Bilgisayar Programlama II Introduction 1.
1 Project 7: Northwind Traders Order Entry. 2 Northwind Order Entry Extend the Select Customer program from Project 6 to permit the user to enter orders.
Chapter Two Creating a First Project in Visual Basic.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
CNS 1410 Graphical User Interfaces. Obectives Students should understand the difference between a procedural program and an Event Driven Program. Students.
Chapter 2 – Introduction to the Visual Studio .NET IDE
Return to Outline Copyright © 2011 by Maribeth H. Price 3-1 Labeling and annotation.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Exploring the Macromedia Flash Workspace – Lesson 2 1 Exploring the Macromedia Flash Workspace Lesson 2.
1 Project 5: Printing Address Labels. 2 Assignment Write a Windows forms program to display and print a set of address labels. Input from a csv file.
Chapter 8: Plotting. After completing this Chapter, you will be able to use the following features: Planning the Plot Sheet Plotting Environments Plotting.
Pasewark & Pasewark 1 Access Lesson 5 Creating and Modifying Reports Microsoft Office 2007: Introductory.
Using Command Options IBA Mrs. Brown. Bell Ringer What is does it mean to Cascade windows What does it mean to tile windows SAVE YOUR RESPONSE FOR LATER.
Fireworks Web Page mockups. Set up canvas/page size Fireworks is very well-suited to designing graphics and web pages for the screen. To create a web.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to the Visual Studio.NET IDE Outline 2.1Introduction 2.2Visual Studio.NET Integrated.
Architecture Multi Layered Architecture (n-tier): Application: Model Controllers Database Access Graphical User Interface (GUI): Forms, components, controls.
1 Printing a Document. 2 Objectives You will be able to print a real multipage document.
1111 Creating ASPX Controls Programatically Objectives You will be able to Dynamically add controls to a page. Dynamically alter properties of controls.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Address Book Application Introducing Database Programming.
11 Introduction to Object Oriented Programming (Continued) Cats.
Collaborate. Coordinate. Evaluate. Connecting Communities > Demonstrating Outcomes ™ / I&R Housing Youth & Family Services Older Adult Services ShelterPoint™
11 User Controls Beginning ASP.NET in C# and VB Chapter 8.
XP New Perspectives on Macromedia Dreamweaver MX 2004 Tutorial 5 1 Adding Shared Site Elements.
Integrating Components and Dynamic Text Boxes with the Animated Map– Lesson 101 Integrating Components and Dynamic Text Boxes with the Animated Map Lesson.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
Visual Basic .NET BASICS
Creating & Working with Clipping Masks
Microsoft Visual Basic 2005 BASICS
Chapter 2 – Introduction to the Visual Studio .NET IDE
Reference: COS240 Syllabus
Chapter 1: An Introduction to Visual Basic 2015
Chapter 2 – Introduction to the Visual Studio .NET IDE
Extend Text Editor to Draw shapes
Overview of the IDE Visual Studio .NET is Microsoft’s Integrated Development Environment (IDE) for creating, running and debugging programs (also.
Presentation transcript:

1 Scroll Bars Providing Scrollbars

2 Objectives You will be able to: Use Windows Graphics to display tabular information on a Windows form. Add graphics capability to objects. Provide scroll bars on a Windows form.

3 Object Oriented Drawing and Printing In an object oriented program, everything that appears on the screen should be the visual representation of an object. Objects should know how to draw themselves. Printing is essentially the same.

4 Schedule Grid Let’s modify the Schedule Viewer program to use Windows graphics instead of the DataGridView. We will teach the Schedule_Record class how to draw itself.

5 Schedule Grid In order for schedule entries to fit on one line with legible type, display only: Course Number Section Course Title Days Time Building Room

6 Menu Provide a File menu with commands: Open Print Exit Use the common dialog for Open. Menu commands should be enabled only when relevant. Enable Print only when there is something to print. Disable Open once a file is open.

7 Scroll Bars Provide scroll bars to permit the user to view all of the schedule when it doesn’t fit in the window. The scroll bars should not be visible if the schedule fits in the window.

8 Start with Schedule Viewer Example Download the example Downloads/2011_02_22_Schedule_Viewer_2/ Downloads/2011_02_22_Schedule_Viewer_2/ File Schedule_Viewer.zip Also the schedule data files schedule_2010_fall.csv schedule_2010_spring.csv schedule_2011_spring.csv

9 Getting Started Be sure we have a known Starting Point Expand and build the project. Verify that the program works.

10 Out with the old! Delete the DataGridView. Keep the menu strip and openFileDialog.

11 Stripped Down Project

12 Out with the old! View the code for Form1.cs Delete all of the DataGridView code. Lines (Most of openToolSTripMenuItem_Click) Lines (Most of Form1 constructor ) Keep file and menu related functions Build. Verify that project compiles.

13 In With the New! Add some member variables to Form1 using System.Drawing;... public partial class Form1 : Form { List Schedule; // Graphics information Font Font1 = new Font("Arial", 10); Brush Brush1 = SystemBrushes.WindowText; // Screen information const int Top_Margin = 30; const int Bottom_Margin = 30; const int Left_Margin = 20;

14 Add Graphics Add Output method to class Schedule_Record. Initially make it a stub Just output “Schedule Entry” public void Output(Graphics G, Font F, Brush B, Point P) { Pen pen = new Pen(Color.Black, 1); G.DrawString("Schedule Entry", F, B, P); } Will need using System.Drawing;

15 Add a Paint Event Handler to Form1 private void Form1_Paint(object sender, PaintEventArgs e) { int y_pos = Top_Margin; if ((Schedule == null) || (Schedule.Count == 0)) { return; } for (int i = 0; i < Schedule.Count; i++) { Point P = new Point(Left_Margin, y_pos); Schedule[i].Output(e.Graphics, Font1, Brush1, P); y_pos += Font1.Height; }

16 Open private void openToolStripMenuItem_Click(object sender, EventArgs e) { Import_Schedule(); this.Invalidate(); this.Update(); } Build and run. In Form1.cs

17 Program Running

18 Teaching the Schedule Record to Output Itself A Schedule Record object should know how to draw itself on the screen or a printed page. But it must be told: Where to draw itself. The drawing objects to use: Graphics Font Brush Download: Downloads/2011_03_22_Scroll_Bars/Output.cs Downloads/2011_03_22_Scroll_Bars/Output.cs

19 Implement Schedule_Record Output() public void Output(Graphics G, Font F, Brush B, Point P) { Pen pen = new Pen(Color.Black, 1); int X_Pos = P.X; int Y_Pos = P.Y; Rectangle R = new Rectangle(X_Pos, Y_Pos, 75, F.Height); G.DrawString(course_number, F, B, R); G.DrawRectangle(pen, R); X_Pos += R.Width; R = new Rectangle(X_Pos, Y_Pos, 40, F.Height); G.DrawString(section.ToString(), F, B, R); G.DrawRectangle(pen, R); X_Pos += R.Width; R = new Rectangle(X_Pos, Y_Pos, 250, F.Height); G.DrawString(course_title, F, B, R); G.DrawRectangle(pen, R); X_Pos += R.Width;

20 Schedule_Record Output() R = new Rectangle(X_Pos, Y_Pos, 75, F.Height); G.DrawString(days, F, B, R); G.DrawRectangle(pen, R); X_Pos += R.Width; R = new Rectangle(X_Pos, Y_Pos, 160, F.Height); G.DrawString(time, F, B, R); G.DrawRectangle(pen, R); X_Pos += R.Width; R = new Rectangle(X_Pos, Y_Pos, 40, F.Height); G.DrawString(building, F, B, R); G.DrawRectangle(pen, R); X_Pos += R.Width; R = new Rectangle(X_Pos, Y_Pos, 60, F.Height); G.DrawString(room, F, B, R); G.DrawRectangle(pen, R); X_Pos += R.Width; }

21 Program Running Note that the schedule runs off the page.

22 Scroll Bars Let’s add scroll bars. The Form object will do most of the work for us. For documentation search for autoscroll in Visual Studio Help.

23 Autoscroll To get automatic scrollling we must: Set the Autoscroll property to True. Set AutoScrollMinSize property Scroll bars will be added if form is smaller. Data dependent! Adjust X and Y coordinates for output to account for scrolling: AutoScrollPosition.X; AutoScrollPosition.Y;

24 In Schedule_Record.cs In class definition: private static int line_width = 500; public static int Line_width { get { return line_width; } } At end of function Output() line_width = X_Pos;

25 Form1_Paint At top of function: if ((Schedule == null) || (Schedule.Count < 1)) { return; } int Document_Length = Schedule.Count * Font1.Height + Top_Margin + Bottom_Margin; int line_width = Schedule_Record.Line_width; this.AutoScrollMinSize = new Size(Left_Margin + line_width, Document_Length); int dx = this.AutoScrollPosition.X; int dy = this.AutoScrollPosition.Y;... Point P = new Point(Left_Margin + dx, y_pos + dy);

26 We have scroll bars!

27 Just One Problem The menu scrolls off the screen! Need to scroll just the area below the menu. How?

28 Saving the Menu Put a Panel below the menu Fill rest of form Draw on the Panel rather than the form. Scroll the panel.

29 Form with Panel

30 Configure the Panel Position and size the panel to fill the form below the menu strip. Anchor it on all sides.

31 Configure the Panel

32 Drawing on the Panel Now we need to draw on the panel rather than the form. Set AutoScroll true. Add a Paint event handler for the panel. Move the contents of Form1_Paint to panel1_Paint.

33 Scrolling the Panel Change the scrolling information from form1 to panel1. In openToolStripMenuItem_Click ()... this.panel1.Invalidate(); this.panel1.Update(); In panel1_Paint ()... this.panel1.AutoScrollMinSize = new Size(Schedule_Record.Line_Width, Document_Length); int dx = this.panel1.AutoScrollPosition.X; int dy = this.panel1.AutoScrollPosition.Y;

34 Program Running

35 Some Finishing Touches Change panel1 BackColor to white. Add a bit of space below the panel. Set the Text property of Form1 CSE Schedule

36 Some Finishing Touches

37 Program Running