private void Page_Load(object sender, System.EventArgs e)
{
InfoCity infoCity = new InfoCity();
M1(infoCity);
M2(infoCity);
Response.Write(infoCity.CityName);
}
private void M1(InfoCity info)
{
info.CityName = "M1";
}
private void M2(InfoCity info)
{
info = new InfoCity(); // 改变了地址
info.CityName = "M2";
}
把 GB2312 编码转成汉字
string s = Convert.ToString(47524, 2); // 转成二进制
byte byte1 = Convert.ToByte(s.Substring(0, 8), 2);
byte byte2 = Convert.ToByte(s.Substring(8), 2);
byte[] array = new byte[2] { byte1, byte2 };
MessageBox.Show(System.Text.Encoding.GetEncoding("GB2312").GetString(array));
汉字获取 GB2312 编码
byte[] array = System.Text.Encoding.GetEncoding("GB2312").GetBytes("工");
string s1 = Convert.ToString(array[0], 16);
string s2 = Convert.ToString(array[1], 16);
int i = Convert.ToInt32(s1 + s2, 16);
MessageBox.Show(i.ToString());
1.二进制
二进制转十进制
int i = Convert.ToInt32("10100100", 2);
二进制转十六进制
int i = Convert.ToInt32("10100100", 2);
string s = Convert.ToString(i, 16);
2.十进制
十进制转二进制
string s = Convert.ToString(164, 2);
十进制转十六进制
string s = Convert.ToString(164, 16);
3.十六进制
十六进制转二进制
string s = Convert.ToString(0xa4, 2);
十六进制转十进制
int i = Convert.ToInt32("A4", 16)
string s = Convert.ToString(0xa4, 10);
1.使用abstract关键字
2.实现抽象方法用override关键字。
public abstract class ThreadMan
{
protected bool sleep = false;
public void Suspend()
{
sleep = true;
}
public void Resume()
{
sleep = false;
}
public abstract void ThreadProc();
}
public class ThreadHH : ThreadMan
{
public override void ThreadProc()
{
while(true)
{
System.Windows.Forms.MessageBox.Show("Hello ThreadProc!");
Thread.Sleep(2000);
while (sleep)
{
Thread.Sleep(100);
}
}
}
}
要Post ViewState、EventValidation的值
string viewState = "/wEPDwUKMTk4MTYLDzI/WN9r0TKKWFH6vw==";
stringeventValidation = "/wEWGwLL1JTyAQK4oc2iCgK0jZI7vlS/";
viewState = System.Web.HttpUtility.UrlEncode(viewState);
eventValidation = System.Web.HttpUtility.UrlEncode(eventValidation);
string postData = "__VIEWSTATE=" + viewState + "&__EVENTVALIDATION=" + eventValidation;
关于分页,指定 EventTarget
postData += "&__EVENTTARGET="
每次新页面的ViewState、EventValidation的值都会变
// Ctrl + H
if ((Control.ModifierKeys & Keys.Control) != 0 && e.KeyCode == Keys.H)
{
MessageBox.Show("Ctrl + H");
}
// Alt + H
if ((Control.ModifierKeys & Keys.Alt) != 0 && e.KeyCode == Keys.H)
{
MessageBox.Show("Alt + H");
}
// Shift + H
if ((Control.ModifierKeys & Keys.Shift) != 0 && e.KeyCode == Keys.H)
{
MessageBox.Show("Shift + H");
}
// Ctrl + Alt + Shift + H
if ((Control.ModifierKeys & Keys.Control) != 0 &&
(Control.ModifierKeys & Keys.Alt) != 0 &&
(Control.ModifierKeys & Keys.Shift) != 0 &&
e.KeyCode == Keys.H)
{
MessageBox.Show("Ctrl + Alt + Shift + H");
}
通过调用系统的API实现
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern IntPtr CreateDC(
string lpszDriver, // 驱动名称
string lpszDevice, // 设备名称
string lpszOutput, // 无用,可以设定位"NULL"
IntPtr lpInitData // 任意的打印机数据
);
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern bool BitBlt(
IntPtr hdcDest, // 目标设备的句柄
int nXDest, // 目标对象的左上角的X坐标
int nYDest, // 目标对象的左上角的X坐标
int nWidth, // 目标对象的矩形的宽度
int nHeight, // 目标对象的矩形的长度
IntPtr hdcSrc, // 源设备的句柄
int nXSrc, // 源对象的左上角的X坐标
int nYSrc, // 源对象的左上角的X坐标
int dwRop // 光栅的操作值
);
private void button1_Click(object sender, EventArgs e)
{
//创建显示器的DC
IntPtr dc1 = CreateDC("DISPLAY", null, null, (IntPtr)null);
//由一个指定设备的句柄创建一个新的Graphics对象
Graphics g1 = Graphics.FromHdc(dc1);
//根据屏幕大小创建一个与之相同大小的Bitmap对象
Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, g1);
//根据此位图创建一个和其一样的Graphic对象
Graphics g2 = Graphics.FromImage(bitmap);
//获得屏幕的句柄
IntPtr dc3 = g1.GetHdc();
//获得位图的句柄
IntPtr dc2 = g2.GetHdc();
//把当前屏幕捕获到位图对象中,实现屏幕捕获
BitBlt(dc2, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, dc3, 0, 0, 13369376);
//释放屏幕句柄
g1.ReleaseHdc(dc3);
//释放位图句柄
g2.ReleaseHdc(dc2);
bitmap.Save("c:\\1.jpg", ImageFormat.Jpeg);
}
Byte[]数组与其他数据类型相互转换
通过 BitConverter 类实现
把整型转成 byte[]
byte[] arrayByte = BitConverter.GetBytes(10);
把 byte[] 转成整型
byte[] arrayByte = BitConverter.GetBytes(10);
int a = BitConverter.ToInt32(arrayByte, 0);
把字符串转成 byte[]
string str = "汉字";
byte[] arrayByte = System.Text.Encoding.GetEncoding("GB2312").GetBytes(str);
把 byte[] 转成字符串
string str = "汉字";
byte[] arrayByte = System.Text.Encoding.GetEncoding("GB2312").GetBytes(str);
string str2 = System.Text.Encoding.GetEncoding("GB2312").GetString(arrayByte);
其他数据类型如:Boolean、Char、Single、Double、Int64等都可用 BitConverter 类实现相互转换
通过钩子,用快捷键激活窗体,实现窗体显示在用户界面的前台。
if (this.WindowState == FormWindowState.Normal || this.WindowState == FormWindowState.Maximized)
{
this.Activate();
}
else
{
// 窗体处在最小化状态
this.WindowState = FormWindowState.Normal;
this.Focus();
this.Activate();
}