1 / 23

Windows Programming

Windows Programming. C# Software Development. Overview. DLLs / PInvoke DirectX .NET Component Library Custom Controls Event Model (in C++) GUI Events Custom Filters Drawing, Painting, Printing. Using DLLs. To gain access to a DLL, use the DllImport attribute to tag the method

suzuki
Download Presentation

Windows Programming

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. Windows Programming C# Software Development

  2. Overview • DLLs / PInvoke • DirectX • .NET Component Library • Custom Controls • Event Model (in C++) • GUI Events • Custom Filters • Drawing, Painting, Printing

  3. Using DLLs • To gain access to a DLL, use the DllImport attribute to tag the method • Use the extern keyword on the method • Return/parameter types don't necessarily need to match • only the datatype size needs to match DllImport("gdi32.dll")] public static extern int SetPixel(int hDC, int x, int y, int crColor);

  4. PInvoke • Calling a dll method is called P-Invoke (platform invoke) • Simply call the method • Some types (hdc, handles, etc) are exposed in the .NET interface (See WindowsManipulation and SetPixel Demos)

  5. DirectX • See Mike Go • Go Mike Go

  6. .NET Component Library • System.Windows.Forms.Control • Base class for controls • Visual Components • Handles Keyboard and Mouse Input • Provides bounds for painting • Does not actually paint anything by default • Provides a Windows Handle • Has ambient properties • if not set, an ambient property uses its parent's value • Provides accessibility support (See MSDN)

  7. Windows Forms • Properties • Text • Text on top of the form • BackColor • Background color • ForeColor • Text Color • Font • Font used by child controls • FormBorderStyle • Border Style • ControlBox • Minimize, Maximize and Close buttons • ShowInTaskbar • Indicates whether to show in the taskbar or not

  8. Splash screen • On a Form, set: • Text = ""; • ControlBox = false; • Create a Panel with the BackgroundImage property set to your picture

  9. Menus • Create a Context Menu or a MainMenu • Associate it with the Form (or Control)

  10. Adding Controls Programmatically • Form (or any other container control) has a Controls property Button newBtn = new Button … this.Controls.Add(newBtn);

  11. Custom Controls • Create a new UserControl file in your project • Default UserControl class inherits from UserControl • You can inherit from a pre-built control (like button) or from Control itself

  12. UserControl Attributes • ToolboxBitmap • Sets the icon for the UserControl • Browsable • Pass it false to prevent the member from being displayed • Category • Places the control in the specified category • DefaultValue • Sets a default value for the member • Description • Sets the description associated with the member • DesignOnly • Specifies that the member can only be set at design time

  13. Adding UserControls to Toolbox • Build the UserControl • Right-click the toolbox • Choose Add/Remove, browse to the built assembly (.dll or .exe file).

  14. Painting • Subscribe to the Paint event • Gives access to the appropriate Graphics object • Call Refresh() • Invalidates the entire client area including child controls • Call Invalidate() • Invalidates the given region (client area by default) • Some controls have BeginUpdate and EndUpdate methods • BeginUpdate disables drawing • Call when you are changing/updating the control • EndUpdate enables drawing • Call when you are finished changing/updating the control

  15. Paint Event • private void Form1_Paint(object sender, PaintEventArgs e) • PaintEventArgs contains: • ClipRectangle being painted • Graphics for the current object

  16. Graphics object • Methods: • Clear() • DrawArc() • DrawBezier() • etc. (See DrawDemo)

  17. Brushes • System.Drawing.Brush • abstract class • Subclasses: • HatchBrush • LinearGradientBrush • PathGradientBrush • SolidBrush • TextureBrush • Can get texture from an image • Represents a color, gradient, image etc. • Fills the interior region of an area • Must be disposed when you're finished using it • Limited resource on Win9x/Me (as are pens)

  18. Brush example: • Brush brush = new SolidBrush(Color.Red); • Brush brush = new TextureBrush(new Bitmap("MyImage.gif")); • Brush brush = Brushes.Brown;

  19. System.Drawing.Brushes • System-stored default brushes • All kinds of crazy colors • Do not dispose System-stored resources • SolidBrush type

  20. Pens • System.Drawing.Pen • Represent a color and width • Used to draw lines and curves • Has an associated brush • Can set: • DashPattern • DashCap • StartCap (arrow, etc) • EndCap • etc. • Need to be disposed when finished using

  21. System.Drawing.Pens • System-stored default pens • All kinds of crazy colors • Do not dispose System-stored resources • Also System.Drawing.SystemPens

  22. Fonts • Immutable • To change a font, you must create a new one, then reassign the property

  23. Color • Represents an ARGB color • Contains hundreds of Pre-defined colors

More Related