c# 两个form的嵌套

private void button5_Click(object sender, EventArgs e)
        {
            Form form = new Form();
            Label label = new Label();
            TextBox textBox = new TextBox();
            Label label_content = new Label();
            TextBox textBox_content = new TextBox();
            Button buttonOk = new Button();
            Button buttonCancel = new Button();

            form.Text = "tetle";
            label.Text = "课件标题";
            textBox.Text = "";

            label_content.Text = "课件内容";
            textBox_content.Text = "";

            buttonOk.Text = "确定";
            buttonCancel.Text = "取消";
            buttonOk.DialogResult = DialogResult.OK;
            buttonCancel.DialogResult = DialogResult.Cancel;


            textBox_content.Multiline = true;

            label.SetBounds(9, 20, 372, 13);
            label_content.SetBounds(9,60, 372, 13);
            textBox.SetBounds(12, 36, 250, 20);
            textBox_content.SetBounds(12,78,275,100);
            buttonOk.SetBounds(228, 200, 75, 23);
            buttonCancel.SetBounds(309, 200, 75, 23);

            label.AutoSize = true;
            textBox.Anchor = textBox.Anchor | AnchorStyles.Right;
            buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
            buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;

            form.ClientSize = new Size(396, 300);
            form.Controls.AddRange(new Control[] { label, textBox,label_content,textBox_content, buttonOk, buttonCancel});
            form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height);
            form.FormBorderStyle = FormBorderStyle.FixedDialog;
            form.StartPosition = FormStartPosition.CenterScreen;
            form.MinimizeBox = false;
            form.MaximizeBox = false;
            form.AcceptButton = buttonOk;
            form.CancelButton = buttonCancel;
       //显示新对话框
            DialogResult dialogResult = form.ShowDialog();
       //取值并做相应处理部分 String title
= textBox.Text; String content = textBox_content.Text; String dataPath = System.Windows.Forms.Application.StartupPath+"\\"+title+".txt"; FileStream fs = new FileStream(dataPath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None); fs.SetLength(0); StreamWriter swFromFile = new StreamWriter(fs, System.Text.Encoding.UTF8); Encoding encoder = Encoding.UTF8; swFromFile.Write(content); swFromFile.Close(); }

直接上代码,啥也不说,研究了半天!中间新form控件没显示主要由于红色部分没有添加!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值