[DllImport("gdi32.dll")]
private static extern bool BitBlt(
IntPtr hdcDest, // handle to destination DC
int nXDest, // x-coord of destination upper-left corner
int nYDest, // y-coord of destination upper-left corner
int nWidth, // width of destination rectangle
int nHeight, // height of destination rectangle
IntPtr hdcSrc, // handle to source DC
int nXSrc, // x-coordinate of source upper-left corner
int nYSrc, // y-coordinate of source upper-left corner
System.Int32 dwRop // raster operation code
);
private void button2_Click(object sender, EventArgs e)
{
Graphics g1 = this.CreateGraphics();
Image MyImage = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height, g1);
Graphics g2 = Graphics.FromImage(MyImage);
IntPtr dc1 = g1.GetHdc();
IntPtr dc2 = g2.GetHdc();
BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0, 0, 13369376);
g1.ReleaseHdc(dc1);
g2.ReleaseHdc(dc2);
MyImage.Save(@"c:\1.jpg", ImageFormat.Jpeg);
}
方法很简单,首先被copy的类需要实现IClonable的接口,具体实现方法如下:
public object Clone()
{
MemoryStream ms = new MemoryStream();
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(ms, this);
ms.Position = 0;
object obj = bf.Deserialize(ms);
ms.Close();
return obj;
}
当然,需要引用System.Runtime.Serialization.Formatters.Binary namespace.
其实,如果有很多类需要实现deep copy的话,可以考虑用一个抽象类实现IClonable接口,其他的类继承这个抽象类就可以了。
以前看到过一个测试:
有一盘葡萄,你会选择什么吃法?
A 每次都挑最好的一颗吃;
B 每次都挑最差的一颗吃;
C 随机拿一颗吃;
不知道大家会有怎样的选择,不过其中有一些隐含的道理。如果你每次都选最好或者最差,你是要花费很长时间来挑选的。而且你要保证你一直按照最好或者最差的线路,是很困难的。
所以生活当中,你永远不可能一直吃到最好的或是最差的葡萄。所以很多时候的比较,就是上一颗葡萄和正在吃的这颗。我们很难拿很久以前的一颗和现在的比较,更不会拿现在这颗和很久以后的某颗比较。因为现在这颗酸的,正酸得让人牙痛呢!
你想吃的葡萄有哪些呢?又在哪里呢?或许,你的葡萄是被人塞进来的,你会直接吞下去吗?
昨天上午,闲得无聊,就想到去理发。小区门口有家理发店,不过阿邓说那里理得不好,不过自己也懒得跑了。
今天来公司,就有人说,我的发型很有个性,够短!! 而且,基本上每个人都会这么说几句,看来这个发确实理得很失败了!
总结一下,虽然头发理得很失败,但是,够凉快(我的位置正对着空调)!踢球比较有感觉(不过是脚,昨天没顶到头球的)!省钱(好几个月不用去理发了,哈哈)
周六,阿邓的同学过来吃中饭。期间,和她一个宿舍的MM说,阿邓的手技进步很大呀!
呵呵,可惜她同学不知道,上次她过来是阿邓炒的菜,而这次是我炒的菜!
参考:http://www.codeproject.com/csharp/fscommand.asp
1. FSCommand事件;
fscommand("Button","Blue");
axShockwaveFlash1.FSCommand += new AxShockwaveFlashObjects._IShockwaveFlashEvents_FSCommandEventHandler(this.axShockwaveFlash1_FSCommand);
private void axShockwaveFlash1_FSCommand(object sender, AxShockwaveFlashObjects._IShockwaveFlashEvents_FSCommandEvent e)
{
// (e.command) e.args
}
2. axShockwaveFlash1.SetVariable("data",flashData);
axShockwaveFlash1.GetVariable("data");
在flash中通过Obejct.watch()得到结果
var mo:Object=new Object();
mo.watch("txt");
这两天要实现一个功能,中间因为走了一点弯路,呵呵,所以记下来!
功能:
创建几个文本文件,然后将它们压缩为一个zip文件。 下面是压缩的helper.
using
using System.Collections;
using
System.Collections.Generic;
using
System.Text;
using
System.IO;
using
ICSharpCode.SharpZipLib.Zip;
using
ICSharpCode.SharpZipLib.Core;
using
ICSharpCode.SharpZipLib.Checksums;
namespace
{
GadgetTestpublic class ZipHelper
{
{
m_ZipFile = zipFile;
m_files =
}
{
m_files.Add(
}
{
private string m_ZipFile;private ArrayList m_files;public ZipHelper(string zipFile)new ArrayList();public void AddFileItem(string fileName, string fileContent)new FileItem(fileName, fileContent));public void Compress()//System.IO.FileStream ZipFile = new FileStream(m_ZipFile, FileMode.Create);
System.IO.
{
ZipStream.SetLevel(9);
{
FileStream ZipFile = File.Create(m_ZipFile);using (ZipOutputStream ZipStream = new ZipOutputStream(ZipFile))int index = 0;Crc32 crc = new Crc32();foreach (object var in m_files)FileItem fileItem = (FileItem)var;ZipEntry ZipEntry = new ZipEntry(fileItem.FileName);//必须正确的设置crc和size,否则Winzip解压时会有问题。
crc.Reset();
crc.Update(fileItem.FileContent);
ZipEntry.Size = fileItem.FileContent.Length;
ZipEntry.Crc = crc.Value;
ZipStream.PutNextEntry(ZipEntry);
try
{
ZipStream.Write(fileItem.FileContent,0,fileItem.FileContent.Length);
ZipStream.CloseEntry();
}
{
System.Diagnostics.
}
}
ZipStream.Flush();
ZipStream.Close();
}
ZipFile.Close();
}
}
catch (System.Exception ex)Debug.WriteLine(ex.Message);internal class FileItem
{
{
m_fileContent = fileContent;
//不同的Encoding格式会导致最后的文本文件的format不一样。
m_content =
m_fileName = fileName;
}
{
}
{
private string m_fileName;private string m_fileContent;private byte[] m_content;public FileItem(string fileName, string fileContent)Encoding.UTF8.GetBytes(fileContent); public string FileNameget { return m_fileName; } public byte[] FileContentget
{
}
}
}
}
return m_content;
System;
昨天晚上没事看电视,新闻里面说到一个拐卖儿童的案例。一位妇女被拐卖到潮州某地区后,被当地的文化同化,极力维护当地的传宗接代的思想。其实对于这种思想,我也不想说什么。她看到很多家庭没有男孩,就到外地偷儿童,转卖到本地。而当地人对于这种行为,也没有觉得什么不妥,觉得是理所当然的事。借用他们族长的话来说,就是没有后代,是绝对不行的,所以买一个男孩回来是很正常的事情。当然,妇女在当地的地位是不高的。
我觉得这个妇女的转化是一个很有意思的问题。为什么她会极力维护一个对妇女并不公平的思想?扯远一点,就是为什么有的人在一个对自己不利的氛围中,还要极力维护这样的氛围呢?难听一点就是,别人打了左脸,再把右脸转过去给人打。当然,我相信这样的人基本都不是圣人。
生活当中,其实我们也会犯这样的错误,不过可能是没有意思到罢了。呵呵
但究竟是什么在诱使我们做出这样的行为呢?利益?文化?还是就是盲从?