您的位置:首页 > 其它

鼠标可以控制窗体(包括非标题栏)移动 || ?? 运算符

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: