Beispiel #1
0
 public static void ToNormal(Microsoft.Office.Tools.Word.RichTextContentControl ctrl)
 {
     ctrl.LockContents          = false;
     ctrl.Text                  = ctrl.Text.Replace("*", "");
     ctrl.Range.Font.ColorIndex = WdColorIndex.wdBlack;
     ctrl.LockContents          = true;
 }
Beispiel #2
0
 public static void Highlight(Microsoft.Office.Tools.Word.RichTextContentControl ctrl)
 {
     ctrl.LockContents          = false;
     ctrl.Text                  = ctrl.Text + "*";
     ctrl.Range.Font.ColorIndex = WdColorIndex.wdRed;
     ctrl.LockContents          = true;
 }
Beispiel #3
0
        #pragma warning restore 0467
        private void RichText_Exiting(object sender, ContentControlExitingEventArgs e)
        {
            Microsoft.Office.Tools.Word.RichTextContentControl ctrl = (Microsoft.Office.Tools.Word.RichTextContentControl)sender;

            string messaggio     = "";
            bool   overDimension = false;
            int    length        = 0;

            if (ctrl.Equals(txtOggetto) && ctrl.Text.Length > OGGETTO_MAX_LEN)
            {
                messaggio     = "La lunghezza dell'oggetto supera i caratteri consentiti. Se si procede così il testo salvato risulterà parziale.";
                overDimension = true;
                length        = OGGETTO_MAX_LEN;
            }
            else if (ctrl.Equals(txtDescrizione) && ctrl.Text.Length > DESCRIZIONE_MAX_LEN)
            {
                messaggio     = "La lunghezza della descrizione supera i caratteri consentiti. Se si procede così il testo salvato risulterà parziale.";
                overDimension = true;
                length        = DESCRIZIONE_MAX_LEN;
            }
            else if (ctrl.Equals(txtNote) && ctrl.Text.Length > NOTE_MAX_LEN)
            {
                messaggio     = "La lunghezza delle note supera i caratteri consentiti. Se si procede così il testo salvato risulterà parziale.";
                overDimension = true;
                length        = NOTE_MAX_LEN;
            }

            FormatTextOverDimension(ctrl, length, overDimension);
            if (overDimension)
            {
                System.Windows.Forms.MessageBox.Show(messaggio, "Attenzione", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
        private void AddRichTextControlAtRange()
        {
            this.Paragraphs[1].Range.InsertParagraphBefore();

            richTextControl2 = this.Controls.AddRichTextContentControl(this.Paragraphs[1].Range,
                                                                       "richTextControl2");
            richTextControl2.PlaceholderText = "Enter your first name";
        }
        private void AddRichTextControlAtSelection()
        {
            this.Paragraphs[1].Range.InsertParagraphBefore();
            this.Paragraphs[1].Range.Select();

            richTextControl1 = this.Controls.AddRichTextContentControl("richTextControl1");
            richTextControl1.PlaceholderText = "Enter your first name";
        }
        private void AddRichTextControlAtRange()
        {
            Word.Document currentDocument = this.Application.ActiveDocument;
            currentDocument.Paragraphs[1].Range.InsertParagraphBefore();

            Document extendedDocument = Globals.Factory.GetVstoObject(currentDocument);

            richTextControl2 = extendedDocument.Controls.AddRichTextContentControl(
                currentDocument.Paragraphs[1].Range, "richTextControl2");
            richTextControl2.PlaceholderText = "Enter your first name";
        }
Beispiel #7
0
        //<Snippet4>
        private void AddRichTextControlAtRange()
        {
            Word.Document currentDocument = this.Application.ActiveDocument;
            currentDocument.Paragraphs[1].Range.InsertParagraphBefore();

            Document extendedDocument = Globals.Factory.GetVstoObject(currentDocument);

            richTextContentControl = extendedDocument.Controls.AddRichTextContentControl(
                currentDocument.Paragraphs[1].Range, "richTextContentControl");
            richTextContentControl.PlaceholderText =
                "Click here to download MSDN Library information about content controls.";
        }
Beispiel #8
0
        // </Snippet1>


        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            // <Snippet2>
            this.adventureWorksDataSet = new AdventureWorksLTDataSet();
            this.customerTableAdapter  = new AdventureWorksLTDataSetTableAdapters.CustomerTableAdapter();
            this.customerTableAdapter.Fill(this.adventureWorksDataSet.Customer);
            this.customerBindingSource = new System.Windows.Forms.BindingSource();
            // </Snippet2>

            // <Snippet3>
            Word.Document currentDocument = this.Application.ActiveDocument;

            Document extendedDocument = Globals.Factory.GetVstoObject(currentDocument);

            // </Snippet3>

            // <Snippet4>
            extendedDocument.Paragraphs[1].Range.InsertParagraphBefore();
            extendedDocument.Paragraphs[1].Range.InsertParagraphBefore();
            extendedDocument.Paragraphs[1].Range.Text =
                "The companies listed in the AdventureWorksLT database:   \n";
            extendedDocument.Paragraphs[2].Range.Text = "  ";

            Word.Range range1 = extendedDocument.Paragraphs[2].Range.Characters.First;
            Word.Range range2 = extendedDocument.Paragraphs[2].Range.Characters.Last;
            Word.Range range3 = extendedDocument.Paragraphs[1].Range.Characters.Last;
            // </Snippet4>

            // <Snippet5>
            this.button1      = extendedDocument.Controls.AddButton(range1, 60, 15, "1");
            this.button1.Text = "Previous";
            this.button2      = extendedDocument.Controls.AddButton(range2, 60, 15, "2");
            this.button2.Text = "Next";

            this.customerContentControl = extendedDocument.Controls.AddRichTextContentControl(
                range3, "richTextContentControl1");
            // </Snippet5>

            // <Snippet6>
            this.customerBindingSource.DataSource = this.adventureWorksDataSet.Customer;
            this.customerContentControl.DataBindings.Add("Text", this.customerBindingSource,
                                                         "CompanyName", true, this.customerContentControl.DataBindings.DefaultDataSourceUpdateMode);

            this.button1.Click += new EventHandler(button1_Click);
            this.button2.Click += new EventHandler(button2_Click);
            // </Snippet6>
        }
        private void AddProtectedContentControls()
        {
            this.Paragraphs[1].Range.InsertParagraphBefore();
            Word.Range range1 = this.Paragraphs[1].Range;

            deletableControl = this.Controls.AddRichTextContentControl(range1,
                                                                       "deletableControl");
            deletableControl.PlaceholderText = "You can delete this control, " +
                                               "but you cannot edit it";
            deletableControl.LockContents = true;

            range1.InsertParagraphAfter();
            Word.Range range2 = this.Paragraphs[2].Range;

            editableControl = this.Controls.AddRichTextContentControl(range2,
                                                                      "editableControl");
            editableControl.PlaceholderText = "You can edit this control, " +
                                              "but you cannot delete it";
            editableControl.LockContentControl = true;
        }
Beispiel #10
0
 public void FormatTextOverDimension(Microsoft.Office.Tools.Word.RichTextContentControl ctrl, int length, bool overDimension)
 {
     if (overDimension)
     {
         string     text = ctrl.Text;
         Word.Range rng  = ctrl.Range;
         rng.Text            = text.Substring(0, length);
         rng.Font.ColorIndex = WdColorIndex.wdBlack;
         rng.Collapse(WdCollapseDirection.wdCollapseEnd);
         rng.Text            = text.Substring(length, text.Length - length);
         rng.Font.ColorIndex = WdColorIndex.wdRed;
     }
     else
     {
         if (!ctrl.ShowingPlaceholderText)
         {
             ctrl.Range.Font.ColorIndex = WdColorIndex.wdAuto;
         }
     }
 }
        private void CreateRichTextControlsFromNativeControls()
        {
            if (this.ContentControls.Count <= 0)
            {
                return;
            }

            richTextControls = new System.Collections.Generic.List
                               <Microsoft.Office.Tools.Word.RichTextContentControl>();
            int count = 0;

            foreach (Word.ContentControl nativeControl in this.ContentControls)
            {
                if (nativeControl.Type ==
                    Microsoft.Office.Interop.Word.WdContentControlType.wdContentControlRichText)
                {
                    count++;
                    Microsoft.Office.Tools.Word.RichTextContentControl tempControl =
                        this.Controls.AddRichTextContentControl(nativeControl,
                                                                "VSTORichTextControl" + count.ToString());
                    richTextControls.Add(tempControl);
                }
            }
        }
        private void Application_DocumentOpen(Microsoft.Office.Interop.Word.Document Doc)
        {
            if (Doc.ContentControls.Count > 0)
            {
                Document extendedDocument = Globals.Factory.GetVstoObject(Doc);

                richTextControls = new System.Collections.Generic.List
                                   <Microsoft.Office.Tools.Word.RichTextContentControl>();
                int count = 0;

                foreach (Word.ContentControl nativeControl in Doc.ContentControls)
                {
                    if (nativeControl.Type ==
                        Microsoft.Office.Interop.Word.WdContentControlType.wdContentControlRichText)
                    {
                        count++;
                        Microsoft.Office.Tools.Word.RichTextContentControl tempControl =
                            extendedDocument.Controls.AddRichTextContentControl(nativeControl,
                                                                                "VSTORichTextControl" + count.ToString());
                        richTextControls.Add(tempControl);
                    }
                }
            }
        }
        private void AddProtectedContentControls()
        {
            Microsoft.Office.Tools.Word.Document vstoDocument =
                Globals.Factory.GetVstoObject(this.Application.ActiveDocument);


            vstoDocument.Paragraphs[1].Range.InsertParagraphBefore();
            Word.Range range1 = vstoDocument.Paragraphs[1].Range;

            deletableControl = vstoDocument.Controls.AddRichTextContentControl(range1,
                                                                               "deletableControl");
            deletableControl.PlaceholderText = "You can delete this control, " +
                                               "but you cannot edit it";
            deletableControl.LockContents = true;

            range1.InsertParagraphAfter();
            Word.Range range2 = vstoDocument.Paragraphs[2].Range;

            editableControl = vstoDocument.Controls.AddRichTextContentControl(range2,
                                                                              "editableControl");
            editableControl.PlaceholderText = "You can edit this control, " +
                                              "but you cannot delete it.";
            editableControl.LockContentControl = true;
        }