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.

  • 相关阅读:
    tomcat war包自动化部署脚本
    nginx只允许域名访问,禁止ip访问
    Nginx Errors: upstream response cache error
    Linux进程的睡眠和唤醒
    传输层:UDP 协议
    IP网际协议
    应用层协议
    [Eclipse插件] Eclipse设置Tab键为空格(ctrl+shirt+f格式化生效)!
    [Android Pro] 使用CursorLoader异步加载数据 from 3.0
    [Android Memory] 内存分析工具 MAT 的使用
  • 原文地址:https://www.cnblogs.com/luqingfei/p/674904.html
Copyright © 2011-2022 走看看