zoukankan      html  css  js  c++  java
  • Winform 的小技巧

    1.窗体居中显示。Form的Propertity,StartPosition ----CenterScreen 

    2.窗体的位置  This.Left, This.Top

    3.显示在其他窗口前 TopMost=true

    4.窗体的位置由上次关闭时决定。

      其实也很简单,在From 的Closed 事件中,记录下当前窗体的Left值和Top值。然后在窗体加载时(Load事件)中,获取记录的值,再改变Left和Top属性,就实现了该功能。

    这里以记录到注册表为例:

    复制代码
            private void Form1_Load(object sender, EventArgs e)
    {
    RegistryKey reg = Registry.CurrentUser.CreateSubKey("SoftWare\MySoft");
    int x = Convert.ToInt32(reg.GetValue("1"));
    int y = Convert.ToInt32(reg.GetValue("2"));
    this.Location = new Point(x, y);//可以转换成 Left 、Top 见 2.
    }

    private void Form1_FormClosed(object sender, FormClosedEventArgs e)
    {
    RegistryKey reg1 = Registry.CurrentUser;
    RegistryKey reg2 = reg1.CreateSubKey("SoftWare\MySoft");
    reg2.SetValue("1", this.Location.X);
    reg2.SetValue("2", this.Location.Y);
    }
    复制代码

     参数传递

       1.构造函数传参。即重载第二个窗体的构造函数,把需要传的参数写入第二个窗体的构造函数。

       2. 全局变量传参数。即 第二个窗体通过获取第一个窗体的全局变量的值。来达到传参的目的。代码如下:

       3.还可以通过事件来传参数。 这种方式的好处是可以使解耦两个form之间的关联。

    1.先定义一个中间模块(Observer类库),用来处理两个FORM中关系。

    View Code

    2.Form1代码

    View Code

    3. Form2代码

    View Code

    参考:http://topic.csdn.net/u/20100112/12/34f6d852-fd02-474f-bfc4-621c6baa35a8.html

    1.获取和设置当前目录的完全限定路径。

    string str = System.Environment.CurrentDirectory;

    Result: C:xxxxxx

    2.获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称。

    string str = System.Windows.Forms.Application.StartupPath;

    Result: C:xxxxxx

    3.获取新的 Process 组件并将其与当前活动的进程关联的主模块的完整路径,包含文件名。

    string str = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;

    Result: C:xxxxxxxxx.exe

    4.获取当前 Thread 的当前应用程序域的基目录,它由程序集冲突解决程序用来探测程序集。

    string str = System.AppDomain.CurrentDomain.BaseDirectory;

    Result: C:xxxxxx

    5.获取应用程序的当前工作目录。

    string str = System.IO.Directory.GetCurrentDirectory();

    Result: C:xxxxxx

    6.获取和设置包含该应用程序的目录的名称。

    string str = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;

    Result: C:xxxxxx

    7.获取当前进程的完整路径,包含文件名。

    string str = this.GetType().Assembly.Location;

    Result: C:xxxxxxxxx.exe

    8.获取启动了应用程序的可执行文件的路径,包括可执行文件的名称。

    string str = System.Windows.Forms.Application.ExecutablePath;

    Result: C:xxxxxxxxx.exe

     

  • 相关阅读:
    图像的仿射变换
    计算机视觉五大技术介绍
    图像处理与Python实现(岳亚伟)笔记五——图像特征提取
    图像处理与Python实现(岳亚伟)笔记四——频域滤波
    图像处理与Python实现(岳亚伟)笔记三——空间滤波
    python 求矩阵的特征值和特征向量
    python + numpy + np.polyfit()(最小二乘多项式拟合曲线)
    Python求定积分+处理can‘t convert expression to float错误
    python reduce() 函数
    python中的sum求和函数
  • 原文地址:https://www.cnblogs.com/huangll/p/3909962.html
Copyright © 2011-2022 走看看