热门标签 | HotTags
当前位置:  开发笔记 > 小程序 > 正文

C#Winform多屏幕多显示器编程技巧实例

这篇文章主要介绍了C#Winform多屏幕多显示器编程技巧实例,本文直接给出代码实例,需要的朋友可以参考下

在窗口的中间有一个System.Windows.Forms.PictureBox控件(该控件区域的面积为所在窗口的1/4),当该控件的大部分区域落在其中一台显示器时,在另一台显示器将不显示该控件,(该PictureBox控件将移动到主显示器所在的窗口区域)。 

实现方法:

using System; 
using System.Drawing; 
using System.Collections; 
using System.ComponentModel; 
using System.Windows.Forms; 
using System.Data; 
namespace WindowsApplication12 
{ 
///  
/// Summary description for Form1. 
///  
public class Form1 : System.Windows.Forms.Form 
{ 
private int tmpx = 0; 
private int tmpy = 0; 
private System.Windows.Forms.PictureBox pictureBox1; 
///  
/// Required designer variable. 
///  
private System.ComponentModel.Container compOnents= null; 
System.Drawing.Rectangle[] ScreensRect; 
public Form1() 
{ 
// 
// Required for Windows Form Designer support 
// 
InitializeComponent(); 
// 
// TODO: Add any constructor code after InitializeComponent call 
// 
} 
///  
/// Clean up any resources being used. 
///  
protected override void Dispose( bool disposing ) 
{ 
if( disposing ) 
{ 
if (components != null) 
{ 
components.Dispose(); 
} 
} 
base.Dispose( disposing ); 
} 
#region Windows Form Designer generated code 
///  
/// Required method for Designer support - do not modify 
/// the contents of this method with the code editor. 
///  
private void InitializeComponent() 
{ 
this.pictureBox1 = new System.Windows.Forms.PictureBox(); 
this.SuspendLayout(); 
// 
// pictureBox1 
// 
this.pictureBox1.BackColor = System.Drawing.SystemColors.HotTrack; 
this.pictureBox1.Location = new System.Drawing.Point(120, 88); 
this.pictureBox1.Name = "pictureBox1"; 
this.pictureBox1.Size = new System.Drawing.Size(248, 176); 
this.pictureBox1.TabIndex = 0; 
this.pictureBox1.TabStop = false; 
// 
// Form1 
// 
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); 
this.ClientSize = new System.Drawing.Size(504, 357); 
this.Controls.Add(this.pictureBox1); 
this.Name = "Form1"; 
this.Text = "Form1"; 
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseDown); 
this.Load += new System.EventHandler(this.Form1_Load); 
this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseUp); 
this.ResumeLayout(false); 
} 
#endregion 
///  
/// The main entry point for the application. 
///  
[STAThread] 
static void Main() 
{ 
Application.Run(new Form1()); 
} 
private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) 
{ 
this.tmpx = e.X; 
this.tmpy = e.Y; 
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.form1_MouseMove); 
} 
private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) 
{ 
this.MouseMove -= new System.Windows.Forms.MouseEventHandler(this.form1_MouseMove); 
System.Drawing.Rectangle pictureBox1Rect=Screen.GetWorkingArea(pictureBox1); 
for(int i=0;i


推荐阅读
  • html显示屏幕中心1,HTML中常见的长度单位
    8种机械键盘轴体对比本人程序员,要买一个写代码的键盘,请问红轴和茶轴怎么选?THML中常见的8种长度1、常见的单位px:像素 ... [详细]
  • 本文主要介绍关于人工智能,shell的知识点,对【winyyy.sys,hcpidesk.sys,mtlrd.sys,uldfhjfh.sys,servets.exe等1】和【】有兴趣的朋友可以看下由 ... [详细]
  • 概念:组合模式(CompositePattern)将对象组合成树形结构以表示“部分-整体”的层次结构,组合模式使得用户对单个对象和组合对象的使用具有一致性。有时候又叫做部分-整体模 ... [详细]
  • 本文内容为asp.net微信公众平台开发的目录汇总,包括数据库设计、多层架构框架搭建和入口实现、微信消息封装及反射赋值、关注事件、用户记录、回复文本消息、图文消息、服务搭建(接入)、自定义菜单等。同时提供了示例代码和相关的后台管理功能。内容涵盖了多个方面,适合综合运用。 ... [详细]
  • PostgresX2 MPP部署试验
    2019独角兽企业重金招聘Python工程师标准MPP结构:129GTM节点,130coordinator、gtm_proxy、datanode& ... [详细]
  • Matlab:数学之美–绘制分形图形学习最好的动力是兴趣,所以我们先看看效果:这一篇与Java学习日记:数学之美-分形图形绘制有共同之处,只是所用的工具不同。clear;%不同的参 ... [详细]
  • A题这题贼水,直接暴力就可以了。用个bool数组记录一下,如果某一天,当前剩下的最大的出现了的话,就输出一段。1#include<stdio.h>2intn;3boolvi ... [详细]
  • #-*-coding:utf-8-*-print(upython与开源QGis课题研究组)#print(汉字)##创建矢量数据文件#try:fromosgeoimporto ... [详细]
  • 主函数:CStringGetCPUIDString()Copyright(C)shangweixiao2011 ... [详细]
  • 1引言在多线程并发编程中Synchronized一直是元老级角色,很多人都会称呼它为重量级锁,但是随着JavaSE1.6对Synchronized进行 ... [详细]
  • 本文目录一览:1、\mysybase.dump对数据库正常使用有影响吗 ... [详细]
  • xmake-ftmpxxx.luaxmake--filexxx.lua最简单:--添加名为demo的目标到工程target(demo)--设置目标程序类型为二进制,一般为 ... [详细]
  • 我是这么写的, ... [详细]
  • 我有一个vim默认安装在Linux上,在一个系统上有vt52终端仿真器和unicode功能。Vim不会接受换行一切都工作正常,直到今天,当 ... [详细]
  • 并发系列之CAS与原子操作1、CAS的概念2、Java实现CAS的原理-Unsafe类3、原子操作-AtomicInteger类源码简析4、CAS实现原子操作的三大问题4.1、AB ... [详细]
author-avatar
The-6ixth-Floor乐队
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有