Dll path: C:\Program Files (x86)\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.ExceptionMessageBox.dll
Document: http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.messagebox.exceptionmessagebox.aspx
Nothing is everything.
Thursday, December 31, 2009
Wednesday, December 30, 2009
Event Recursion Problem
We often meet some issues that an event will be fired recursively and its handlers will also be called recursively. Below is a sample which shows a AfterCheck event handler of the TreeView in similar circumstances:
void treeView1_AfterCheck(object sender, TreeViewEventArgs e)
{
if (e.Node.Nodes.Count > 0)
{
foreach (TreeNode subNode in e.Node.Nodes)
{
//This property setting will firing the AfterCheck event again.
subNode.Checked = true;
}
}
}
To control the event firing and handler calling, we need to create our own TreeView control and override the OnAfterCheck method to control the event firing. There are four requirements below:
1. The event should be fired recursively and its handlers can also be called recursively.
In this case, we need to do nothing.
2. The event should be fired only once and its handlers can only be called once as well.
public class MyTreeView : TreeView
{
//Indicate if the event should be fired.
private bool IsFire = true;
protected override void OnAfterCheck(TreeViewEventArgs e)
{
if (IsFire)
{
IsFire = false;
//Your Code in the old AfterCheck event handler.
IsFire = true;
base.OnAfterCheck(e);
}
}
}
3. The event should be fired recursively but the handler can only be called once.
public class MyTreeView : TreeView
{
//Indicate if the event should be fired.
private bool IsFire = true;
protected override void OnAfterCheck(TreeViewEventArgs e)
{
if (IsFire)
{
IsFire = false;
//Your Code in the old AfterCheck event handler.
IsFire = true;
base.OnAfterCheck(e);
}
else
{
base.OnAfterCheck(e);
}
}
}
4. The handler should be called recursively but the event can only be fired once.
public class MyTreeView : TreeView
{
//Indicate if the event should be fired.
private bool IsFire = true;
protected override void OnAfterCheck(TreeViewEventArgs e)
{
if (IsFire)
{
IsFire = false;
//Your Code in the old AfterCheck event handler.
IsFire = true;
base.OnAfterCheck(e);
}
else
{
//Your Code in the old AfterCheck event handler.
}
}
}
Please feel free to tell me if I made some mistakes. Thanks.
Tuesday, December 29, 2009
Monday, December 28, 2009
Sunday, December 27, 2009
Friday, December 25, 2009
Thursday, December 24, 2009
Wednesday, December 23, 2009
Tuesday, December 22, 2009
Thursday, December 17, 2009
Bind a BindingSource to a Type
When we set the DataSource property of the BindingSource class to a Type instance, it will automatically create a empty IBindingList and bind it to the BindingSource. This will result in an allowance to call the AddNew method of the BindingSource to add a new object of the corresponding type. If the type implements IList, the object type will be T, not IList.
By the way, in this case, the type of the inner data source is System.RuntimeType. This is an introduction:
http://doogalbellend.blogspot.com/2006/06/what-is-systemruntimetype.html
This is the details: http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.datasource.aspx
By the way, in this case, the type of the inner data source is System.RuntimeType. This is an introduction:
http://doogalbellend.blogspot.com/2006/06/what-is-systemruntimetype.html
This is the details: http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.datasource.aspx
Wednesday, December 16, 2009
How to modify the app.config programmatically.
The code snippet below shows how add a connection string during runtime:
// Open App.Config of executable
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
// Add an Application Setting.
config.ConnectionStrings.ConnectionStrings.Add(new ConnectionStringSettings("myConnectionString1", @"Data Source=MyPC\SQLEXPRESS;Initial Catalog=MyDataBase2;User ID=MyUserName"));
// Save the configuration file.
config.Save(ConfigurationSaveMode.Modified);
// Force a reload of a changed section.
ConfigurationManager.RefreshSection("appSettings");
The link below contains the details:
http://geekswithblogs.net/akraus1/articles/64871.aspx
// Open App.Config of executable
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
// Add an Application Setting.
config.ConnectionStrings.ConnectionStrings.Add(new ConnectionStringSettings("myConnectionString1", @"Data Source=MyPC\SQLEXPRESS;Initial Catalog=MyDataBase2;User ID=MyUserName"));
// Save the configuration file.
config.Save(ConfigurationSaveMode.Modified);
// Force a reload of a changed section.
ConfigurationManager.RefreshSection("appSettings");
The link below contains the details:
http://geekswithblogs.net/akraus1/articles/64871.aspx
How to modify the app.config during runtime.
This is the code:
// Open App.Config of executable
System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
// Add an Application Setting.
config.AppSettings.Settings.Add("Modification Date",
DateTime.Now.ToLongTimeString() + " ");
// Save the configuration file.
config.Save(ConfigurationSaveMode.Modified);
// Force a reload of a changed section.
ConfigurationManager.RefreshSection("appSettings");
The link below shows the details:
// Open App.Config of executable
System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
// Add an Application Setting.
config.AppSettings.Settings.Add("Modification Date",
DateTime.Now.ToLongTimeString() + " ");
// Save the configuration file.
config.Save(ConfigurationSaveMode.Modified);
// Force a reload of a changed section.
ConfigurationManager.RefreshSection("appSettings");
The link below shows the details:
How to set StartUri in WPF
We can easily set the start window of a WPF application by setting the StartupUri property of the Application node in the App.xaml to the window xaml file name, such as "Window1.xaml". But if the Window1.xmal is placed in another folder, what can we do?
We only need to add the directory path before the window xaml file name, such as "Palyer/MyPlayerWindow.xaml" or "Palyer\MyPlayerWindow.xaml".
We only need to add the directory path before the window xaml file name, such as "Palyer/MyPlayerWindow.xaml" or "Palyer\MyPlayerWindow.xaml".
How to convert a char to a digit efficiently
We often need to allow the user to input a digit(0~9). We can call getch() method to get the char, because it is fast. But when we convert it to a digit, it becomes a little complicated, since we need to build a string and call atoi.
There is a simple and efficient method to achieve this:
int digit = getchar() & 0xF.
These are the binary formats of the digits:
0: 11 0000
1: 11 0001
...
0xF: 00 1111
So this calculation will remove the high bits and only leave the lower four bits, these bits formed a new integer, which is just the digit we need.
There is a simple and efficient method to achieve this:
int digit = getchar() & 0xF.
These are the binary formats of the digits:
0: 11 0000
1: 11 0001
...
0xF: 00 1111
So this calculation will remove the high bits and only leave the lower four bits, these bits formed a new integer, which is just the digit we need.
Tuesday, December 15, 2009
How to call C++ function in C#
#include "stdafx.h"
#include "QueryAPI.h"
extern "C"
{
__declspec(dllexport) unsigned long QueryUser(const wchar_t* AccountName,
wchar_t* FullUserName,
wchar_t* EmailAddress,
double* Salary,
wchar_t* CardId,
int* Old,
bool* Single)
{
cout<<*AccountName; char* name = "微软" ; ::memcpy((void*)FullUserName,name,100); char* Email = "guochao6398@126.com";
::memcpy((void*)EmailAddress,Email,100);
char* CardID = "12345678";
::memcpy((void*)CardId,CardID,20);
*Salary = 200.34;
//*CardId = "123456789";
*Old = 2;
*Single = false;
return 0;
}
}
#include "QueryAPI.h"
extern "C"
{
__declspec(dllexport) unsigned long QueryUser(const wchar_t* AccountName,
wchar_t* FullUserName,
wchar_t* EmailAddress,
double* Salary,
wchar_t* CardId,
int* Old,
bool* Single)
{
cout<<*AccountName; char* name = "微软" ; ::memcpy((void*)FullUserName,name,100); char* Email = "guochao6398@126.com";
::memcpy((void*)EmailAddress,Email,100);
char* CardID = "12345678";
::memcpy((void*)CardId,CardID,20);
*Salary = 200.34;
//*CardId = "123456789";
*Old = 2;
*Single = false;
return 0;
}
}
Subscribe to:
Posts (Atom)