2015-02-12 87 views
0

我想每次启动我的窗口形式,他设在屏幕的底部(任务栏上面)定位窗口形式

public void goBottomWindow(Form targetForm) 
    { 

       targetForm.WindowState = FormWindowState.Maximized; 
       targetForm.FormBorderStyle = FormBorderStyle.None; 
       targetForm.TopMost = true; 
       WinApi.SetWinFullScreen(targetForm.Handle); 

    } 
    public class WinApi 
    { 
     [DllImport("user32.dll", EntryPoint = "GetSystemMetrics")] 
     public static extern int GetSystemMetrics(int which); 

     [DllImport("user32.dll")] 
     public static extern void 
      SetWindowPos(IntPtr hwnd, IntPtr hwndInsertAfter, 
         int X, int Y, int width, int height, uint flags); 

     private const int SM_CXSCREEN = 0; 
     private const int SM_CYSCREEN = 1; 
     private static IntPtr HWND_TOP = IntPtr.Zero; 
     private const int SWP_SHOWWINDOW = 64; // 0x0040 

     public static int ScreenX 
     { 
      get { return GetSystemMetrics(SM_CXSCREEN); } 
     } 

     public static int ScreenY 
     { 
      get {return 60;} 
     } 

     public static void SetWinFullScreen(IntPtr hwnd) 
     { 
      SetWindowPos(hwnd, HWND_TOP, 0, 0, ScreenX, ScreenY, SWP_SHOWWINDOW); 
     } 
    } 

使用此代码,它离开我的窗口形式在屏幕上方....但我需要的是位于下方的窗体窗口。 有可能做到这一点?

对不起,我的英语很不好:(

+0

你尝试过'StartPostion'吗? – chouaib 2015-02-12 01:13:02

+0

是的,不起作用,为什么它也放置在下面的窗口窗体需要她占据屏幕100%的宽度(它已经在运行)。 – JoaoFelipe 2015-02-12 01:14:39

回答

1

为什么targetForm.WindowState = FormWindowState.Maximized;? 不FormWindowState.Normal更适合您?

就去拿你的桌面的尺寸/屏幕

var rect = Screen.PrimaryScreen.WorkingArea; 
targetForm.Witdh = rect.Width; 
targetForm.Top = rect.Height - targetForm.Height; 
0

我在你的第一行看到它说targetForm.TopMost = true; 这意味着你的表格将是TOPMOST,如果你想你的表格t o BottomMost,你应该改变为false;

希望这会有所帮助! - 建设银行

+0

不,完全没有。 TopMost与屏幕上的Y位置无关,*与Z-order一致* – BradleyDotNET 2015-02-26 23:06:39