显示具有 C# 标签的文章。 显示所有文章
显示具有 C# 标签的文章。 显示所有文章

2007年10月27日 星期六

How to Resize Windows with No Form border in .NET

如何在.NET调整一个无窗体边缘的窗体?

  在Naio Talk的界面设计部分,由于项目周期的问题以及对Windows系统编程尤其是消息传递机制的不熟悉,选择了.NET来开发。为了使得克服.NET带来的窗体反应迟钝感,打算对Naio Talk的界面经行彻底精心设计。

  其中计划将Naio Talk的主界面的窗体边框去掉。一是减少重绘,二是看上去更加轻薄。

首先设置窗体FormBorderStyle = None;
然后添加如下C#代码即可。

protected override void WndProc(ref Message m)
{base.WndProc(ref m);
switch (m.Msg)
{
case WM_NCHITTEST:
Point vPoint = new Point((int)m.LParam &
0xFFFF,

(int)m.LParam >> 16 &
0xFFFF);

vPoint = PointToClient(vPoint);
if (vPoint.X <= 5)
if (vPoint.Y <= 5)
m.Result = (IntPtr)HTTOPLEFT;
else if (vPoint.Y >= ClientSize.Height -5)
m.Result = (IntPtr)HTBOTTOMLEFT;
else m.Result = (IntPtr)HTLEFT;
else if (vPoint.X >= ClientSize.Width - 5)
if (vPoint.Y <= 5)
m.Result = (IntPtr)HTTOPRIGHT;
else if (vPoint.Y >= ClientSize.Height - 5)
m.Result = (IntPtr)HTBOTTOMRIGHT;
else m.Result = (IntPtr)HTRIGHT;
else if (vPoint.Y <= 5)
m.Result = (IntPtr)HTTOP;
else if (vPoint.Y >= ClientSize.Height - 5)
m.Result = (IntPtr)HTBOTTOM;
break;
}
}
}

以及如下的成员变量。

const int WM_NCHITTEST = 0x0084;
const int HTLEFT = 10;
const int HTRIGHT = 11;
const int HTTOP = 12;
const int HTTOPLEFT = 13;
const int HTTOPRIGHT = 14;
const int HTBOTTOM = 15;
const int HTBOTTOMLEFT = 0x10;
const int HTBOTTOMRIGHT = 17;



2007年10月26日 星期五

如何设置Google企业用户帐号连接Google Talk服务

  如果你使用Google Talk来连接您的Google App(Google 企业应用程序),那么您不会碰到无法连接的问题。

  然而,企业用户毕竟是个企业,而非个人。必然有企业的需求,这也是会出现那么多Enterprise版本的原因吧。
企业内部可能需要自己的通讯客户端。比如YourCompany Talk.不过我在完成一个Besti Talk的时候,发现 -_-我竟然连不上Google 的Jabber服务器。后来才发现配置的问题。
以下是正确配置和使用agsXMPP SDK的参考代码。

string input = support@naionetwork.net;
Jid jid = new Jid(input);
_connection.Server= jid.Server;
_connection.Username= jid.User;
_connection.Password= “my password”;
_connection.Resource= "psi";
_connection.Priority= 10; //一般我习惯写5
_connection.Port= 5223;
_connection.UseSSL= true
_connection.AutoResolveConnectServer=False;
_connection.ConnectServer ="talk.google.com";//not null
_connection.SocketConnectionType =agsXMPP.net.SocketConnectionType.Direct;
_connection.UseStartTLS = true;


  如果我的Google App帐号是support@naionetwork.net
  则 jid.server = naionetwork.net
  这里要区别的是ConnectServer = "talk.google.com"。同时你要记得设置AutoResolveConnectServer为False.否则就找naionetwork.net来连接您的Jabber服务器了。如果您使用Google App帐号,显然无法成功通讯了。

2007年10月24日 星期三

在.NET中使用Sqlite的解决方案

使用正确的Wrapper将使得在C#中使用Sqlite更加方便。半年前试图在C#中通过调用普通DLL的方法使用Sqlite,比较繁琐。这里又一个phpguru的SQLite.NET wrapper,使用起来和Visual Studio自带的库能很自然的结合。

开发文档:
http://www.phpguru.org/static/SQLite.NET.html

下载:
http://www.phpguru.org/downloads/csharp/SQLite.NET/

使用范例:

using SQLite.NET;


Open



try
{
Console.WriteLine("opening db...");
// Open database
SQLiteClient db = new SQLiteClient("c:\test.db");

}
catch (SQLiteException e)
{
Console.WriteLine("Fatal error: {0}", e.Message);
return;
}

Select:


ArrayList tables = db.GetColumn("SELECT name FROM sqlite_master WHERE type = 'table'");

foreach (string tableName in tables)
{
Console.WriteLine("\t" + tableName);
}
 
(L)1984 - 2007 TONY CHEUNG