Меню Рубрики

Windows forms control library

Controls to Use on Windows Forms

The following is an alphabetic list of controls and components that can be used on Windows Forms. In addition to the Windows Forms controls covered in this section, you can add ActiveX and custom controls to Windows Forms. If you do not find the control you need listed here, you can also create your own. For details, see Developing Windows Forms Controls at Design Time. For more information about choosing the control you need, see Windows Forms Controls by Function.

Visual Basic controls are based on classes provided by the .NET Framework.

In This Section

Windows Forms Controls by Function
Lists and describes Windows Forms controls based on the .NET Framework.

Controls with Built-In Owner-Drawing Support
Describes how to alter aspects of a control’s appearance that are not available through properties.

BackgroundWorker Component
Enables a form or control to run an operation asynchronously.

BindingNavigator Control
Provides the navigation and manipulation user interface (UI) for controls that are bound to data.

BindingSource Component
Encapsulates a data source for binding to controls.

Button Control
Presents a standard button that the user can click to perform actions.

CheckBox Control
Indicates whether a condition is on or off.

CheckedListBox Control
Displays a list of items with a check box next to each item.

ColorDialog Component
Allows the user to select a color from a palette in a pre-configured dialog box and to add custom colors to that palette.

ComboBox Control
Displays data in a drop-down combo box.

ContextMenu Component
Provides users with an easily accessible menu of frequently used commands that are associated with the selected object. Although ContextMenuStrip replaces and adds functionality to the ContextMenu control of previous versions, ContextMenu is retained for both backward compatibility and future use if so desired.

ContextMenuStrip Control
Represents a shortcut menu. Although ContextMenuStrip replaces and adds functionality to the ContextMenu control of previous versions, ContextMenu is retained for both backward compatibility and future use if so desired.

DataGrid Control
Displays tabular data from a dataset and allows for updates to the data source.

DataGridView Control
Provides a flexible, extensible system for displaying and editing tabular data.

DateTimePicker Control
Allows the user to select a single item from a list of dates or times.

Dialog-Box Controls and Components
Describes a set of controls that allow users to perform standard interactions with the application or system.

DomainUpDown Control
Displays text strings that a user can browse through and select from.

ErrorProvider Component
Displays error information to the user in a non-intrusive way.

FileDialog Class Provides base-class functionality for file dialog boxes.

FlowLayoutPanel Control
Represents a panel that dynamically lays out its contents horizontally or vertically.

FolderBrowserDialog Component
Displays an interface with which users can browse and select a directory or create a new one.

FontDialog Component
Exposes the fonts that are currently installed on the system.

GroupBox Control
Provides an identifiable grouping for other controls.

HelpProvider Component
Associates an HTML Help file with a Windows-based application.

HScrollBar and VScrollBar Controls
Provide navigation through a list of items or a large amount of information by scrolling either horizontally or vertically within an application or control.

ImageList Component
Displays images on other controls.

Label Control
Displays text that cannot be edited by the user.

LinkLabel Control
Allows you to add Web-style links to Windows Forms applications.

ListBox Control
Allows the user to select one or more items from a predefined list.

ListView Control
Displays a list of items with icons, in the manner of Windows Explorer.

MainMenu Component
Displays a menu at run time. Although MenuStrip replaces and adds functionality to the MainMenu control of previous versions, MainMenu is retained for both backward compatibility and future use if you choose.

MaskedTextBox Control
Constrains the format of user input in a form.

MenuStrip Control
Provides a menu system for a form. Although MenuStrip replaces and adds functionality to the MainMenu control of previous versions, MainMenu is retained for both backward compatibility and future use if you choose.

MonthCalendar Control
Presents an intuitive graphical interface for users to view and set date information.

NotifyIcon Component
Displays icons for processes that run in the background and would not otherwise have user interfaces.

NumericUpDown Control
Displays numerals that a user can browse through and select from.

OpenFileDialog Component
Allows users to open files by using a pre-configured dialog box.

PageSetupDialog Component
Sets page details for printing through a pre-configured dialog box.

Panel Control
Provide an identifiable grouping for other controls, and allows for scrolling.

PictureBox Control
Displays graphics in bitmap, GIF, JPEG, metafile, or icon format.

PrintDialog Component
Selects a printer, chooses the pages to print, and determines other print-related settings.

PrintDocument Component
Sets the properties that describe what to print, and prints the document in Windows-based applications.

PrintPreviewControl Control
Allows you to create your own PrintPreview component or dialog box instead of using the pre-configured version.

PrintPreviewDialog Control
Displays a document as it will appear when it is printed.

ProgressBar Control
Graphically indicates the progress of an action towards completion.

RadioButton Control
Presents a set of two or more mutually exclusive options to the user.

RichTextBox Control
Allows users to enter, display, and manipulate text with formatting.

SaveFileDialog Component
Selects files to save and where to save them.

SoundPlayer Class Enables you to easily include sounds in your applications.

SplitContainer Control
Allows the user to resize a docked control.

Splitter Control
Allows the user to resize a docked control (.NET Framework version 1.x).

StatusBar Control
Displays status information related to the control that has focus. Although StatusStrip replaces and extends the StatusBar control of previous versions, StatusBar is retained for both backward compatibility and future use if you choose.

StatusStrip Control
Represents a Windows status bar control. Although StatusStrip replaces and extends the StatusBar control of previous versions, StatusBar is retained for both backward compatibility and future use if you choose.

TabControl Control
Displays multiple tabs that can contain pictures or other controls.

TableLayoutPanel Control
Represents a panel that dynamically lays out its contents in a grid composed of rows and columns.

TextBox Control
Allows editable, multiline input from the user.

Timer Component
Raises an event at regular intervals.

ToolBar Control
Displays menus and bitmapped buttons that activate commands. You can extend the functionality of the control and modify its appearance and behavior. Although ToolStrip replaces and adds functionality to the ToolBar control of previous versions, ToolBar is retained for both backward compatibility and future use if you choose.

ToolStrip Control
Creates custom toolbars and menus in your Windows Forms applications. Although ToolStrip replaces and adds functionality to the ToolBar control of previous versions, ToolBar is retained for both backward compatibility and future use if you choose.

ToolStripContainer Control
Provides panels on each side of a form for docking, rafting, and arranging ToolStrip controls, and a central ToolStripContentPanel for traditional controls.

ToolStripPanel Control
Provides one panel for docking, rafting and arranging ToolStrip controls.

ToolStripProgressBar Control Overview
Graphically indicates the progress of an action towards completion. The ToolStripProgressBar is typically contained in a StatusStrip.

ToolTip Component
Displays text when the user points at other controls.

TrackBar Control
Allows navigation through a large amount of information or visually adjusting a numeric setting.

TreeView Control
Displays a hierarchy of nodes that can be expanded or collapsed.

WebBrowser Control
Hosts Web pages and provides Internet Web browsing capabilities to your application.

Windows Forms Controls Used to List Options
Describes a set of controls used to provide users with a list of options to choose from.

Related Sections

Windows Forms Controls
Explains the use of Windows Forms controls, and describes important concepts for working with them.

Developing Windows Forms Controls at Design Time
Provides links to step-by-step topics, recommendations for which kind of control to create, and other information about creating your own control.

Controls and Programmable Objects Compared in Various Languages and Libraries
Provides a table that maps controls in Visual Basic 6.0 to the corresponding control in Visual Basic .NET. Note that controls are now classes in the .NET Framework.

How to: Add ActiveX Controls to Windows Forms
Describes how to use ActiveX controls on Windows Forms.

Источник

Walkthrough: Author a Composite Control with C#

Composite controls provide a means by which custom graphical interfaces can be created and reused. A composite control is essentially a component with a visual representation. As such, it might consist of one or more Windows Forms controls, components, or blocks of code that can extend functionality by validating user input, modifying display properties, or performing other tasks required by the author. Composite controls can be placed on Windows Forms in the same manner as other controls. In the first part of this walkthrough, you create a simple composite control called ctlClock . In the second part of the walkthrough, you extend the functionality of ctlClock through inheritance.

Create the Project

When you create a new project, you specify its name to set the root namespace, assembly name, and project name, and ensure that the default component will be in the correct namespace.

To create the ctlClockLib control library and the ctlClock control

In Visual Studio, create a new Windows Forms Control Library project, and name it ctlClockLib.

The project name, ctlClockLib , is also assigned to the root namespace by default. The root namespace is used to qualify the names of components in the assembly. For example, if two assemblies provide components named ctlClock , you can specify your ctlClock component using ctlClockLib.ctlClock.

In Solution Explorer, right-click UserControl1.cs, and then click Rename. Change the file name to ctlClock.cs . Click the Yes button when you are asked if you want to rename all references to the code element «UserControl1».

By default, a composite control inherits from the UserControl class provided by the system. The UserControl class provides functionality required by all composite controls, and implements standard methods and properties.

On the File menu, click Save All to save the project.

Add Windows Controls and Components to the Composite Control

A visual interface is an essential part of your composite control. This visual interface is implemented by the addition of one or more Windows controls to the designer surface. In the following demonstration, you will incorporate Windows controls into your composite control and write code to implement functionality.

To add a Label and a Timer to your composite control

In Solution Explorer, right-click ctlClock.cs, and then click View Designer.

In the Toolbox, expand the Common Controls node, and then double-click Label.

A Label control named label1 is added to your control on the designer surface.

In the designer, click label1. In the Properties window, set the following properties.

Property Change to
Name lblDisplay
Text (blank space)
TextAlign MiddleCenter
Font.Size 14

In the Toolbox, expand the Components node, and then double-click Timer.

Because a Timer is a component, it has no visual representation at run time. Therefore, it does not appear with the controls on the designer surface, but rather in the Component Designer (a tray at the bottom of the designer surface).

In the Component Designer, click timer1, and then set the Interval property to 1000 and the Enabled property to true .

The Interval property controls the frequency with which the Timer component ticks. Each time timer1 ticks, it runs the code in the timer1_Tick event. The interval represents the number of milliseconds between ticks.

In the Component Designer, double-click timer1 to go to the timer1_Tick event for ctlClock .

Modify the code so that it resembles the following code sample. Be sure to change the access modifier from private to protected .

This code will cause the current time to be shown in lblDisplay . Because the interval of timer1 was set to 1000 , this event will occur every thousand milliseconds, thus updating the current time every second.

Modify the method to be overridable with the virtual keyword. For more information, see the «Inheriting from a User Control» section below.

On the File menu, click Save All to save the project.

Add Properties to the Composite Control

Your clock control now encapsulates a Label control and a Timer component, each with its own set of inherent properties. While the individual properties of these controls will not be accessible to subsequent users of your control, you can create and expose custom properties by writing the appropriate blocks of code. In the following procedure, you will add properties to your control that enable the user to change the color of the background and text.

To add a property to your composite control

In Solution Explorer, right-click ctlClock.cs, and then click View Code.

The Code Editor for your control opens.

Locate the public partial class ctlClock statement. Beneath the opening brace ( <) , type the following code.

These statements create the private variables that you will use to store the values for the properties you are about to create.

Enter or paste the following code beneath the variable declarations from step 2.

The preceding code makes two custom properties, ClockForeColor and ClockBackColor , available to subsequent users of this control. The get and set statements provide for storage and retrieval of the property value, as well as code to implement functionality appropriate to the property.

On the File menu, click Save All to save the project.

Test the Control

Controls are not stand-alone applications; they must be hosted in a container. Test your control’s run-time behavior and exercise its properties with the UserControl Test Container. For more information, see How to: Test the Run-Time Behavior of a UserControl.

To test your control

Press F5 to build the project and run your control in the UserControl Test Container.

In the test container’s property grid, locate the ClockBackColor property, and then select the property to display the color palette.

Choose a color by clicking it.

The background color of your control changes to the color you selected.

Use a similar sequence of events to verify that the ClockForeColor property is functioning as expected.

In this section and the preceding sections, you have seen how components and Windows controls can be combined with code and packaging to provide custom functionality in the form of a composite control. You have learned to expose properties in your composite control, and how to test your control after it is complete. In the next section you will learn how to construct an inherited composite control using ctlClock as a base.

Inherit from a Composite Control

In the previous sections, you learned how to combine Windows controls, components, and code into reusable composite controls. Your composite control can now be used as a base upon which other controls can be built. The process of deriving a class from a base class is called inheritance. In this section, you will create a composite control called ctlAlarmClock . This control will be derived from its parent control, ctlClock . You will learn to extend the functionality of ctlClock by overriding parent methods and adding new methods and properties.

The first step in creating an inherited control is to derive it from its parent. This action creates a new control that has all of the properties, methods, and graphical characteristics of the parent control, but can also act as a base for the addition of new or modified functionality.

To create the inherited control

In Solution Explorer, right-click ctlClockLib, point to Add, and then click User Control.

The Add New Item dialog box opens.

Select the Inherited User Control template.

In the Name box, type ctlAlarmClock.cs , and then click Add.

The Inheritance Picker dialog box appears.

Under Component Name, double-click ctlClock.

In Solution Explorer, browse through the current projects.

A file called ctlAlarmClock.cs has been added to the current project.

Add the Alarm Properties

Properties are added to an inherited control in the same way they are added to a composite control. You will now use the property declaration syntax to add two properties to your control: AlarmTime , which will store the value of the date and time the alarm is to go off, and AlarmSet , which will indicate whether the alarm is set.

To add properties to your composite control

In Solution Explorer, right-click ctlAlarmClock, and then click View Code.

Locate the public class statement. Note that your control inherits from ctlClockLib.ctlClock . Beneath the opening brace ( <) statement, type the following code.

Add to the Graphical Interface of the Control

Your inherited control has a visual interface that is identical to the control it inherits from. It possesses the same constituent controls as its parent control, but the properties of the constituent controls will not be available unless they were specifically exposed. You may add to the graphical interface of an inherited composite control in the same manner as you would add to any composite control. To continue adding to your alarm clock’s visual interface, you will add a label control that will flash when the alarm is sounding.

To add the label control

In Solution Explorer, right-click ctlAlarmClock, and then click View Designer.

The designer for ctlAlarmClock opens in the main window.

Click the display portion of the control, and view the Properties window.

While all the properties are displayed, they are dimmed. This indicates that these properties are native to lblDisplay and cannot be modified or accessed in the Properties window. By default, controls contained in a composite control are private , and their properties are not accessible by any means.

If you want subsequent users of your composite control to have access to its internal controls, declare them as public or protected . This will allow you to set and modify properties of controls contained within your composite control by using the appropriate code.

Add a Label control to your composite control.

Using the mouse, drag the Label control immediately beneath the display box. In the Properties window, set the following properties.

Property Setting
Name lblAlarm
Text Alarm!
TextAlign MiddleCenter
Visible false

Add the Alarm Functionality

In the previous procedures, you added properties and a control that will enable alarm functionality in your composite control. In this procedure, you will add code to compare the current time to the alarm time and, if they are the same, to flash an alarm. By overriding the timer1_Tick method of ctlClock and adding additional code to it, you will extend the capability of ctlAlarmClock while retaining all of the inherent functionality of ctlClock .

To override the timer1_Tick method of ctlClock

In the Code Editor, locate the private bool blnAlarmSet; statement. Immediately beneath it, add the following statement.

In the Code Editor, locate the closing brace ( >) at the end of the class. Just before the brace, add the following code.

The addition of this code accomplishes several tasks. The override statement directs the control to use this method in place of the method that was inherited from the base control. When this method is called, it calls the method it overrides by invoking the base.timer1_Tick statement, ensuring that all of the functionality incorporated in the original control is reproduced in this control. It then runs additional code to incorporate the alarm functionality. A flashing label control will appear when the alarm occurs.

Your alarm clock control is almost complete. The only thing that remains is to implement a way to turn it off. To do this, you will add code to the lblAlarm_Click method.

To implement the shutoff method

In Solution Explorer, right-click ctlAlarmClock.cs, and then click View Designer.

The designer opens.

Add a button to the control. Set the properties of the button as follows.

Property Value
Name btnAlarmOff
Text Disable Alarm

In the designer, double-click btnAlarmOff.

The Code Editor opens to the private void btnAlarmOff_Click line.

Modify this method so that it resembles the following code.

On the File menu, click Save All to save the project.

Use the Inherited Control on a Form

You can test your inherited control the same way you tested the base class control, ctlClock : Press F5 to build the project and run your control in the UserControl Test Container. For more information, see How to: Test the Run-Time Behavior of a UserControl.

To put your control to use, you will need to host it on a form. As with a standard composite control, an inherited composite control cannot stand alone and must be hosted in a form or other container. Since ctlAlarmClock has a greater depth of functionality, additional code is required to test it. In this procedure, you will write a simple program to test the functionality of ctlAlarmClock . You will write code to set and display the AlarmTime property of ctlAlarmClock , and will test its inherent functions.

To build and add your control to a test form

In Solution Explorer, right-click ctlClockLib, and then click Build.

Add a new Windows Forms Application project to the solution, and name it Test.

In Solution Explorer, right-click the References node for your test project. Click Add Reference to display the Add Reference dialog box. Click the tab labeled Projects. Your ctlClockLib project will be listed under Project Name. Double-click the project to add the reference to the test project.

In Solution Explorer, right-click Test, and then click Build.

In the Toolbox, expand the ctlClockLib Components node.

Double-click ctlAlarmClock to add a copy of ctlAlarmClock to your form.

In the Toolbox, locate and double-click DateTimePicker to add a DateTimePicker control to your form, and then add a Label control by double-clicking Label.

Use the mouse to position the controls in a convenient place on the form.

Set the properties of these controls in the following manner.

Control Property Value
label1 Text (blank space)
Name lblTest
dateTimePicker1 Name dtpTest
Format Time

In the designer, double-click dtpTest.

The Code Editor opens to private void dtpTest_ValueChanged .

Modify the code so that it resembles the following.

In Solution Explorer, right-click Test, and then click Set as StartUp Project.

On the Debug menu, click Start Debugging.

The test program starts. Note that the current time is updated in the ctlAlarmClock control, and that the starting time is shown in the DateTimePicker control.

Click the DateTimePicker where the minutes of the hour are displayed.

Using the keyboard, set a value for minutes that is one minute greater than the current time shown by ctlAlarmClock .

The time for the alarm setting is shown in lblTest . Wait for the displayed time to reach the alarm setting time. When the displayed time reaches the time to which the alarm is set, the lblAlarm will flash.

Turn off the alarm by clicking btnAlarmOff . You may now reset the alarm.

This article has covered a number of key concepts. You have learned to create a composite control by combining controls and components into a composite control container. You have learned to add properties to your control, and to write code to implement custom functionality. In the last section, you learned to extend the functionality of a given composite control through inheritance, and to alter the functionality of host methods by overriding those methods.

Источник

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *

  • Windows forms c текстовый редактор
  • Windows forms c игра
  • Windows forms c datagridview
  • Windows forms button click
  • Windows format fat32 windows 7