2012-08-07 55 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

相關問題