下面的程序片段是将一个图片插入到打开的Word文档中,并让其浮于文字的上面。
代码
1
Word.Document doc
=
this
.msWord1.CurrentDocument;
2 object missing = System.Reflection.Missing.Value;
3 object start = 10 ;
4 object end = 20 ;
5 Word.Range rg = doc.Range( ref start, ref end);
6 object org = ( object )rg;
7 Word.InlineShape pic = doc.InlineShapes.AddPicture( @" d:\1.gif " , ref missing, ref missing, ref org);
8 Word.Shape sp = pic.ConvertToShape();
9 sp.ZOrder(Microsoft.Office.Core.MsoZOrderCmd.msoBringToFront);
2 object missing = System.Reflection.Missing.Value;
3 object start = 10 ;
4 object end = 20 ;
5 Word.Range rg = doc.Range( ref start, ref end);
6 object org = ( object )rg;
7 Word.InlineShape pic = doc.InlineShapes.AddPicture( @" d:\1.gif " , ref missing, ref missing, ref org);
8 Word.Shape sp = pic.ConvertToShape();
9 sp.ZOrder(Microsoft.Office.Core.MsoZOrderCmd.msoBringToFront);
这里面重要的是Shape对象的ZOrder方法,这个方法的参数是MsoZOrderCmd枚举变量,主要是通过其来控制图片的效果。