private void ReadSlide(object sender, EventArgs e) { if (NoPowerPoint()) { ofd = new OpenFileDialog { Filter = powerpointformat }; try { if (ofd.ShowDialog() == DialogResult.OK) { file_path = ofd.FileName; } else { return; } } catch (SystemException exc) { MessageBox.Show(open_err_msg + ofd.FileName + ":\n\n" + exc); return; } finally { ofd.Dispose(); } PowerPoint_App = new Ppt.Application(); multi_presentations = PowerPoint_App.Presentations; presentation = multi_presentations.Open(file_path, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoTrue); } TitleBox.Text = string.Empty; BodyTextBox.Text = string.Empty; layout = Active_slide.Layout; if (layout == Ppt.PpSlideLayout.ppLayoutText) { TitleBox.Text = Active_slide.Shapes[1].TextFrame.TextRange.Text; BodyTextBox.Text = Active_slide.Shapes[2].TextFrame.TextRange.Text; } else { foreach (var item in presentation.Slides[1].Shapes) { var shape = (Ppt.Shape)item; if (shape.HasTextFrame != MsoTriState.msoTrue) { continue; } if (shape.Name.Contains("Title")) { TitleBox.Text += shape.TextFrame.TextRange.Text + ' '; box_list.Insert(0, shape.Name); } else if (shape.TextFrame.HasText == MsoTriState.msoTrue) { IDataObject clipped = Clipboard.GetDataObject(); shape.TextFrame.TextRange.Copy(); BodyTextBox.Paste(); Clipboard.SetDataObject(clipped, true); box_list.Add(shape.Name); } } } }
private void ReadSlide(object sender, EventArgs e) { if (NoPowerPoint()) { if (!LoadPresentation()) { return; //If there is no presentation open load one, but return if the user cancels. } } TitleBox.Clear(); BodyTextBox.Clear(); BodyTextBox.ZoomFactor = 1f; //This line is to alleviate a bug in the RichTextBox class that //^prevents display of the proper ZoomFactor after clearing it. foreach (var item in presentation.Slides[1].Shapes) { var shape = (Ppt.Shape)item; if (shape.HasTextFrame != msoTrue) { continue; } if (shape.Name.Contains("Title")) { TitleBox.Text += shape.TextFrame.TextRange.Text + ' '; } else if (shape.TextFrame.HasText == msoTrue) { IDataObject clipped = Clipboard.GetDataObject(); shape.TextFrame.TextRange.Copy(); BodyTextBox.Paste(); //if (BodyTextBox.Font.SizeInPoints > 17f) BodyTextBox.ZoomFactor = 0.5f; if (shape.TextFrame.TextRange.Font.Size > 17f) { BodyTextBox.ZoomFactor = 0.5f; } Clipboard.SetDataObject(clipped, true); } } }