2012-08-07 121 views
0

如果“TotalFileCount”== 0,此代码将打开一个文件夹。我想要打开该文件夹并使其位于屏幕中心,并且我希望它是一个特定的大小。有没有办法在C#中做到这一点?如何打开在屏幕中间以特定大小打开的文件夹

if (TotalFileCount == 0) 
{ 
    MessageBox.Show("There are no files in this directory. Please add pictures to this folder: " + AppVars.PolicyImagesDirectory + " and try again.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); 
    btnBrowse.Focus(); 

    System.Diagnostics.Process process = new System.Diagnostics.Process(); 
    process.StartInfo.FileName = AppVars.PolicyImagesDirectory; 
    process.Start(); 
} 

当新的Windows资源管理器窗口打开时,我可以将其设置为特定的大小并将其居中在屏幕上吗?

+2

所以你的问题是“当打开新的Windows资源管理器窗口,我可以让它具有一定规模,并把它某个位置?“ – 2012-08-07 17:40:23

+0

是的,例如,当您双击一个文件夹时,它会打开资源管理器。我想调整这个观点。 – Testifier 2012-08-07 17:43:37

+2

真的,我不希望应用程序调整我的其他应用程序的窗口。 – 2012-08-07 17:54:42

回答

0

获得来自过程的句柄然后从Win32 API调用本机SetWindowPos

process.handle //to get the handle of the window. 

[DllImport("user32.dll", SetLastError=true)] 
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int W, int H, uint uFlags); 
+0

'Process.handle'是**进程**句柄,而不是'SetWindowPos'所需的**窗口**句柄。不要降低投票率,因为'SetWindowPos'可能是正确的选择,但是你需要修正是正确的;第一行是完全错误的。 – 2012-08-08 12:34:19