WinForm Control Development Summary (ix) for attributes pull-down property editor

Source: Internet
Author: User
Tags min

In the previous article, I introduced how to write the modal Dialog property Editor, which I'll describe how to write a Drop-down property editor. The difference between the drop-down (DropDown) property Editor and the modal Dialog property Editor is that when you click on the attribute value change, the modal dialog editor is a modal dialog box, and the Drop-down property Editor displays a Drop-down control where the property value is pressed. Do not know that you have noticed no, here I said is to display a Drop-down control, and this control is also required you to develop, next I still take the scope attribute as an example, to introduce the specific implementation.

First we're going to create a control for editing properties, and at the beginning of this series we've covered three types of custom controls: Composite controls, extended controls, and custom controls. In this example we make a composite control (Compsite controls), the development of composite control is relatively simple, not the scope of this series of articles, I simply do an introduction, in the Solution browser right click Customcontrolsample Project Selection add- >user control ..., enter filename ScopeEditorControl.cs. We did this composite control. The modal dialog box contained in the previous article is basically the same as the child controls, except for the confirmation and cancellation buttons, as shown below:

Since we canceled the button for confirmation and cancellation, and is a Drop-down editor control, the Drop-down editor control closes when the following three situations occur: the user knocks in return, the user knocks the ESC key, and the user clicks outside the editor. We need to update the value of the property when the immediate Drop-down editor control closes. Below is the code for this control:

Using System;

Using System.Collections.Generic;

Using System.ComponentModel;

Using System.Drawing;

Using System.Data;

Using System.Text;


Using System.Windows.Forms; namespace Customcontrolsample {public partial class Scopeeditorcontrol:usercontrol {private Scope

        _oldscope;

        Private Scope _newscope;

        

        Private Boolean canceling;

            Public Scopeeditorcontrol (Scope scope) {_oldscope = scope;

            _newscope = scope;

        InitializeComponent ();

            Public scope Scope {get {return _newscope;

            }} private void Textbox1_validating (object sender, CancelEventArgs e) {try


            {Int32.Parse (TextBox1.Text);

                The catch (formatexception) {e.cancel = true; MessageBox.Show ("Invalid value", "verifyError ", MessageBoxButtons.OK, Messageboxicon.error);

            }} private void Textbox2_validating (object sender, CancelEventArgs e) {try

            {Int32.Parse (TextBox2.Text);

                The catch (formatexception) {e.cancel = true;

            MessageBox.Show ("Invalid value", "Validation error", MessageBoxButtons.OK, Messageboxicon.error); } protected override bool processDialogKey (keys KeyData) {if (KeyData = keys.

                Escape) {_oldscope = _newscope;

            canceling = true; Return to base.

        processDialogKey (KeyData);

            } private void Scopeeditorcontrol_leave (object sender, EventArgs e) {if (!canceling)

                {_newscope.max = Convert.ToInt32 (TextBox1.Text); _newscope.min = Convert.ToInt32 (textboX2.

            Text); }} private void Scopeeditorcontrol_load (object sender, EventArgs e) {Textbox1.tex

            t = _oldscope.max.tostring ();

        TextBox2.Text = _oldscope.min.tostring (); }     } }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.