C#打开word文档,如何将word窗口放在屏幕最前。

qwe6890087 2014-03-28 11:50:19
LinkButton lbtn = (LinkButton)sender;

object missing = System.Reflection.Missing.Value;
object fileName = lbtn.ToolTip;//这里要求文件放在bin的debug中,文件夹名为document(举例)
Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document doc = null;

doc = app.Documents.Open(ref fileName,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing);

app.Visible = true;


目前已经可以打开word文档,但是只在任务栏显示,无法再屏幕最前显示,不知道如何获取焦点,求高人指示!!!!
...全文
667 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jonesmiller 2014-11-12
  • 打赏
  • 举报
回复 1
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long Private Declare Function FindWindow% Lib "user32" Alias "FindWindowA" (ByVal lpclassname As Any, ByVal lpCaption As Any) Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long Private Declare Function IsIconic Lib "user32" (ByVal hwnd As Long) As Long Const HWND_TOPMOST = -1 Const SWP_NOSIZE = &H1 Const SWP_NOMOVE = &H2 Private Const SW_RESTORE = 9 Private Sub Command1_Click() b = FindWindow("opusApp", vbNullString) If b = 0 Then x = Shell("C:\Program Files\Microsoft Office\Office\WINWORD.EXE", 1) b = FindWindow("opusApp", vbNullString) Else If IsIconic(b) <> 0 Then ShowWindow b, SW_RESTORE End If End If SetWindowPos b, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE End Sub free c#.net qr creator
qwe6890087 2014-04-20
  • 打赏
  • 举报
回复

110,502

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧