質問者
powerpointのスライド上でのドラッグドロップ検出について

質問
すべての返信
-
こんな?
using System; using System.Windows.Forms; using Microsoft.Office.Interop.PowerPoint; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { var ppa = new Microsoft.Office.Interop.PowerPoint.Application(); ppa.Visible = Microsoft.Office.Core.MsoTriState.msoCTrue; ppa.WindowSelectionChange += ppa_WindowSelectionChange; ppa.PresentationBeforeClose += ppa_PresentationBeforeClose; ppa.CommandBars.OnUpdate += CommandBars_OnUpdate; Presentation ppp = ppa.Presentations.Add(); CustomLayout customLayout = ppp.SlideMaster.CustomLayouts[PpSlideLayout.ppLayoutTitle]; var sl = ppp.Slides.AddSlide(1, customLayout); var shp1 = sl.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle, 0, 0, 100, 100); shp1.TextFrame.TextRange.Text = "1"; var shp2 = sl.Shapes.AddShape(Microsoft.Office.Core.MsoAutoShapeType.msoShapeRectangle, 200, 0, 100, 100); shp2.TextFrame.TextRange.Text = "2"; } private ShapeRange lastShape; private ShapeRange previewShape; void ppa_WindowSelectionChange(Selection Sel) { var shp = Sel.ShapeRange; previewShape = shp == null ? null : lastShape; lastShape = shp; } void CommandBars_OnUpdate() { if (lastShape != null && previewShape != null) { try { previewShape.Left = lastShape.Left + 100; previewShape.Top = lastShape.Top + 100; } catch (Exception ex) { MessageBox.Show(ex.Message); previewShape = null; lastShape = null; } } } void ppa_PresentationBeforeClose(Presentation Pres, ref bool Cancel) { lastShape = null; previewShape = null; } } }
アドインじゃなくFormですが方法は同じでいけるはず
#適当に書いたのでテキスト枠触ると暴走しますw
個別に明示されていない限りgekkaがフォーラムに投稿したコードにはフォーラム使用条件に基づき「MICROSOFT LIMITED PUBLIC LICENSE」が適用されます。(かなり自由に使ってOK!)