【问题标题】:Sliding Effect in Windows Form ApplicationWindows 窗体应用程序中的滑动效果
【发布时间】:2015-02-20 19:27:52
【问题描述】:

如何让我的 winforms c# 应用程序位于屏幕左侧?

我想显示一个小标签,以便当我将鼠标光标移动到屏幕的该区域时,它会显示在屏幕上。但是当我最小化它会回到那个位置。

【问题讨论】:

  • 这个选项卡是您表单的一部分吗?不清楚你在说什么标签。
  • 我不认为标签在winforms中以这种方式存在?但是是的,我也需要那个......
  • @Seb YESSSS 但在监视器屏幕区域内...所以选项卡需要位于右侧屏幕的一半。

标签: c# .net winforms user-interface


【解决方案1】:

所以听起来你想让你的表单贴在电脑屏幕的一侧,然后当鼠标悬停时,它会展开或做一些事情。

这是基于 Microsoft here 记录的异形窗口。

下面使用了一个贴在屏幕侧面的矩形。对于我的 MouseHover,我只是让表单再次变大。您可能会显示第二种形式或做一些动画。

将这些链接到表单的 Load 和 MouseHover 事件。 MouseEnter 可能也可以。

    private void Form1_Load(object sender, EventArgs e)
    {
        System.Drawing.Drawing2D.GraphicsPath shape = new System.Drawing.Drawing2D.GraphicsPath();
        shape.AddRectangle(new Rectangle(8, 40, 200, 200));
        // I just picked a shape.  The user will see whatever exists in these pixels of the form.
        // After you get it going, make sure that things not on the visible area are disabled.  
        // A user can't click on them but they could tab to them and hit ENTER.
        // Give the user a way to close it other than Alt-F4, stuff like that.
        this.Region = new System.Drawing.Region(shape);
        this.Top = (Screen.PrimaryScreen.WorkingArea.Height - 160) / 2;
        this.Left = Screen.PrimaryScreen.WorkingArea.Left;
    }

    private void Form1_MouseHover(object sender, EventArgs e)
    {
        this.Region = new Region(new Rectangle(0, 0, this.Width, this.Height));
    }

【讨论】:

    【解决方案2】:

    或者,如果您不想受到形状的限制,您可以使用位图来创建非标准的窗口形状。但是使用这种技术,您的窗口仍然是方形的,这意味着如果人们点击不可见的部分,它不会掉到下面的窗口。要解决这个问题,您必须制作自定义形状....borrow this guy's code.

    • 您必须将主窗体的背景图像设置为图片。
    • 确保底角(右下角?)是您的“隐形颜色”
    • 将表单的 BorderStyle 属性设置为 None。

    我在这项技术上的成功在于一个看起来像咖啡杯的程序。您甚至可以通过把手上的孔点击来找到它下面的东西。

        private void Form1_Load(object sender, EventArgs e)
        {
            this.TransparencyKey = new Bitmap(this.BackgroundImage).GetPixel(1, 1);
            this.Width = this.BackgroundImage.Width;
            this.Height = this.BackgroundImage.Height;
            this.Region = GetRegion(new Bitmap(this.BackgroundImage), this.TransparencyKey);
            // GetRegion fetched from referenced blog post
        }
    

    【讨论】:

      猜你喜欢
      • 2021-09-24
      • 1970-01-01
      • 1970-01-01
      • 2011-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多