public partial class FrmAnchor : Form, IMessageFilter
{
public FrmAnchor(Control parentControlc, Control keyControl)
{
InitializeComponent();
this.Size = keyControl.Size;
this.HandleCreated += FrmDownBoard_HandleCreated;
this.HandleDestroyed += FrmDownBoard_HandleDestroyed;
this.Controls.Add(keyControl);
keyControl.Dock = DockStyle.Fill;
Point p = parentControlc.Parent.PointToScreen(parentControlc.Location);
int intX = ;
int intY = ;
if (p.Y + parentControlc.Height + keyControl.Height > Screen.PrimaryScreen.Bounds.Height)
{
intY = p.Y - keyControl.Height-;
}
else
{
intY = p.Y + parentControlc.Height+;
} if (p.X + keyControl.Width > Screen.PrimaryScreen.Bounds.Width)
{
intX = Screen.PrimaryScreen.Bounds.Width - keyControl.Width; }
else
{
intX = p.X;
}
this.Location = new Point(intX, intY); } public FrmAnchor(Size size,Point location, Control keyControl)
{
InitializeComponent();
this.Size = keyControl.Size;
this.HandleCreated += FrmDownBoard_HandleCreated;
this.HandleDestroyed += FrmDownBoard_HandleDestroyed;
this.Controls.Add(keyControl);
keyControl.Dock = DockStyle.Fill;
Point p = location;
int intX = ;
int intY = ;
if (p.Y + size.Height + size.Height > Screen.PrimaryScreen.Bounds.Height)
{
intY = p.Y - keyControl.Height - ;
}
else
{
intY = p.Y + size.Height + ;
} if (p.X + keyControl.Width > Screen.PrimaryScreen.Bounds.Width)
{
intX = Screen.PrimaryScreen.Bounds.Width - keyControl.Width; }
else
{
intX = p.X;
}
this.Location = new Point(intX, intY); } private void FrmDownBoard_HandleDestroyed(object sender, EventArgs e)
{
Application.RemoveMessageFilter(this);
} private void FrmDownBoard_HandleCreated(object sender, EventArgs e)
{
Application.AddMessageFilter(this);
} #region 无焦点窗体 [System.Runtime.InteropServices.DllImport("user32.dll")]
private extern static IntPtr SetActiveWindow(IntPtr handle);
private const int WM_ACTIVATE = 0x006;
private const int WM_ACTIVATEAPP = 0x01C;
private const int WM_NCACTIVATE = 0x086;
private const int WA_INACTIVE = ;
private const int WM_MOUSEACTIVATE = 0x21;
private const int MA_NOACTIVATE = ;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_MOUSEACTIVATE)
{
m.Result = new IntPtr(MA_NOACTIVATE);
return;
}
else if (m.Msg == WM_NCACTIVATE)
{
if (((int)m.WParam & 0xFFFF) != WA_INACTIVE)
{
if (m.LParam != IntPtr.Zero)
{
SetActiveWindow(m.LParam);
}
else
{
SetActiveWindow(IntPtr.Zero);
}
}
}
base.WndProc(ref m);
} #endregion public bool PreFilterMessage(ref Message m)
{
if (m.Msg != 0x0201 || this.Visible == false) return false;
var pt = this.PointToClient(MousePosition);
this.Visible = this.ClientRectangle.Contains(pt);
return false;
}
}

效果如下:

c# 停靠窗体的更多相关文章

  1. Pyqt QDockWidget 停靠窗体

    网上的一个关于QDockWidget 停靠窗体的教程 代码: # -*- coding: utf-8 -*- from PyQt4.QtGui import * from PyQt4.QtCore i ...

  2. WeifenLuo组件中如何设置停靠窗体的宽度

    在项目中使用了WeifenLuo.WinFormsUI.Docking组件,窗体停靠效果非常棒. 现在项目出现了这样的需求,希望可以控制停靠窗体的宽度,因为默认的宽度往往会造成停靠窗体的内容显示不完全 ...

  3. (十九)c#Winform自定义控件-停靠窗体

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...

  4. Delphi 停靠技术的应用

    一.基础知识介绍 1.VCL组件的基础知识 在TWinControl类中有一个DockSite属性(boolean),它的作用是是否允许别的控件停靠在它的上面:在TControl类中有一个DragKi ...

  5. Delphi中停靠技术的实现

    随着软件技术的不断进步,软件界面也越来越美观,操作也越来越方便.综观市面上比较专业的各种软件,我们会发现大部分都提供窗体停靠的功能,特别象工具软件,基本上都或多或少有停靠功能.自然,Delphi也支持 ...

  6. 高级停靠(Dock)技术的实现

    高级停靠(Dock)技术的实现 介绍 所谓停靠就是可以用鼠标拖动窗体或者控件,并将其从一个父窗体移出或者移动到另一个父窗体上,可以按水平,垂直方向整齐排列, 并且可以停靠在分页控制组件上.下面的示意图 ...

  7. WeiFenLuo.winFormsUI.Docking.dll的使用(停靠效果)

    1.  重置工具箱: 新建一个WinForm程序,项目名称为TestDockPanelControl.选中Form1窗体后选择工具箱--->>新建个添加选项卡命名为WeiFenLuo--- ...

  8. Qt创建停靠悬浮窗口

    1.Qt实现窗口停靠和悬浮使用类QDockWidget,它有两个重要方法用来设置停靠特性以及停靠区域, dw1->setFeatures(QDockWidget::DockWidgetMovab ...

  9. Qt布局管理: 停靠窗口QDockWidget类(纯代码实现)

    转载:好儿郎~志在四方 详细描述: QDockWidget类提供了一个窗体部件,其可以停靠在QMainWindow,或其本身作为一个在桌面上的顶级窗口(也就是父窗体). QDockWidget类提供了 ...

随机推荐

  1. iOS中,MRC和ARC混编

    假设一个project为MRC,当中要加入ARC的文件: 选择target -> build phases -> compile sources -> 单击ARC的文件将compil ...

  2. 亲测有效,解决Can 't connect to local MySQL server through socket '/tmp/mysql.sock '(2) ";

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/hjf161105/article/details/78850658 最近租了一个阿里云云翼服务器,趁 ...

  3. Apparatus, system, and method for automatically minimizing real-time task latency and maximizing non-real time task throughput

    An apparatus, system, and method are provided for automatically minimizing Real-Time (RT) task laten ...

  4. 关于hexo的SEO的好文章

    1.hexo高阶教程:想让你的博客被更多的人在搜索引擎中搜到吗? 2.Hexo Seo优化让你的博客在google搜索排名第一 3.hexo 博客 seo 优化 4.HEXO SEO 高级优化 5.H ...

  5. 【14.94%】【codeforces 611E】New Year and Three Musketeers

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. spring定时任务.线程池,自定义多线程配置

    定时任务及多线程配置xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=" ...

  7. 利用WPF建立自己的3d gis软件(非axhost方式)(五)在鼠标点击的位置增加UI

    原文:利用WPF建立自己的3d gis软件(非axhost方式)(五)在鼠标点击的位置增加UI 先下载SDK:https://pan.baidu.com/s/1M9kBS6ouUwLfrt0zV0bP ...

  8. 【23.15%】【codeforces 703C】Chris and Road

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  9. layer的使用笔记

    $('#calendar').fullCalendar({ lang:"zh-cn", buttonText:{ today: '今天' }, eventLimit: true, ...

  10. HDU 1010 Tempter of the Bone heuristic 修剪

    的问题是,在测试修剪. 应该说是更先进的应用. 由于使用的heuristic(经验)修剪.总结这方面的经验法则,别easy.我说,这也是由于先进的在线报告中的应用程序没有分析太多太好的解决这个问题,计 ...