首页 新闻 赞助 找找看

怎么把功能封装出来

0
[待解决问题]
复制代码
    private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            WinPosition();
        }

        /// <summary>
        /// 设置窗体在屏幕的位置
        /// </summary>
        public void WinPosition()
        {
            double ScreenWidth = System.Windows.SystemParameters.PrimaryScreenWidth;//WPF
            this.Top = this.ActualWidth / 5;
            this.Left = ScreenWidth - this.ActualWidth *1.3;
        }
复制代码

我设置窗体初始位置在屏幕右上角,怎么把WinPosition进一步封装到类

Gino森的主页 Gino森 | 菜鸟二级 | 园豆:204
提问于:2016-11-25 16:40
< >
分享
所有回答(2)
0

定义一个类,将WinPosition定义为静态方法喽

 

~扎克伯格 | 园豆:1923 (小虾三级) | 2016-11-25 16:42

这两条代码怎么调用所在窗体

this.Top = this.ActualWidth / 5;
this.Left = ScreenWidth - this.ActualWidth *1.3;

 

支持(0) 反对(0) Gino森 | 园豆:204 (菜鸟二级) | 2016-11-25 16:45
1

static AdjustPosition(Window win)

{

 double ScreenWidth = System.Windows.SystemParameters.PrimaryScreenWidth;//WPF

win.Top = win.ActualWidth / 5;

win.Left = ScreenWidth - win.ActualWidth *1.3;

}

 

public class BaseWindow:Window

{

 void Window_Loaded(object sender, RoutedEventArgs e) { AdjustPosition(this); }

}

 

class YourWindow:BaseWindow

{}

 

Daniel Cai | 园豆:10424 (专家六级) | 2016-11-25 16:52
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册