/// <summary> /// Handle Word's AfterAdd event for content controls, to set new controls' placeholder text /// </summary> /// <param name="ccAdded"></param> /// <param name="InUndoRedo"></param> private void doc_ContentControlAfterAdd(Word.ContentControl ccAdded, bool InUndoRedo) { if (!InUndoRedo && m_cmTaskPane.RecentDragDrop) { ccAdded.Application.ScreenUpdating = false; //grab the current text in the node (if any) string currentText = null; if (ccAdded.XMLMapping.IsMapped) { currentText = ccAdded.XMLMapping.CustomXMLNode.Text; } //set the placeholder text (this has the side effect of clearing out the control's contents) ccAdded.SetPlaceholderText(null, null, Utilities.GetPlaceholderText(ccAdded.Type)); //bring back the original text if (currentText != null) { ccAdded.Range.Text = currentText; } ccAdded.Application.ScreenUpdating = true; ccAdded.Application.ScreenRefresh(); } }
/// <summary> /// Bu metot o an aktif olan soru grubu kutusundaki tabloya /// içine bir soru metni yazılacak bir zengin metin kutusu /// ve o sorunun için bir seçim kutusu ekler. /// </summary> public void SoruEkle() { // Her bir form kutusunu tara ve o bir soru grubu mu diye bak. foreach (Word.ContentControl ctrlGroup in this.ContentControls) { HurTestDataSet.QuestionGroupsRow qgroupRow = docDataSet.QuestionGroups.FindByGroupID(ctrlGroup.ID); if (qgroupRow == null) { continue; } // O an seçili konum hangi soru grubu kutusundaysa o kutudaki // tabloya bir soru kutusu ekle. if (Globals.ThisDocument.Application.Selection.Range.InRange(ctrlGroup.Range)) { Word.Table tblGroup = ctrlGroup.Range.Tables[1]; tblGroup.Rows.Add(); Word.ContentControl chkIncludeQuestion = this.ContentControls.Add( Word.WdContentControlType.wdContentControlCheckBox, tblGroup.Rows.Last.Cells[1].Range); chkIncludeQuestion.Checked = true; chkIncludeQuestion.LockContentControl = true; Word.ContentControl ctrlQuestion = this.ContentControls.Add( Word.WdContentControlType.wdContentControlRichText, tblGroup.Rows.Last.Cells[2].Range); docDataSet.Questions.AddQuestionsRow(ctrlQuestion.ID, qgroupRow, chkIncludeQuestion.ID, true, 0); ctrlQuestion.SetPlaceholderText(null, null, "Soru metnini buraya yazın"); ctrlQuestion.LockContentControl = true; } } }
/// <summary> /// Bu metot belgeye içine soru metinler için zengin metin kutucukları konacak /// olan bir tablo içeren bir zengin metin kutusu ekler. /// </summary> public void SoruGrubuEkle() { // Soru grubu kutusu belge sonuna eklenecek object end = this.Content.End - 1; Word.ContentControl ctrlGroup = this.ContentControls.Add( Word.WdContentControlType.wdContentControlRichText, this.Range(ref end, ref end)); HurTestDataSet.QuestionGroupsRow qgroupRow = docDataSet.QuestionGroups.AddQuestionGroupsRow(ctrlGroup.ID, 1, 1); // Sorular için bu kutu içinde bir tablo olacak. Word.Table tblGroup = this.Tables.Add(ctrlGroup.Range, 1, 2); tblGroup.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleSingle; tblGroup.Borders.OutsideLineWidth = Word.WdLineWidth.wdLineWidth225pt; tblGroup.Borders.OutsideColor = Word.WdColor.wdColorBlue; tblGroup.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleSingle; tblGroup.Borders.InsideLineWidth = Word.WdLineWidth.wdLineWidth025pt; tblGroup.Borders.InsideColor = Word.WdColor.wdColorBlue; tblGroup.Columns[1].SetWidth(50, Word.WdRulerStyle.wdAdjustFirstColumn); object groupbegin = ctrlGroup.Range.Start; this.Range(ref groupbegin, ref groupbegin).InsertBefore("Seçilecek Soru Sayısı: "); this.Range(ref groupbegin, ref groupbegin).InsertParagraph(); Word.Range par1range = ctrlGroup.Range.Paragraphs[1].Range; // Soru grubu kutusunda açıklamalar için bir metin kutusu olacak. Word.ContentControl ctrlComment = this.ContentControls.Add( Word.WdContentControlType.wdContentControlRichText, par1range); ctrlComment.SetPlaceholderText(null, null, "Soru grubu açıklamalarını buraya yazın"); ctrlComment.LockContentControl = true; // Soru grubu kutusunda bir de seçilecek soru sayısını belirlemek // için bir açılır liste kutusu olacak. object par2end = ctrlGroup.Range.Paragraphs[2].Range.End - 1; Word.ContentControl cbQuestionCount = this.ContentControls.Add( Word.WdContentControlType.wdContentControlComboBox, this.Range(ref par2end, ref par2end)); cbQuestionCount.DropdownListEntries.Add("1", "1", 0); cbQuestionCount.SetPlaceholderText(null, null, "Sayı seçin"); cbQuestionCount.LockContentControl = true; // Gruba eklenen ilk boş soru için seçim kutusu konacak. Word.ContentControl chkIncludeQuestion = this.ContentControls.Add( Word.WdContentControlType.wdContentControlCheckBox, tblGroup.Cell(1, 1).Range); chkIncludeQuestion.Checked = true; chkIncludeQuestion.LockContentControl = true; // Gruba bir boş soru kutusu konacak. Word.ContentControl ctrlQuestion = this.ContentControls.Add( Word.WdContentControlType.wdContentControlRichText, tblGroup.Cell(1, 2).Range); docDataSet.Questions.AddQuestionsRow(ctrlQuestion.ID, qgroupRow, chkIncludeQuestion.ID, true, 0); ctrlQuestion.SetPlaceholderText(null, null, "Soru metnini buraya yazın"); ctrlQuestion.LockContentControl = true; }
internal static void AddPictureToControl(Word.Document doc, Word.ContentControl contentControl, string fileName, ref int selectionStart) { try { if (contentControl != null) { contentControl.SetPlaceholderText(null, null, String.Empty); //selectionStart = contentControl.Range.End + 1; //int start = contentControl.Range.Start; //int end = contentControl.Range.End; Object oMissed = contentControl.Range; //the position you want to insert Object oLinkToFile = false; //default Object oSaveWithDocument = true; //default //08/05/2017 - Remove all typed text try { contentControl.LockContents = false; contentControl.LockContentControl = false; ((contentControl).Range).Text = ""; } catch (Exception ex) { string A = ex.Message; // } var shape = doc.InlineShapes.AddPicture(fileName, ref oLinkToFile, ref oSaveWithDocument, ref oMissed); //shape.Width = 300; //shape.Height = 25; if (Marshal.IsComObject(oMissed)) { Marshal.ReleaseComObject(oMissed); } } } catch (Exception ex) { logger.LogException(LogLevel.Error, "AddPictureToControl", ex); } }
/// <summary> /// Bu metot o an aktif olan soru kutusunun sonuna içinde bir değişken ///sayısal değer gözükecek olan bir zengin metin kutusu ekler. /// </summary> public void InsertNumericField() { foreach (Word.ContentControl ctrlQuestion in this.ContentControls) { if (docDataSet.Questions.FindByQuestionID(ctrlQuestion.ID) == null) { continue; } Word.Range rngSelected = Globals.ThisDocument.Application.Selection.Range; if (ctrlQuestion.Range.Start <= rngSelected.Start && ctrlQuestion.Range.End >= rngSelected.End) { Word.ContentControl ctrlNumeric = this.ContentControls.Add( Word.WdContentControlType.wdContentControlText, rngSelected); ctrlNumeric.SetPlaceholderText(null, null, "<1|2|3>"); ctrlNumeric.LockContents = true; docDataSet.Numerics.AddNumericsRow(ctrlNumeric.ID, 0, 0, 0); } } }
/// <summary> /// Bu metot o an aktif olan soru kutusunun sonuna içine bir seçenek /// metni yazılacak bir zengin metin kutusu ekler. /// </summary> public void InsertChoiceField() { // Her bir form kutusunu tara ve o bir soru kutusu mu diye bak. foreach (Word.ContentControl ctrlQuestion in this.ContentControls) { HurTestDataSet.QuestionsRow questionRow = docDataSet.Questions.FindByQuestionID(ctrlQuestion.ID); if (questionRow == null) { continue; } Word.Range rngSelected = Globals.ThisDocument.Application.Selection.Range; // O an seçili konum hangi soru kutusundaysa o kutudaki // tabloya bir seçenek kutusu ekle. if (ctrlQuestion.Range.Start <= rngSelected.Start && ctrlQuestion.Range.End >= rngSelected.End) { ctrlQuestion.Range.InsertParagraphAfter(); if (questionRow.ChoiceCount == 0) { ctrlQuestion.Range.InsertParagraphAfter(); } object posChoice = ctrlQuestion.Range.End - 1; Word.Range rngChoice = this.Range(ref posChoice, ref posChoice); Word.ContentControl ctrlChoice = this.ContentControls.Add( Word.WdContentControlType.wdContentControlRichText, rngChoice); ctrlChoice.SetPlaceholderText(null, null, "Seçenek metnini buraya yazın"); questionRow.ChoiceCount = questionRow.ChoiceCount + 1; docDataSet.Choices.AddChoicesRow(ctrlChoice.ID, questionRow, false, false); } } }