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

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

转载于:https://www.cnblogs.com/danch/archive/2011/10/31/2229941.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值