2010年6月10日星期四

How to select a row in DataGridView

the C++.Net solution is :
this->dataGridView1->ClearSelection();
this->dataGridView1->SelectionMode = DataGridViewSelectionMode::FullRowSelect;
this->dataGridView1->Rows[i]->
Selected=true;
this->dataGridView1->
CurrentCell=this->dataGridView1->Rows[i]->Cells["ColumnName"];
这几步的作用分别是:
清除当前选择;设定选择模式为整行选取;设定某行为选定;设定当前网格

2009年4月6日星期一

将U盘格式化为NTFS格式

Windows系统默认只能将U盘格式化为FAT或者FAT32格式,这些格式有个最大文件的限制,还有其他,如保存大量小体积文件时,占用空间比较大。
怎样将U盘格式化为NTFS格式呢?
1. 打开设备管理器
操作方法是我的电脑点击右键,选择管理,在打开的窗口的左边的树中选择“设备管理器”
2. 在设备管理器的树中选择“磁盘驱动器”
3. 在磁盘驱动器中选择USB盘,点击右键,选择属性
4. 在属性窗口中选择策略,选择为性能优化。

好了,这样就可以格式化优盘为NTFS格式了。

2009年3月19日星期四

Using Resources in .NET

我有个C++.NET程序。
在修改Form自带的resx文件时会弹出 警告菜单"You are trying to edit a resources file that ..."
如果强制进行修改,当对Form进行其他修改后,resx会更新,手工进行的修改就会消失。
这是Visual Studio的一个BUG。
但是怎样添加自己想要的resources呢,如运行时载入的图片等等。
这里是一个可行的步骤:

1. 在名为MyProject的Project里添加MyResources.resx
2. 在MyResources.resx中添加你想要添加的Image如MyImage.png等resources资源文件。
注意,图片导入后,后缀就消失了。
3. 在代码中添加如下的代码进行操作:
using namespace System::Resources; // for ResourceManager and MissingManifestResourceException
using namespace System::Reflection; //for Assembly::GetExecutingAssembly()
try{
ResourceManager^ resources = gcnew ResourceManager("MyProject.MyResources", Assembly::GetExecutingAssembly());
this->toolStripMenuItem1->Image = (cli::safe_cast(resources->GetObject(L"MyImage")));

}catch(MissingManifestResourceException^ ex){
MessageBox::Show(ex->Message);
}
上述代码中的MyProject.MyResources是对应的MyProject.MyResources.resources文件名,这个文件在编译后存在于你的Debug和Release文件夹中,如果名字写错了,将会抛出MissingManifestResourceException异常。

好,祝你好运。

2009年3月14日星期六

Is it possible to deploy a .NET exe without installing .NET framework

在没有安装.NET Framework的平台上运行.NET程序,问题是可能吗?
答案是:没有不可能。
C#的出现是为了与Java抗衡,和Java一样,需要安装虚拟机平台来运行。如果没有CLR,似乎是不行的。但是如果将所有需要的dll都拷贝过来,将其他的所有设置相关的内容都拷贝过来,集成到exe中,不就可以了吗?

怎么做呢?Google Thinstall to Check the detail.
其他的包括

Static Compilation in Mono

Xenocode(Deploy your .NET app securely, with no Framework install ),
Remotesoft(Salamander .NET Linker, Native Compiler and Mini-Deployment Tool)

Thinstall软件已经被VMWare收购了。

.NET framework virtualization

Deploy and run .NET applications - with out installing the .NET framework. Run applications that require different versions of .NET, concurrently, without conflicts and protect code from dissassembly.

Challenges

Developing with the latest release of the .NET framework offers clear advantages. However, deploying an application requiring the latest .NET can present challenges due to a number issues including:

  • Other applications require an earlier version of .NET
  • Locked down desktops can not be upgraded immediately
  • Computers may need to have different versions of .NET installed concurrently

Whether a commercial application distributed to home computers or a custom application to corporate locked down computers, the correct version of the .NET framework - or any of the .NET components - may not be installed. This presents challenges in terms of updating, running, and installing applications and also problems when applications require different .NET versions to be installed.

VMware ThinApp Solution (Formerly Thinstall)

ThinApp provides essential features that make .NET deployments conflict free and secure. Benefits include:

  • Not requiring the .NET Framework to be installed. By packaging the application and linking the .NET framework with ThinApp, no installation of the .NET framework is required. The application runs without modifying the host computer.
  • Eliminating all installation errors and conflicts. ThinApp enables applications to run concurrently that each require a different version of .NET to be installed.
  • Reducing download and installation time. ThinApp packages all of the .NET framework or only the components that the program needs into a single, compressed EXE. This not only reduces the size of the components that need to be installed (and downloaded), but also makes ‘installation’ significantly faster. Nothing is installed, rather the program is run via the ThinApp Virtual Operating System.

Additionally, even applications created for internal corporate use at some point may be distributed externally. .NET applications can be easily disassembled with readily available developer tools that make inspection of source code easy, enabling hacking and reverse engineering relatively simple for any experienced programmer.

ThinApp also protects against hacking and disassembly. Rather than using obfuscation, ThinApp instead encrypts the .NET Program inside of secure loader which prevents disassembly. The resulting EXE no longer appears to be a .NET Program so codedisassemblers are unable to decrypt the program stored inside.

2009年3月4日星期三

error C2143: syntax error : missing ')' before 'constant'

翻译为汉语就是:在常数的前面缺少')'
例如,你在某处 #define A 1
但是在程序中某处又忘记了常数的定义,而使用了int A;等,就会得到这个错误。

一个可能的原因:Additional information: Cannot access a disposed object.

编译正常,但是在执行CSharp程序的时候却出现了Additional information: Cannot access a disposed object.

检查错误,是自己在Load程序中新建了一个Form对象,使用了Show(),改为ShowDialog()后正常。

Built successfully, but fail to run.
change the frmSomething.Show()
into frmSomething.ShowDialog();
Things are OK.

2009年2月28日星期六

How to open multiple files through single ifstream object?

怎样在定义了一个ifstream对象的情况下,打开多个文件。
重点:
每次打开新文件前,确保上一次的文件对象在close()之前被clear()!
// declare one ifstream object for every file

ifstream FileObject;

//open a input file which contain names of all files

ifstream InputFile("Input.txt");

while(std::getline(InputFile,buf)){
std::string name=buf;
FileObject.open(name.c_str());
if (!FileObject.is_open()){
//report error here.
continue;
}
while(std::getline(FileObject,buf2))
{ //doing some validation operations. }
//Clear the fileobject for next use
FileObject.clear();
//Prepare for next open,每次打开前都要clear和close
FileObject.close();
}