zoukankan      html  css  js  c++  java
  • Dot Net WinForm 控件开发 (六) 为属性提供弹出式编辑对话框

    1、先画出弹出对话框的windows窗体


    代码如下:

     1using System;
     2using System.Collections.Generic;
     3using System.ComponentModel;
     4using System.Data;
     5using System.Drawing;
     6using System.Text;
     7using System.Windows.Forms;
     8
     9namespace CustomControlSample
    10{
    11    public partial class FrmSimpleCustomTypeDialogEditor : Form
    12    {
    13        private SimpleCustomType _simpleCustomType;
    14
    15        public SimpleCustomType SimpleCustomTypeProperty
    16        {
    17            get return _simpleCustomType; }
    18            set { _simpleCustomType = value; }
    19        }

    20
    21
    22        public FrmSimpleCustomTypeDialogEditor(SimpleCustomType sct)
    23        {
    24            InitializeComponent();
    25            this._simpleCustomType = sct;
    26            this.textBox1.Text = sct.Min.ToString();
    27            this.textBox2.Text = sct.Max.ToString();
    28        }

    29
    30        private void button1_Click(object sender, EventArgs e)
    31        {
    32            this.DialogResult = DialogResult.OK;
    33            this._simpleCustomType.Min = int.Parse(this.textBox1.Text);
    34            this._simpleCustomType.Max = int.Parse(this.textBox2.Text);
    35            this.Close(); // 这句随便写不写?!!
    36        }

    37
    38        private void button2_Click(object sender, EventArgs e)
    39        {
    40            this.Close();
    41        }

    42
    43        private void textBox1_Validating(object sender, CancelEventArgs e)
    44        {
    45            try
    46            {
    47                int.Parse(textBox1.Text);
    48            }

    49            catch (FormatException)
    50            {
    51                e.Cancel = true;
    52                MessageBox.Show("无效的值。""验证错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
    53            }

    54        }

    55
    56        private void textBox2_Validating(object sender, CancelEventArgs e)
    57        {
    58            try
    59            {
    60                int.Parse(textBox2.Text);
    61            }

    62            catch (FormatException)
    63            {
    64                e.Cancel = true;
    65                MessageBox.Show("无效的值。""验证错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
    66            }

    67        }

    68
    69    }

    70}


    2、再编写属性值编辑器类

     1SimpleCustomTypeDialogEdit

    3、再添加一个属性,并用EditorAttribute 指定相应的编辑器类

     1弹出属性值编辑对话框的属性

    The end.

  • 相关阅读:
    sql注入-原理&防御
    vulnhub靶场之AI-WEB1.0渗透记录
    python -m http.server 搭建一个简易web下载服务器
    渗透测试工具-sqlmap
    OSI七层模型
    LAXCUS大数据操作系统3.03版本发布,欢迎使用试用
    松耦合和紧耦合的架构设计、性能对比
    Laxcus大数据操作系统2.0(5)- 第二章 数据组织
    从AlphaGo谈通用型人工智能设计
    基于深度推理、自编程、大数据的通用人工智能
  • 原文地址:https://www.cnblogs.com/luqingfei/p/674904.html
Copyright © 2011-2022 走看看