Jump to content

Help with Visual C#

fredsmith
Go to solution Solved by mlecruz,

Please read again. I said oPara1.Range.Text = textbox1.Text.

Hi guys,

 

I am sort of a new programmer and kind of stuck with the below box.  Basically, I am writing a word document generator using Microsoft.Office.Interop.Word and want to have whatever the user types in the text box textbox1.TextChanged to get printed out in the word document.  Please see below.

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using Microsoft.Office.Interop.Word;using System.Reflection;namespace WindowsFormsApplication4{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)        {        }        private void textBox1_TextChanged(object sender, EventArgs e)  <======================================= THIS        {                    }        private void label1_Click(object sender, EventArgs e)        {        }        private void textBox7_TextChanged(object sender, EventArgs e)        {        }        private void textBox6_TextChanged(object sender, EventArgs e)        {        }        private void textBox5_TextChanged(object sender, EventArgs e)        {        }        private void textBox11_TextChanged(object sender, EventArgs e)        {        }        private void textBox9_TextChanged(object sender, EventArgs e)        {        }        private void textBox2_TextChanged(object sender, EventArgs e)        {        }        private void label12_Click(object sender, EventArgs e)        {        }        private void textBox9_TextChanged_1(object sender, EventArgs e)        {        }        private void Form1_Load(object sender, EventArgs e)        {        }        private void textBox18_TextChanged(object sender, EventArgs e)        {        }        private void button1_Click(object sender, EventArgs e)        {            object oMissing = System.Reflection.Missing.Value;            object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */            //Start Word and create a new document.            Word._Application oWord;            Word._Document oDoc;            oWord = new Word.Application();            oWord.Visible = true;            oDoc = oWord.Documents.Add(ref oMissing, ref oMissing,                ref oMissing, ref oMissing);            //Insert a paragraph at the beginning of the document.            Word.Paragraph oPara1;            oPara1 = oDoc.Content.Paragraphs.Add(ref oMissing);            oPara1.Range.Text = "SOMETHING";  <========================================================= THIS            oPara1.Range.Font.Bold = 1;            oPara1.Format.SpaceAfter = 24;    //24 pt spacing after paragraph.            oPara1.Range.InsertParagraphAfter();                               }        private void button2_Click(object sender, EventArgs e)        {        }    }}

Right now it genrates the string "Something".  How do i make it so that it generates the input of whatever the user types in textbox1.TextChanged ?

 

I would greatly appreciate your help.

 

Thank you!

Link to comment
Share on other sites

Link to post
Share on other sites

Do you really need it the in text_change event?

 

With what you're doing right now you could just set oPara1.Range.Text = textBox1.Text in the button_click event.

CPU: Intel Core i5-4670K @ 4.4GHz CPU Cooler: Noctua NH-D14 GPU: Sapphire R9 290 Tri-X OC Motherboard: Asus Z87-Plus RAM: Corsair Vengeance 8GB DDR3-1600 SSD: Samsung EVO 840 120GB HDD: Western Digital 1TB Blue PSU: Corsair RM1000 Case: NZXT Phantom 630

Link to comment
Share on other sites

Link to post
Share on other sites

Do you really need it the in text_change event?

 

With what you're doing right now you could just set oPara1.Range.Text = textBox1.Text in the button_click event.

 

I don't think that works.

I generated the code again without all those extra lines. 

 

When i set oPara1.Range.Text = textBox1_TextChanged; , it gives me an error. "Error 1 Cannot convert method group 'textBox1_TextChanged' to non-delegate type 'string'. Did you intend to invoke the method?"

 
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using Word = Microsoft.Office.Interop.Word;using System.Reflection;namespace WindowsFormsApplication7{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private void button1_Click(object sender, EventArgs e)        {            object oMissing = System.Reflection.Missing.Value;            object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */            //Start Word and create a new document.            Word._Application oWord;            Word._Document oDoc;            oWord = new Word.Application();            oWord.Visible = true;            oDoc = oWord.Documents.Add(ref oMissing, ref oMissing,                ref oMissing, ref oMissing);            //Insert a paragraph at the beginning of the document.            Word.Paragraph oPara1;            oPara1 = oDoc.Content.Paragraphs.Add(ref oMissing);            oPara1.Range.Text = textBox1_TextChanged;            oPara1.Range.Font.Bold = 1;            oPara1.Format.SpaceAfter = 24;    //24 pt spacing after paragraph.            oPara1.Range.InsertParagraphAfter();        }        private void textBox1_TextChanged(object sender, EventArgs e)        {                   }    }}
Link to comment
Share on other sites

Link to post
Share on other sites

Please read again. I said oPara1.Range.Text = textbox1.Text.

CPU: Intel Core i5-4670K @ 4.4GHz CPU Cooler: Noctua NH-D14 GPU: Sapphire R9 290 Tri-X OC Motherboard: Asus Z87-Plus RAM: Corsair Vengeance 8GB DDR3-1600 SSD: Samsung EVO 840 120GB HDD: Western Digital 1TB Blue PSU: Corsair RM1000 Case: NZXT Phantom 630

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×