Windows 窗体应用程序中的滑动效果 [英] Sliding Effect in Windows Form Application

查看:21
本文介绍了Windows 窗体应用程序中的滑动效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

how can i get my winforms c# app to be in the left of the screen?

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

I would like a small tab showing so that when i move the mouse cursor to that area of the screen it shows up on screen. But when i minimize it goes back to that position.

推荐答案

所以听起来您想让表单贴在计算机屏幕的一侧,然后当鼠标悬停时,它会展开或执行某些操作.

So it sounds like you want to make your form stick to the side of the computer screen and then when a mouse-over happens, it expands or does something.

这是基于 Microsoft 记录的 Shaped Window 此处.

This is based on the Shaped Window which is documented by Microsoft here.

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

The following uses a rectangle stuck to the side of the screen. For my MouseHover, I just make the form big again. You might show a second form or do some animations.

将这些链接到表单的 Load 和 MouseHover 事件.MouseEnter 可能也会提供服务.

Link these to your form's Load and MouseHover events. MouseEnter would probably serve too.

    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));
    }

这篇关于Windows 窗体应用程序中的滑动效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆