270 likes | 378 Vues
Learn how to write custom class methods to return derived values, use absolute and relative positioning for picture boxes, and implement static and dynamic tool tip text. Enhance efficiency and accuracy in your code through derived values.
E N D
D101 Software Developmemt Custom Classes II
Content • Custom Class Methods • Returning Derived Values • Area • Height • Picture Box Positioning • Absolute Positioning • Relative Positioning • ToolTips
Learning Outcomes • Write custom class methods that return derived values (e.g. area, total height) • Use absolute positioning to position picture boxes • Use relative positioning to position picture boxes • Implement static and dynamic tool tip text
Custom Class Methods • Derived Values: • A derived value is a value that can be figured out based on another information • It therefore does not need to be stored as it’s own value • Using derived values increase efficiency and accuracy of code
Derived Values • What is the area of these two picture boxes? • Blue is: • 10 wide • 70 high • Red is: • 70 wide • 10 high
Positioning • Every C# Control has a location property • The location property consists of an X and Y integer value • These are coordinates • The X and Y values determine the location of the top left corner of the control • X is the number of pixels across • Y is the number of pixels down
Positioning • The position of a picture box can be set as follows: X Y
Positioning • The X and Y coordinates can be set individually using the Left and Top properties • X = Left • Y = Top
Positioning • Picture Box at location 0,0
Positioning • Picture Box at location 0, 40
Positioning • Picture box at location 40, 0
Positioning • Picture Box at location 40, 40
Positioning • Example Application (absolute positioning) tbxX tbxY
Positioning • Location 0,0 is in the top left corner of the From • However, for controls located inside a panel, Location 0,0 becomes the top left corner of the Panel
Positioning • The Picture Box is in Location 40, 0
Positioning • Horizontally centering a picture box How do we figure out where the top left corner should be? Are there other values we can derive it from?
Positioning • Horizontally centering a picture box in a panel Good Reminder - Follow this link
Positioning • Horizontally centering a picture box relative to another picture box
Positioning • Relative Positioning
Positioning • Horizontally centering a picture box relative to another picture box (relative positioning)
Tool Tips • Introducing the ToolTip control
ToolTips • Once a ToolTip control has been added to the project it can be used to add tool tips to multiple controls • This text shows up when the mouse hovers
ToolTips • Changing the ToolTip Text dynamically at runtime
Review • Can you: • Write custom class methods that return derived values (e.g. area, total height)? • Use absolute positioning to position picture boxes? • Use relative positioning to position picture boxes? • Implement static and dynamic tool tip text?