1 / 13

Control Models

Control Models. Jim Fawcett CSE775 – Distributed Objects Spring 2007. Control Types. Components Hosted by toolbox and in Form’s tray Controls Visible interface hosted by toolbox and on Form’s surface UserControls Composite control Container for controls Control for forms

liona
Download Presentation

Control Models

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. Control Models Jim Fawcett CSE775 – Distributed Objects Spring 2007

  2. Control Types • Components • Hosted by toolbox and in Form’s tray • Controls • Visible interface hosted by toolbox and on Form’s surface • UserControls • Composite control • Container for controls • Control for forms • Derived Controls • Any of the above, with much functionality provided by a base component or controls .Net Control Model

  3. What it takes to be a Component • Class that implements the IComponent interface • Can be hosted in containers • Reusable,configurable classes • Don’t have hosted UI, keyboard, and mouse processing • Components may have Tooltip or dialog UI, e.g., OpenFileDialog and SaveFileDialog. • Neither of these requires Form real-estate .Net Control Model

  4. What it takes to be a Component • When pulled onto a Form, components: • Join the form’s System.ComponentModel.Container • Are given, in their constructor, a reference to ComponentModel.Container • If the component exposes properties and events these are automatically integrated with the Form Designer’s property window • A component does this by defining .Net class properties and delegates .Net Control Model

  5. BackgroundWorker DirectoryEntry DirectorySearcher ErrorProvider EventLog FileSystemWatcher HelpProvider ImageList MessageQueue PerformanceCounter Process SerialPort ServiceController Timer Standard Components .Net Control Model

  6. Building a Custom Component • You can create a component this way: • Use the project wizard to create a Windows Forms Control library • Change the base class to: System::ComponentModel::Component • In the constructor add the line of code:container->Add(this); • Change the contents of the InitializeComponent() method to the line of code:this->components = gcnew System::ComponentModel::Container(); .Net Control Model

  7. An even easier way is to: Build a Windows Forms Application Right-click on the Form project and select add new item Add Component Class A blank design view will appear onto which you can, but do not have to, pull other components from the toolbox Building a Custom Component .Net Control Model

  8. Here is the result of pulling on the DirectorySearcher .Net Control Model

  9. Controls • What it takes to be a control: • Derive from System::Windows::Forms::Control or UserControl or a previously defined .Net Control • Provide a UI via overriding Control::OnPaint • Provide properties and events .Net Control Model

  10. Button Checkbox ComboBox DataGridView DomainUpDown FlowLayoutPanel GroupBox ListBox LinkLabel ListView MonthCalendar Panel PictureBox ProgressBar RadioButton RichTextBox SplitContainer StatusStrip TreeView Many more … Standard Controls .Net Control Model

  11. Build a Custom Control • Easiest way is to derive from a control that already does most of what you need: • New Project/Windows Forms Control Library • Change the base class from UserControl to the control you want to inherit from • Add additional methods, properties, and events .Net Control Model

  12. Build a Custom Control • Alternately, do as in the previous slide, except, instead of changing from UserControl to an existing control, change to Control, the base for all controls. • Now, you will have to provide all the methods, properties, events, and UI by overriding the Control::OnPaint method .Net Control Model

  13. Examples • You will find examples of a component and a custom control in: • Handouts/CSE775/code/Custom-Component • Handouts/CSE775/code/Custom-Control .Net Control Model

More Related