惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Threatpost
V
Vulnerabilities – Threatpost
TaoSecurity Blog
TaoSecurity Blog
C
Cybersecurity and Infrastructure Security Agency CISA
P
Proofpoint News Feed
G
GRAHAM CLULEY
S
Securelist
P
Palo Alto Networks Blog
MongoDB | Blog
MongoDB | Blog
A
Arctic Wolf
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
WordPress大学
WordPress大学
Project Zero
Project Zero
T
Threat Research - Cisco Blogs
L
Lohrmann on Cybersecurity
C
Cyber Attacks, Cyber Crime and Cyber Security
F
Fortinet All Blogs
博客园 - 叶小钗
B
Blog RSS Feed
C
Cisco Blogs
Google DeepMind News
Google DeepMind News
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Apple Machine Learning Research
Apple Machine Learning Research
G
Google Developers Blog
K
Kaspersky official blog
D
Docker
Latest news
Latest news
Cisco Talos Blog
Cisco Talos Blog
T
Tor Project blog
Cyberwarzone
Cyberwarzone
Security Latest
Security Latest
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Spread Privacy
Spread Privacy
Microsoft Azure Blog
Microsoft Azure Blog
C
Check Point Blog
J
Java Code Geeks
Simon Willison's Weblog
Simon Willison's Weblog
T
Tenable Blog
Recent Announcements
Recent Announcements
T
Tailwind CSS Blog
H
Help Net Security
L
LINUX DO - 热门话题
T
The Exploit Database - CXSecurity.com
Jina AI
Jina AI
S
SegmentFault 最新的问题
MyScale Blog
MyScale Blog
NISL@THU
NISL@THU
美团技术团队
腾讯CDC

博客园 - Seraph

共享源码 统计多个word文件中的总字数 聚类算法DBScan共享 惭愧啊,居然两年没有写Blog了。翻看从前的东西恍惚隔世 DNN WebMail Module 开发 —— 第一篇 SharpWebMail 调试篇 开始研究DNN了。发现自己落伍了很多 在 ASP.NET 中执行 URL 重写(zz) XML转义 C#中的多線程 ASP 字符串函数 C# escape sequence - Seraph C#字符串的使用笔记 Request Validation - 防止脚本攻击 关于一个算法,看看大家有没有好办法。 写了一个进制转换的小函数,javascript的 发现好久没有写随笔了。 谁知道怎么对一个asp.net的project加注册 天子呼来不上船,自称臣是酒中仙——我的嗜酒情节 两篇文章都是翻译了一半就翻不下去了,E文水平有待提高啊 Scott Watermasysk承诺的文档到现在还没有Release,sigh
都是一些小东西(1)一个InputBox
Seraph · 2005-04-13 · via 博客园 - Seraph

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace InputBoxSample
{
 /// <summary>
 /// The InputBox class is used to show a prompt in a dialog box using the static method Show().
 /// </summary>
 /// <remarks>
 /// Copyright ?2003 Reflection IT
 ///
 /// This software is provided 'as-is', without any express or implied warranty.
 /// In no event will the authors be held liable for any damages arising from the
 /// use of this software.
 ///
 /// Permission is granted to anyone to use this software for any purpose,
 /// including commercial applications, subject to the following restrictions:
 ///
 /// 1. The origin of this software must not be misrepresented; you must not claim
 /// that you wrote the original software.
 ///
 /// 2. No substantial portion of the source code of this library may be redistributed
 /// without the express written permission of the copyright holders, where
 /// "substantial" is defined as enough code to be recognizably from this library.
 ///
 /// </remarks>
 public class InputBox : System.Windows.Forms.Form
 {
  protected System.Windows.Forms.Button buttonOK;
  protected System.Windows.Forms.Button buttonCancel;
  protected System.Windows.Forms.Label labelPrompt;
  protected System.Windows.Forms.TextBox textBoxText;
  protected System.Windows.Forms.ErrorProvider errorProviderText;

  /// <summary>
  /// Required designer variable.
  /// </summary>
  private System.ComponentModel.Container components = null;

  /// <summary>
  /// Delegate used to validate the object
  /// </summary>
  private InputBoxValidatingHandler _validator;

  private InputBox()
  {
   //
   // Required for Windows Form Designer support
   //
   InitializeComponent();

   //
   // TODO: Add any constructor code after InitializeComponent call
   //
  }

  /// <summary>
  /// Clean up any resources being used.
  /// </summary>
  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }

  #region Windows Form Designer generated code
  /// <summary>
  /// Required method for Designer support - do not modify
  /// the contents of this method with the code editor.
  /// </summary>
  private void InitializeComponent()
  {
   this.buttonOK = new System.Windows.Forms.Button();
   this.buttonCancel = new System.Windows.Forms.Button();
   this.textBoxText = new System.Windows.Forms.TextBox();
   this.labelPrompt = new System.Windows.Forms.Label();
   this.errorProviderText = new System.Windows.Forms.ErrorProvider();
   this.SuspendLayout();
   //
   // buttonOK
   //
   this.buttonOK.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
   this.buttonOK.DialogResult = System.Windows.Forms.DialogResult.OK;
   this.buttonOK.Location = new System.Drawing.Point(288, 72);
   this.buttonOK.Name = "buttonOK";
   this.buttonOK.TabIndex = 2;
   this.buttonOK.Text = "OK";
   this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click);
   //
   // buttonCancel
   //
   this.buttonCancel.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
   this.buttonCancel.CausesValidation = false;
   this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
   this.buttonCancel.Location = new System.Drawing.Point(376, 72);
   this.buttonCancel.Name = "buttonCancel";
   this.buttonCancel.TabIndex = 3;
   this.buttonCancel.Text = "Cancel";
   this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
   //
   // textBoxText
   //
   this.textBoxText.Location = new System.Drawing.Point(16, 32);
   this.textBoxText.Name = "textBoxText";
   this.textBoxText.Size = new System.Drawing.Size(416, 20);
   this.textBoxText.TabIndex = 1;
   this.textBoxText.Text = "";
   this.textBoxText.Validating += new System.ComponentModel.CancelEventHandler(this.textBoxText_Validating);
   this.textBoxText.TextChanged += new System.EventHandler(this.textBoxText_TextChanged);
   //
   // labelPrompt
   //
   this.labelPrompt.AutoSize = true;
   this.labelPrompt.Location = new System.Drawing.Point(15, 15);
   this.labelPrompt.Name = "labelPrompt";
   this.labelPrompt.Size = new System.Drawing.Size(39, 13);
   this.labelPrompt.TabIndex = 0;
   this.labelPrompt.Text = "prompt";
   //
   // errorProviderText
   //
   this.errorProviderText.DataMember = null;
   //
   // InputBox
   //
   this.AcceptButton = this.buttonOK;
   this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
   this.CancelButton = this.buttonCancel;
   this.ClientSize = new System.Drawing.Size(464, 104);
   this.Controls.AddRange(new System.Windows.Forms.Control[] {
                    this.labelPrompt,
                    this.textBoxText,
                    this.buttonCancel,
                    this.buttonOK});
   this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
   this.MaximizeBox = false;
   this.MinimizeBox = false;
   this.Name = "InputBox";
   this.Text = "Title";
   this.ResumeLayout(false);

  }
  #endregion

  private void buttonCancel_Click(object sender, System.EventArgs e) {
   this.Validator = null;
   this.Close();
  }

  private void buttonOK_Click(object sender, System.EventArgs e) {
   this.Close();
  }

  /// <summary>
  /// Displays a prompt in a dialog box, waits for the user to input text or click a button.
  /// </summary>
  /// <param name="prompt">String expression displayed as the message in the dialog box</param>
  /// <param name="title">String expression displayed in the title bar of the dialog box</param>
  /// <param name="defaultResponse">String expression displayed in the text box as the default response</param>
  /// <param name="validator">Delegate used to validate the text</param>
  /// <param name="xpos">Numeric expression that specifies the distance of the left edge of the dialog box from the left edge of the screen.</param>
  /// <param name="ypos">Numeric expression that specifies the distance of the upper edge of the dialog box from the top of the screen</param>
  /// <returns>An InputBoxResult object with the Text and the OK property set to true when OK was clicked.</returns>
  public static InputBoxResult Show(string prompt, string title, string defaultResponse, InputBoxValidatingHandler validator, int xpos, int ypos) {
   using (InputBox form = new InputBox()) {
    form.labelPrompt.Text = prompt;
    form.Text = title;
    form.textBoxText.Text = defaultResponse;
    if (xpos >= 0 && ypos >= 0) {
     form.StartPosition = FormStartPosition.Manual;
     form.Left = xpos;
     form.Top = ypos;
    }
    form.Validator = validator;

    DialogResult result = form.ShowDialog();

    InputBoxResult retval = new InputBoxResult();
    if (result == DialogResult.OK) {
     retval.Text = form.textBoxText.Text;
     retval.OK = true;
    }
    return retval;
   }
  }

  /// <summary>
  /// Displays a prompt in a dialog box, waits for the user to input text or click a button.
  /// </summary>
  /// <param name="prompt">String expression displayed as the message in the dialog box</param>
  /// <param name="title">String expression displayed in the title bar of the dialog box</param>
  /// <param name="defaultResponse">String expression displayed in the text box as the default response</param>
  /// <param name="validator">Delegate used to validate the text</param>
  /// <returns>An InputBoxResult object with the Text and the OK property set to true when OK was clicked.</returns>
  public static InputBoxResult Show(string prompt, string title, string defaultText, InputBoxValidatingHandler validator) {
   return Show(prompt, title, defaultText, validator, -1, -1);
  }


  /// <summary>
  /// Reset the ErrorProvider
  /// </summary>
  /// <param name="sender"></param>
  /// <param name="e"></param>
  private void textBoxText_TextChanged(object sender, System.EventArgs e) {
   errorProviderText.SetError(textBoxText, "");
  }

  /// <summary>
  /// Validate the Text using the Validator
  /// </summary>
  /// <param name="sender"></param>
  /// <param name="e"></param>
  private void textBoxText_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
   if (Validator != null) {
    InputBoxValidatingArgs args = new InputBoxValidatingArgs();
    args.Text = textBoxText.Text;
    Validator(this, args);
    if (args.Cancel) {
     e.Cancel = true;
     errorProviderText.SetError(textBoxText, args.Message);
    }
            }
  }

  protected InputBoxValidatingHandler Validator {
   get {
    return (this._validator);
   }
   set {
    this._validator = value;
   }
  }
 }

 /// <summary>
 /// Class used to store the result of an InputBox.Show message.
 /// </summary>
 public class InputBoxResult {
  public bool OK;
  public string Text;
 }

 /// <summary>
 /// EventArgs used to Validate an InputBox
 /// </summary>
 public class InputBoxValidatingArgs : EventArgs {
  public string Text;
  public string Message;
  public bool Cancel;
 }

 /// <summary>
 /// Delegate used to Validate an InputBox
 /// </summary>
 public delegate void InputBoxValidatingHandler(object sender, InputBoxValidatingArgs e);

}