【问题标题】:How to make a window floating on desktop?如何让一个窗口悬浮在桌面上?
【发布时间】:2019-09-03 06:21:40
【问题描述】:

我正在尝试使用“topmost”创建一个按钮以使窗口浮动在桌面上,但我无法为该按钮分配布尔值,因为它是 方法组

 public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            if(this.TopMost)
            {
                this.TopMost = true;
                Button1_Click = true;
            }
            else
            {
                this.TopMost = false;
                Button1_Click = false;
            }
        }
    }

【问题讨论】:

  • Button1_Click = true; 你又想用这个做什么?
  • 我正在尝试为按钮设置2个功能,如果单击它,即使我专注于其他窗口,它也会使窗口浮动,如果再次单击它,它会使窗口变得正常

标签: c# winforms button floating method-group


【解决方案1】:

答案其实很简短:

private void Button1_Click(object sender, EventArgs e)
{
 TopMost = !TopMost;
}

您不需要包含 this,因为您已经在表单的范围内,并且您的 if else 逻辑可以缩短为 e = !e

Button1_Click

是一个方法,不能给它赋值。

【讨论】:

  • @TrungVũĐức 如果对您有帮助,您可以接受我的回答,谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-25
相关资源
最近更新 更多