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控件没显示主要由于红色部分没有添加!