• wpf 只让窗口保留一个,并在最前显示


    就是遍历所有的,有的话就不生成了,没有的话就生成一个,还有最前是一个参数,最后就是窗口事件了。

    ChangeDistingWordOfSelected mw = null;
                foreach (Window win in App.Current.Windows)
                {
                    if (win is ChangeDistingWordOfSelected)
                    {
                        mw = win as ChangeDistingWordOfSelected;
                    }
                }
                if (mw == null)
                {
                    mw = new ChangeDistingWordOfSelected();
                    mw.WindowStartupLocation = WindowStartupLocation.Manual;
                   // mw.Left = 1025;//窗口生成的位置
                    mw.Left = Mouse.GetPosition(GlobalHelper._mainWindow).X;
                    mw.Top = Mouse.GetPosition(this).Y ;
                    mw.Show();
                }
                else
                {
                    mw.Visibility = System.Windows.Visibility.Visible;
                    mw.Topmost = true;
                }

                mw.btn_ok.Click += delegate//确定替换字
                {
                    ListResult[CurrentLineIndex].LineTxtInfo[CurrentTxtIndex].TxtResult = mw.ChangedWord.Text;//更换选中的字;

                    ObservableCollection<string> strNewLineTxt = new ObservableCollection<string>();
                    strNewLineTxt.Clear();
                    for (int l = 0; l < ListResult[CurrentLineIndex].LineTxtInfo.Count; l++)
                    {
                        strNewLineTxt.Add(ListResult[CurrentLineIndex].LineTxtInfo[l].TxtResult);
                    }
                    this.ListListBox[CurrentLineIndex].ItemsSource = strNewLineTxt;
                    mw.Close();
                };

    2,也可以新那家一个全局的窗口对象,每次检查当前对象是否为空

    if (drawingsoftware_wnd == null)
                {
                    double height = this.Height;
                    double width = this.Width;
                    drawingsoftware_wnd = new DrawingSoftware_Popup(this, height, width);
                    drawingsoftware_wnd.Owner = this;
                }

                if (!drawingsoftware_wnd.IsVisible)
                {
                    drawingsoftware_wnd.Show();
                    this.Hide();
                }
                else
                {
                    drawingsoftware_wnd.Hide();
                }

  • 相关阅读:
    一、CentOS 7安装部署GitLab服务器

    四、指定Nginx启动用户
    三、Nginx支持php
    二、Nginx多站点配置(参考宝塔的)分析
    一、Nginx多站点配置
    一、PHP和Apache实现多用户自助建站
    Flask+uwsgi+Nginx+Ubuntu部署
    flask 上传头像
    flask 分页
  • 原文地址:https://www.cnblogs.com/LILING3/p/7610682.html
Copyright © 2020-2023  润新知