一个c#的输入框函数

private static string InputBox(string Caption, string Hint, string Default)
        {
            Form InputForm = new Form();
            InputForm.MinimizeBox = false;
            InputForm.MaximizeBox = false;
            InputForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            InputForm.StartPosition = FormStartPosition.CenterScreen;
            InputForm.Width = 220;
            InputForm.Height = 150;

            InputForm.Text = Caption;
            Label lbl = new Label();
            lbl.Text = Hint;
            lbl.Left = 10;
            lbl.Top = 20;
            lbl.Parent = InputForm;
            lbl.AutoSize = true;
            TextBox tb = new TextBox();
            tb.Left = 30;
            tb.Top = 45;
            tb.Width = 160;
            tb.Parent = InputForm;
            tb.Text = Default;
            tb.SelectAll();
            Button btnok = new Button();
            btnok.Left = 30;
            btnok.Top = 80;
            btnok.Parent = InputForm;
            btnok.Text = "确定";
            InputForm.AcceptButton = btnok;//回车响应

            btnok.DialogResult = DialogResult.OK;
            Button btncancal = new Button();
            btncancal.Left = 120;
            btncancal.Top = 80;
            btncancal.Parent = InputForm;
            btncancal.Text = "取消";
            btncancal.DialogResult = DialogResult.Cancel;
            try
            {
                if (InputForm.ShowDialog() == DialogResult.OK)
                {
                    return tb.Text;
                }
                else
                {
                    return null;
                }
            }
            finally
            {
                InputForm.Dispose();
            }
        }
时间: 2024-08-11 01:34:05

一个c#的输入框函数的相关文章

面试题之java 编写一个截取字符串的函数,输入为一个字符串和字节数,输出为按字节截取的字符串。 要求不能出现截半的情况

题目:10. 编写一个截取字符串的函数,输入为一个字符串和字节数,输出为按字节截取的字符串. 但是要保证汉字不被截半个,如“我ABC”4,应该截为“我AB”,输入“我ABC汉DEF”,6,应该输出为“我ABC”而不是“我ABC+汉的半个”. 一.需要分析 1.输入为一个字符串和字节数,输出为按字节截取的字符串-------------->按照字节[byte]截取操作字符串,先将String转换成byte类型 .2.汉字不可以截半----------------------------------

c语言:编写一个输出链表的函数print

编写一个输出链表的函数print. 解:程序: #include<stdio.h> #include<stdlib.h> #define LEN sizeof(struct Student) struct Student { long num; float score; struct Student *next; }; int n; struct Student *creat()//建立链表的函数 { struct Student *head; struct Student *p1

一个奇怪的JS函数

今天在分析一个jQuery插件源码的时候,发现了一个奇怪的函数. // add leading zeros var pad = function(x){return (1e15+""+x).slice(-2)}; 首先1e15是什么意思? 也不是十六进制表示法. 不管三七21,直接F12打开命令窗口,执行下看看,结果是1后面有15个0. 原来1e15是科学计数法,表示1乘以10的15次方. var y=123e5; // 12300000 var z=123e-5; // 0.0012

编写一个程序实现strcpy函数的功能

1 #include <stdio.h> 2 #include <string.h> 3 #define N 5 4 5 6 char *mycpy(char *s1, char *s2) 7 { 8 //数组型 9 /* int i; 10 while(s2[i] != '\0') { 11 s1[i] = s2[i]; 12 i++; 13 } 14 s1[i] = '\0'; 15 return s1; */ 16 //指针型 17 char *p = s1; 18 whil

编写一个程序实现strcmp函数的功能

写自己的strcat函数------→mycmp 1 #include <stdio.h> 2 #include <string.h> 3 #define N 5 4 5 int mycmp(char *s1, char *s2) 6 { 7 //数组型 8 /* int i = 0; 9 while(s1[i] == s2[i] && s1[i] != '\0') { 10 i++; 11 } 12 13 return s1[i] - s2[i]; */ 14 /

一个简化的printf函数

<C和指针>第7章第5道编程题: 实现一个简化的printf函数,它能够处理%d.%f.%s 和 %c 格式码,根据ANSI标准的原则,其他格式码的行为是未定义的.你可以假定已经存在函数 printf_integer 和 printf_float,用于打印这些类型的值.对于另外两个类型的值,使用 putchar 来打印. 答案参考百度知道 1 /* 2 ** 实现一个简易的printf函数 3 ** 它能处理%d, %f, %s,%c格式码 4 */ 5 6 #include <stda

编写一个程序实现strcat函数的功能

写自己的strcat函数------→mycat 1 #include <stdio.h> 2 #include <string.h> 3 #define N 5 4 5 char *mycat(char *s1, char *s2) 6 { 7 //数组型 8 /* int i = 0; 9 while(s1[i] != '\0') { 10 i++; 11 } 12 int j = 0; 13 while(s2[j] != '\0') { 14 s1[i] = s2[j]; 1

【c语言】用可变参数列表实现一个简化的printf函数

//实现一个简化的printf函数. #include <stdarg.h> #include <string.h> void my_printf(const char *str,...) { va_list arg; //准备访问可变参数 va_start(arg,str); while(*str != '\0') { switch(*str) { case 'c': putchar( va_arg( arg,char ) ); break; case 's': puts( va

C语言学习_C如何在一个文件里调用另一个源文件中的函数

问题 C如何在一个文件里调用另一个源文件中的函数,如题. 解决办法 当程序大了代码多了之后,想模块化开发,不同文件中存一点,是很好的解决办法,那我们如何做才能让各个文件中的代码协同工作呢?我们知道,main函数是程序入口,我们希望把不同的功能写在不同的函数中,并把这些函数统一放到另外一个文件里,以便main函数显得太长,main函数可以在用到某方法的时候调用来处理.为了实现这个步骤,我们这样做.首先定义一个c代码的头文件,如function.h,在里面声明将要实现的函数,如int add(int