控制WinForm界面在屏幕的四个角落显示,具体代码中有说明:

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; namespace Tooltip
{
/// <summary>
/// 弹出自方向 右上、右下、左上、左下
/// </summary>
internal enum PopUp
{
LeftUp, //左上
LeftDown, //左下
RightUp, //右上
RightDown //右下
} /// <summary>
/// 显示窗体
/// </summary>
public class ShowForm
{
#region 字段 属性 private int screenWidth; //除任务栏外的屏幕的宽
private int screenHeight; //除任务栏外的屏幕的高 private Timer timer = new Timer(); //计时器 private Form _form;
/// <summary>
/// 显示的窗体
/// </summary>
public Form TheForm
{
set
{
this._form = value;
SetLocation();
}
get { return this._form; }
} private System.Drawing.Point locationPoint;
/// <summary>
/// 窗体显示位置
/// </summary>
public System.Drawing.Point LocationPoint
{
set
{
this.locationPoint = value;
LimitShowArea();
}
get { return this.locationPoint; }
} private int time;
/// <summary>
/// 设置弹出窗体过程的整个时间
/// </summary>
public int Time
{
set { this.time = value; }
get { return this.time; }
} #endregion #region 构造函数 /// <summary>
/// 构造函数
/// </summary>
public ShowForm()
{
//this._form = form; screenWidth = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width;
screenHeight = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height; this.time = ; //this.timer.Interval = 100;
this.timer.Tick += new EventHandler(timer_Tick);
this.timer.Enabled = false;
} #endregion #region 动态化窗体 开始 结束
#region 窗体动态化参数 private int x_distance; //运动时在X轴上的距离
private int y_distance; //运动时在Y轴上的距离
private int tickCount; //总运动次数
private int x_step; //运动时在Y轴上的步长
private int y_step; //运动时在Y轴上的步长
private int num = ; //运动到第几次
private Point reachPoint = new Point(); //运动到的具体位置 #endregion /// <summary>
/// 设置窗体动态化参数
/// </summary>
private void SetFormDynamicParms()
{
x_distance = this.locationPoint.X - this.screenWidth;
y_distance = this.locationPoint.Y - this.screenHeight; tickCount = this.time * / this.timer.Interval;
PopUp popUpDirection = this.JudgeDirection();
switch (popUpDirection)
{
case PopUp.LeftUp:
x_distance = this.locationPoint.X + this._form.Width; //x_distance = this.locationPoint.X;
y_distance = this.locationPoint.Y + this._form.Height; //y_distance = this.locationPoint.Y
break;
case PopUp.LeftDown:
x_distance = this.locationPoint.X + this._form.Width; //x_distance = this.locationPoint.X;
y_distance = this.locationPoint.Y - this.screenHeight;
break;
case PopUp.RightUp:
x_distance = this.locationPoint.X - this.screenWidth;
y_distance = this.locationPoint.Y + this._form.Height; //y_distance = this.locationPoint.Y;
break;
default:
break;
} x_step = x_distance / tickCount;
y_step = y_distance / tickCount; } /// <summary>
/// 计时器间隔执行函数
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timer_Tick(object sender, EventArgs e)
{
if (this.num == )
{
SetFormDynamicParms();
num++;
}
else
{
this.reachPoint.X = this.locationPoint.X - x_distance + x_step * num;
this.reachPoint.Y = this.locationPoint.Y - y_distance + y_step * num;
if (this.num < this.tickCount)
{
this._form.Location = this.reachPoint;
this._form.Opacity = this.num * / this.tickCount;
this.num++;
}
else
{
this._form.Location = this.locationPoint;
this._form.Opacity = ;
this.num = ;
this.timer.Stop();
}
}
} /// <summary>
/// 开始显示动态窗体
/// </summary>
public void Start()
{
this.timer.Enabled = true;
this.timer.Start();
this._form.Opacity = ;
this._form.Show(); } /// <summary>
/// 关闭显示的窗体
/// </summary>
public void Close()
{
this.timer.Stop();
this.timer.Enabled = false;
this._form.Close();
} #endregion #region 默认显示位置 private void SetLocation()
{
Point lct = new Point();
lct.X = screenWidth - this.TheForm.Width;
lct.Y = screenHeight - this.TheForm.Height;
this.LocationPoint = lct;
} #endregion #region 限制弹框的显示区域 private void LimitShowArea()
{
if (this.locationPoint.X < )
{
this.locationPoint.X = ;
} if (this.locationPoint.Y < )
{
this.locationPoint.Y = ;
} int maxX = this.screenWidth - this._form.Width; //Form 不溢出 X轴最大值
if (this.locationPoint.X > maxX)
{
this.locationPoint.X = maxX;
} int maxY = this.screenHeight - this._form.Height; //Form 不溢出 Y轴最大值
if (this.locationPoint.Y > maxY)
{
this.locationPoint.Y = maxY;
}
} #endregion #region 窗体显示 右上、右下、左上、左下 /// <summary>
/// 窗体中心点
/// </summary>
/// <returns></returns>
private Point FormCentre()
{
Point frmCentre = new Point();
frmCentre.X = this.locationPoint.X + this._form.Width / ;
frmCentre.Y = this.locationPoint.Y + this._form.Height / ;
return frmCentre;
} /// <summary>
/// 屏幕中心点
/// </summary>
/// <returns></returns>
private Point ScreenCentre()
{
Point screenCentre = new Point();
screenCentre.X = this.screenWidth / ;
screenCentre.Y = this.screenHeight / ;
return screenCentre;
} /// <summary>
/// 判断窗体显示自的方向
/// </summary>
/// <returns></returns>
private PopUp JudgeDirection()
{
PopUp popup = PopUp.RightDown; Point frmCentre = FormCentre();
Point screenCentre = ScreenCentre(); if (frmCentre.X < screenCentre.X)
{
if (frmCentre.Y < screenCentre.Y)
{
popup = PopUp.LeftUp;
}
else
{
popup = PopUp.LeftDown;
}
}
else
{
if (frmCentre.Y < screenCentre.Y)
{
popup = PopUp.RightUp;
}
else
{
popup = PopUp.RightDown;
}
} return popup;
} #endregion
}
}

参考:屏幕、任务栏 工作域大小

当前的屏幕除任务栏外的工作域大小
this.Width = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width;
this.Height = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height; 当前的屏幕包括任务栏的工作域大小
this.Width=System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
this.Height=System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height; 任务栏大小
this.Width=System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width-System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width;
this.Height=System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height-System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height; winform实现全屏显示
WinForm:
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.TopMost = true; winform获取屏幕区域
Rectangle ScreenArea = System.Windows.Forms.Screen.GetWorkingArea(this);

C#:控制WinForm界面的显示的更多相关文章

  1. Unity在UI界面上显示3D模型/物体,控制模型旋转

    Unity3D物体在UI界面的显示 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- ...

  2. 循序渐进开发WinForm项目(4)--Winform界面模块的集成使用

    随笔背景:在很多时候,很多入门不久的朋友都会问我:我是从其他语言转到C#开发的,有没有一些基础性的资料给我们学习学习呢,你的框架感觉一下太大了,希望有个循序渐进的教程或者视频来学习就好了. 其实也许我 ...

  3. winform界面特效470多例

    一共470多例winform 界面特效的源码. 实例030 窗口颜色的渐变 实例说明 在程序设计时,可以通过设置窗体的BackColor属性来改变窗口的背景颜色.但是这个属性改变后整个窗体的客户区都会 ...

  4. Web界面和Winform界面生成,代码生成工具

    在上面一篇随笔<代码生成工具之界面快速生成>介绍了代码生成工具Database2Sharp的界面生成操作,其中介绍了Web界面(包括列表界面.内容显示.内容编辑界面的生成,另外还介绍了Wi ...

  5. C#470多例winform 界面特效的源码

    一共470多例winform 界面特效的源码. 窗体与界面设计... 9 实例001  带历史信息的菜单    10 实例002  菜单动态合并    12 实例003  像开始菜单一样漂亮的菜单.. ...

  6. ABP开发框架前后端开发系列---(8)ABP框架之Winform界面的开发过程

    在前面随笔介绍的<ABP开发框架前后端开发系列---(7)系统审计日志和登录日志的管理>里面,介绍了如何改进和完善审计日志和登录日志的应用服务端和Winform客户端,由于篇幅限制,没有进 ...

  7. 总结开发中基于DevExpress的Winform界面效果

    DevExpress是一家全球知名的控件开发公司, DevExpress 也特指此公司出品的控件集合或某系列控件或其中某控件.我们应用最为广泛的是基于Winform的DevExpress控件组,本篇随 ...

  8. NanUI for Winform发布,让Winform界面设计拥有无限可能

    如今,尽管WPF.UWP大行其道,大有把Winform打残干废的趋势.但是还是有那么一波顽固不化的老家伙们固守着Winform,其中就包括我. 好吧,既然都说Winform做得软件不如WPF界面美观效 ...

  9. 在Winform界面中实现对多文档窗体的参数传值

    在Winform界面中窗体我们一般使用多文档进行展示,也就是类似一般的选项卡的方式可以加载多个窗体界面.一般来说,我们如果打开新的窗体,给窗体传递参数是很容易的事情,但是在框架层面,一般的窗体是通过动 ...

随机推荐

  1. bash变量操作

    1.条件变量替换: Bash Shell可以进行变量的条件替换,既只有某种条件发生时才进行替换,替换 条件放在{}中. (1) ${value:-word} 当变量未定义或者值为空时,返回值为word ...

  2. The Struts dispatcher cannot be found. This is usually caused by using Strut

    The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the assoc ...

  3. Android中的Handler机制

    直接在UI线程中开启子线程来更新TextView显示的内容,运行程序我们会发现,如下错 误:android.view.ViewRoot$CalledFromWrongThreadException: ...

  4. SQL Server Index详解

    最近在进行数据库调优,对索引的使用和其内部的运转一知半解.在园子里看到一篇相关文章非常好.留下印记以便日常查找. http://www.cnblogs.com/xwdreamer/archive/20 ...

  5. eclipse启动无响应,停留在Loading workbench状态

    做开发的同学们或多或少的都会遇到eclipse启动到一定程度时,就进入灰色无响应状态再也不动了.启动画面始终停留在Loading workbench状态.反复重启,状态依旧. 多数情况下,应该是非正常 ...

  6. 《数据结构与算法分析:C语言描述_原书第二版》CH2算法分析_课后习题_部分解答

    对于一个初学者来说,作者的Solutions Manual把太多的细节留给了读者,这里尽自己的努力给出部分习题的详解: 不当之处,欢迎指正. 1.  按增长率排列下列函数:N,√2,N1.5,N2,N ...

  7. Summary: Process & Tread

    refer to http://www.programmerinterview.com/index.php/operating-systems/thread-vs-process/ A process ...

  8. 基于Qt实现的截图小程序

    在最近做的行人检测项目中,由于需要训练分类器,而分类器的训练又需要有一个一定长宽的样本.为了方便样本的采集,因此实现了这样的一个截图程序.该程序的主要功能是加载视频到程序中,程序可以对视频进行播放.暂 ...

  9. [转] MongoDB shell 操作 (查询)

    最近有用到mongoDB,每次都去查看官方文档很是费劲,自己准备写点东西.但在博客园上看到另外的一篇博文不错,就转载过来,加上点儿自己的修饰 左边是mongodb查询语句,右边是sql语句.对照着用, ...

  10. Java基础(35):装箱与拆箱---Java 中基本类型和包装类之间的转换(Wrapper类)

    基本类型和包装类之间经常需要互相转换,以 Integer 为例(其他几个包装类的操作雷同哦): 在 JDK1.5 引入自动装箱和拆箱的机制后,包装类和基本类型之间的转换就更加轻松便利了. 那什么是装箱 ...