对,自己一个windows窗体的名字

解决方案 »

  1.   

    Title TipText 使什么??没有show 是无法直接修改对话框的控件的
      

  2.   

    你按钮提交后,实例化InputBox对象后,并不知道f.ShowDialog()对象的值啊,因为这里你还没点OK按钮呢,所以得先执行一次
      

  3.   

    我想问的是为什么我把f.showdialog();这行代码去掉之后就会出现错误呢? 
    -------------------------
    出什么錯?貼出來.
    正常情況f.ShowDialog()不可能需要用兩次
      

  4.   

    把错误代码贴出来看看,窗体在构造函数里,会执行InitializeComponent函数初始化控件,之后就可以修改对话框控件了。然后ShowDialog会调用Form_Load事件和Form_Active事件。根据经验猜测以下,看你的描述,应该是f.Title或者f.TipText的一些执行代码,需要在运行过Form_Load或者Form_Active中的代码才能正常工作。你可以检查一下,把这些代码移到构造函数中执行,应该就可以了
      

  5.   

    我先说明下我的程序
    我时用了两个windows窗体,一个时form1,另一个是inputbox
    这个时form1的代码:using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace 非模态对话框
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void button1_Click(object sender, EventArgs e)
            {
                InputBox f = new InputBox();//调用inputbox
                f.ShowDialog();//问题在这里,为什么去掉这个就会错呢?后面if语句中不是有吗?
                f.Title = "输入对话框";
                f.TipText = "请输入年龄";
                if (f.ShowDialog() == DialogResult.OK)
                {
                    this.label1.Text = f.Message;
                }
            }
        }
    }
    这个是inputbox的代码:using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace 非模态对话框
    {
        public partial class InputBox : Form
        {
            public InputBox()
            {
                InitializeComponent();
            }
            public string Title
            {
                set { this.Text = value; }
            }
            public string Message
            {
                get {return this.Input.Text;}
            }
            public string TipText
            {
                set { this.Tip.Text = value; }
            }        private void InputBox_Load(object sender, EventArgs e)
            {
                this.AcceptButton = this.btnOK;
                this.CancelButton = this.btnCancel;
                this.btnOK.DialogResult = DialogResult.OK;
                this.btnCancel.DialogResult = DialogResult.Cancel;
                this.MaximizeBox = false;
                this.MinimizeBox = false;
                this.ShowInTaskbar = false;
            }
        }
    }
    如果去掉我说的那段代码的话,就会出现这样的问题:当点form1上的按钮想启动inputbox时,inputbox只是在屏幕上闪一下就又关闭了!
      

  6.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace 非模态对话框
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        private void button1_Click(object sender, EventArgs e)
            {
                InputBox f = new InputBox();
                //f.ShowDialog();
                f.Title = "输入对话框";
                f.TipText = "请输入年龄";
                if (f.ShowDialog() == DialogResult.OK)
                {
                    this.label1.Text = f.Message;
                }
            }
        }
    }using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace 非模态对话框
    {
        public partial class InputBox : Form
        {
            public InputBox()
            {
                InitializeComponent();
            }
            public string Title
            {
                set { this.Text = value; }
            }
            public string Message
            {
                get {return this.Input.Text;}
            }
            public string TipText
            {
                set { this.Tip.Text = value; }
            }        private void InputBox_Load(object sender, EventArgs e)
            {
                this.AcceptButton = this.btnOK;
                this.CancelButton = this.btnCancel;
                this.btnOK.DialogResult = DialogResult.OK;
                this.btnCancel.DialogResult = DialogResult.Cancel;
                this.MaximizeBox = false;
                this.MinimizeBox = false;
                this.ShowInTaskbar = false;
            }
        }
    }出现的问题是如果我把f.showdialog()这个语句去掉的话就会出现:当点击from1中的按钮启动inputbox时,inputbox只是闪了一下就又关闭了
      

  7.   

    把InputBox_Load里的代码放到InputBox的构造函数中去,或作为属性在InputBox的属性窗口里来设置!
      

  8.   

    其实主要的原因在于你在Load事件里使用this.ShowInTaskbar = false;像这样的对窗体的属性的设置一般都在构造函数或InitializeComponent里设置。