zoukankan      html  css  js  c++  java
  • 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();
                }

  • 相关阅读:
    POJ1064 Cable master(二分 浮点误差)
    Codeforces1113F. Sasha and Interesting Fact from Graph Theory(组合数学 计数 广义Cayley定理)
    Codeforces1100F. Ivan and Burgers(离线+线性基)
    Codeforces1097D. Makoto and a Blackboard(数论+dp+概率期望)
    Codeforces1099F. Cookies(线段树+dp+贪心+博弈)
    python-zx笔记4-文件操作
    python-zx笔记3-函数
    python-zx笔记2-help
    fiddler使用笔记1
    理解OAuth 2.0
  • 原文地址:https://www.cnblogs.com/LILING3/p/7610682.html
Copyright © 2011-2022 走看看