Thursday, December 4, 2008

Porting a large applcation to run on Mono

Forms and Fonts

*Remove any auto scaling;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

*Change the AutoScaleMode and font;
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.Font = System.Drawing.SystemFonts.DefaultFont;

These changes ensure that your forms will have a look that is consistent with whichever operating system you put them on be it Vista, Windows XP, Linux etc.

*Use PNG files for your graphics!
I had horrible problems trying to get transparency working until I switched.

File System
You must use Path.DirectorySeparatorChar for any file system operations.

Sockets

I stumbled across this gem when testing the port on Vista.
If the operating system supports IPv6 and actually has is using it then you will need to use them!



//Create an IPAddress
private IPAddress GetIPAddress(string host)
{
IPHostEntry ipHostInfo = Dns.GetHostEntry(host);
// raise an exception if no addresses are present
return ipHostInfo.AddressList[0];
}

IPAddress ipAddress = GetIPAddress("localhost");

// Create an IPv6 socket
if (ipAddress.AddressFamily == AddressFamily.InterNetworkV6 && Socket.OSSupportsIPv6)
{
socket = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);
}
else
{
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
}

No comments: