ZengCode.Com (The Thai Php Framework)  


Home   Download   Manual   About us    

Facebook   


MAIN MENU
เขียนโปรแกรมบน iPhone ด้วย MonoTouch
News
Php Tips
Ubuntu
Spring+Strut+Hibernate
Android Programming
Design Pattern By PHP
C# Design Pattern
Linux Quick Tips
C# Tips & Technique
C# using Linq น่าใช้จริงๆ
Java & JavaScript Tips
MAVEN
Database & SQL
ZengCode Framework Guide
Mac OSx
Zeng Code Code
Programming
IPhone (Tips and Trick)

Download เอกสารที่น่าสนใจ

     Create InputBox for C#  (2009-08-19)

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

namespace FujitsuTaskManger
{
    ///
    /// The InputBox class is used to show a prompt in a dialog box using the static method Show().
    ///
    ///
    /// 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.
    ///
    ///
    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;
        private IContainer components;

        ///
        /// Delegate used to validate the object
        ///
        private InputBoxValidatingHandler _validator;

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

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

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

        #region Windows Form Designer generated code
        ///
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        ///
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            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.components);
            ((System.ComponentModel.ISupportInitialize)(this.errorProviderText)).BeginInit();
            this.SuspendLayout();
            //
            // buttonOK
            //
            this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((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.Size = new System.Drawing.Size(75, 23);
            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)((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.Size = new System.Drawing.Size(75, 23);
            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.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.ContainerControl = this;
            this.errorProviderText.DataMember = "";
            //
            // 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.Add(this.labelPrompt);
            this.Controls.Add(this.textBoxText);
            this.Controls.Add(this.buttonCancel);
            this.Controls.Add(this.buttonOK);
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "InputBox";
            this.Text = "Title";
            //this.Load += new System.EventHandler(this.InputBox_Load);
            ((System.ComponentModel.ISupportInitialize)(this.errorProviderText)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }
        #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();
        }

        ///
        /// Displays a prompt in a dialog box, waits for the user to input text or click a button.
        ///
        /// String expression displayed as the message in the dialog box
        /// String expression displayed in the title bar of the dialog box
        /// String expression displayed in the text box as the default response
        /// Delegate used to validate the text
        /// Numeric expression that specifies the distance of the left edge of the dialog box from the left edge of the screen.
        /// Numeric expression that specifies the distance of the upper edge of the dialog box from the top of the screen
        /// An InputBoxResult object with the Text and the OK property set to true when OK was clicked.
        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;
            }
        }

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


        ///
        /// Reset the ErrorProvider
        ///
        ///
        ///
        private void textBoxText_TextChanged(object sender, System.EventArgs e)
        {
            errorProviderText.SetError(textBoxText, "");
        }

        ///
        /// Validate the Text using the Validator
        ///
        ///
        ///
        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;
            }
        }

    }

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

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

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

}

 

เวลาเรียกใช้ก็
using InputBoxSample;

แล้วก็
private void buttonTest_Click(object sender, System.EventArgs e) {
InputBoxResult result = InputBox.Show("Test input Box:", "AIam", "Default text", new InputBoxValidatingHandler(inputBox_Validating));
if (result.OK) {
textBox1.Text = result.Text;
}
}

private void inputBox_Validating(object sender, InputBoxValidatingArgs e) {
if (e.Text.Trim().Length == 0) {
e.Cancel = true;
e.Message = "Required";
}
}

 

ที่มา : http://www.bloggang.com/viewdiary.php?id=iaiam&month=08-2008&date=23&group=3&gblog=7

โค้ดผิดนิดหน่อยผมแก้ไขแล้ว object textBox และ Button เวลาจะ set drawing position ต้องระบุ property Location ให้มันด้วยครับ


Comment

Stinnaenlap  (06 มกราคม 2553)   
IP : 78.26.187.219
Cymbalta no prescription drugCymbalta no rx codcod delivery CymbaltaCymbalta no prescription codCymbalta with doctor consultcheap Cymbalta by money orderCymbalta next dayCymbalta overnight without prescriptionCymbalta no doctorCymbalta fed ex cheap Cymbalta next dayorder Cymbaltabuy Cymbalta and pay by codorder Cymbalta without rxCymbalta no script fedexCymbalta with no presciptionCymbalta overnight fed exbuy Cymbalta without perscriptionno script CymbaltaCymbalta without doctor rx


tetaflurl  (30 ธันวาคม 2552)   
IP : 78.26.187.219
Cephalexin antibiotics beers. Cephalexin suspension. Cephalexin xr buy online cheap Taking cephalexin for fish. Can i give my cat cephalexin. Can cephalexin 500mg interfere with the effectiveness of depo. Cephalexin 500. Cephalexin free saturday delivery Order Cephalexin no prescription Can human take fish cefalexin.


Sawngrorgog  (27 ธันวาคม 2552)   
IP : 78.26.187.219
buy cymbalta and itchingbuy cymbalta and jaw clenchingbuy cymbalta and joint painbuy cymbalta and libidobuy cymbalta and linezolidbuy cymbalta and lipase bloodbuy cymbalta and liverbuy cymbalta and liver damagebuy cymbalta and liver diseasewhere can i get buy Cymbalta (Duloxetine) online buy discount Cymbalta (Duloxetine)cheap buy Cymbalta (Duloxetine) onlineCymbalta (Duloxetine) usawhere can i buy Cymbalta (Duloxetine)Cymbalta (Duloxetine) dosagebuy cheap Cymbalta (Duloxetine) no prescriptionmedikament Cymbalta (Duloxetine)buy Cymbalta (Duloxetine) in Hawaiibuy Cymbalta (Duloxetine) in IllinoisBuy no Prescription Cymbalta (Duloxetine) Online


awerhdia  (14 พฤศจิกายน 2552)   
IP : 94.41.13.34
Thank you very well. buy nolvadex drug http://www.reddit.com/r/reddit.com/comments/a4ao6/buy_nolvadex_online_in_professional_drugstore/ buy nolvadex Happy birthday to you! Good morning! buy nolvadex in the usa buy clomid and nolvadex online buy clomid and nolvadex online Thank you.


absemdia  (13 พฤศจิกายน 2552)   
IP : 94.41.13.34
Could you spare me a moment? buy cymbalta and stomach problems http://www.stumbleupon.com/stumbler/Buy-Cymbalta buy cymbalta and weight changes A merry Christmas! How's your family? buy cymbalta contraindication buy cymbalta antihistamines additive buy cymbalta and tinnitus Thank you very much.


andyddia  (05 พฤศจิกายน 2552)   
IP : 94.41.97.156
Thanks for adding the links. buy clomid without prescription http://connections.blackboard.com/people/080d04131d buy clomid online without a prescription Thanks for sharing! Why not just ask them? buy clomid online no prescription buy generic clomid clomid serophene buy Please let us know.


ammyia  (02 พฤศจิกายน 2552)   
IP : 94.41.98.198
Very nice site! buy buy wellbutrin sr presecriptions http://boxesandarrows.com/person/86435-smarter buy wellbutrin buy wellbutrin sr I'll be back! Why not just ask them? buy wellbutrin sr and weight loss therapy buy wellbutrin 100sr buy wellbutrin sr bupropion maine You had me to the very end... good job!


celexaz  (30 ตุลาคม 2552)   
IP : 77.79.181.184
Amazing work! keyword celexa side effects shop baikalguide http://www.wikipatterns.com/display/wikipatterns/Buy+celexa+online celexa without prescription overnight Done. Why not just ask them? south beach diet and celexa celexa risks celexa hbr Please let us know.


lipitorc  (27 ตุลาคม 2552)   
IP : 81.30.187.197
Very nice site! adverse reactions to lipitor http://blogcastrepository.com/members/buy-lipitor-online-now.aspx doctor grapefruit lipitor I'll be back! Thanks for adding the links. lipitor versus generic lipitor bursitis lipitor 100 mg dosage Thanks for sharing!


annygirl  (23 ตุลาคม 2552)   
IP : 81.30.219.119
http://sharepointmx.mvps.org/members/casodex-50.aspx casodex canada internet pharmacy casodex bicalutamide connecticut casodex bicalutamide nevada casodex drug casodex alcohol http://microsoftontheissues.com/cs/members/medlife.aspx discount drugs casodex casodex united states casodex bicalutamide new hampshire apteki szwajcarskie casodex casodex and liver problems http://hubpages.com/profile/buy+casodex casodex bicalutamide florida casodex bicalutamide scarborough maine casodex black box warning casodex bicalutamide kansas casodex bicalutamide california http://brainjar.com/community/members/buy-casodex.aspx purchase casodex casodex 50mg casodex maximum dose patient teachings for casodex casodex 50mg tablets


AbbyCharles  (22 ตุลาคม 2552)   
IP : 81.30.219.119
http://wetpixel.com/forums/index.php?showuser=29145 buy claritin do brasil nasonex buy claritin abuse drug buy claritin buy claritin d allegra buy claritin vs buy claritin pg 4 overthecounter buy claritin http://identi.ca/prilosec12 synthroid with buy prilosec otc buy prilosec pregnancy prevacid pregnancy journal articles on buy prilosec dreampharmaceuticals online buy prilosec pregnant and taking buy prilosec


Ambroziy  (19 ตุลาคม 2552)   
IP : 81.30.219.119
What type of drunk are you? Are you an angry drunk? Are you a person that talks a lot when they get drunk? Are you a person that does stupid things when they get drunk. ECT. What type of drunk are you? For example http://portishead.forums.umusic.co.uk/members/casodex.aspx Buy Casodex


Aabba  (15 ตุลาคม 2552)   
IP : 94.41.26.39
buy levitra day trippers buy levitra scientists voice tsunami concern buy levitra no prescription buy levitra viagra buy levitra line buy levitra online from dreampharmaceuticals buy levitra uk buy levitra day trippers buy levitra online buy levitra international pharmacy buy levitra online from dreampharmaceuticals buy levitra on-line buy levitra online buy levitra online from dreampharmaceuticals buy levitra online from canada buy levitra online gameday de http://forums.buddytv.com/members/0abby.html buy levitra san jose buy levitra online gameday de buy levitra on-line http://blogcastrepository.com/members/buy-Levitra.aspx buy levitra on line buy levitra vardenafil buy levitra on the internet

Name
Comment
Security CodeCAPTCHA Image

web hit counter

This page took 0.095345 seconds to load.