鼠标可以控制窗体(包括非标题栏)移动 || ?? 运算符
2011-10-31 11:10
399 查看
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; namespace MoveFormOfNoneBorderStyle { public partial class Form1 : Form { [DllImport("user32.dll")] public static extern bool ReleaseCapture(); [DllImport("user32.dll")] public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int IParam); public const int WM_SYSCOMMAND = 0x0112; public const int SC_MOVE = 0xF010; public const int HTCAPTION = 0x0002; public Form1() { InitializeComponent(); } private void Form1_MouseDown(object sender, MouseEventArgs e) { ReleaseCapture(); SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0); //SendMessage(this.Handle, 274, 61458, 0); } static int? GetNullableInt() { return null; } static string GetStringValue() { return null; } private void button1_Click(object sender, EventArgs e) { //?? 运算符称为 null 合并运算符,用于定义可以为 null 值的类型和引用类型的默认值。 //如果此运算符的左操作数不为 null,则此运算符将返回左操作数;否则返回右操作数。 // ?? operator example. // ?? 运算符例子 int? x = null; // y = x, unless x is null, in which case y = -1. //y = x, 如果 x 为空,那 y = -1; int y = x ?? -1; // Assign i to return value of method, unless // return value is null, in which case assign // default value of int to i. // 定义 i 并从方法返回一个值,如果返回的值为空, // 则初始化 i 的值为int类型的默认值 int i = GetNullableInt() ?? default(int); string s = GetStringValue(); // ?? also works with reference types. // Display contents of s, unless s is null, // in which case display "Unspecified". // ?? 也可以用于引用类型。 // 显示 s 的文本, 如果 s 为空, // 那显示 “Unspecified”。 MessageBox.Show(s ?? "Unspecified"); } } }
上部分为鼠标可以控制窗体(包括非标题栏)移动,下部分为 ?? 运算符 (??运算符) 说明。。。 by danch744
这是微软MSDN上的:http://msdn.microsoft.com/zh-cn/library/ms173224.aspx
相关文章推荐
- c# WinForm 中鼠标控制窗体的移动
- 设置鼠标可以移动窗体
- 设置鼠标可以移动窗体
- 设置鼠标可以移动窗体
- 设置鼠标可以移动窗体
- 如何通过鼠标控制无标头窗体
- MFC对话框禁止移动 使标题栏不响应鼠标消息 通过客户区移动窗体 OnNcHitTest()的实现
- 简单的鼠标移动窗体
- 如何在LISTBOX中移动鼠标就可以起到CLICK的作用
- 仿淘宝商品图片放大镜效果(鼠标移动上去会出现放大的图片,并且可以移动)
- Winform 没有FormBorder的情况下 支持鼠标移动窗体
- 如何单击鼠标移动整个窗体
- 网站开发积累(鼠标控制图片左右移动)
- CSS3实现鼠标移动到图片上图片变大(缓慢变大,有过渡效果,放大的过程是有动画过渡的,这个过渡的时间可以自定义)
- winfrom 无窗体边框的时候可以让窗体移动直接在控件上写事件
- 父子窗体滚动条支持鼠标滚轮移动
- Winfrom窗体在去掉窗体边框的情况下使鼠标移动窗体
- MFC对话框禁止移动 使标题栏不响应鼠标消息 通过客户区移动窗体 OnNcHitTest()的实现
- WPF设置窗体可以使用鼠标拖动大小的方法
- 如何在LISTBOX中移动鼠标就可以起到CLICK的作用