An MDI child with FormBorderStyle set to None will still draw borders briefly when loading.
A microsoft report on this bug: connect.microsoft.com
If you do your own skinning this creates a very unprofessional look.
I solved it by overloading WndProc and handling WM_NCACTIVATE, WM_NCPAINT, WM_NCUAHDRAWCAPTION and WM_NCUAHDRAWFRAME manually.
I'll post some code later if someone is interested.
Windows Taskbar Location
I was working on a form window today that pops up from windows tray area and I wanted it to have a different location depending on taskbar dock location.
So again I find lots of people using API (SHAppBarMessage) and other sloppy solutions and came up with my own idea to simply compare Screen.PrimaryScreen.WorkingArea with Screen.PrimaryScreen.Bounds.
Here is my code:
Enjoy!
So again I find lots of people using API (SHAppBarMessage) and other sloppy solutions and came up with my own idea to simply compare Screen.PrimaryScreen.WorkingArea with Screen.PrimaryScreen.Bounds.
Here is my code:
private enum TaskBarLocation { Left, Right, Top, Bottom, Hidden };
private TaskBarLocation GetLocation()
{
Rectangle taskBarRect = Rectangle.Intersect(Screen.PrimaryScreen.WorkingArea, Screen.PrimaryScreen.Bounds);
if (taskBarRect.Width == Screen.PrimaryScreen.Bounds.Width)
{
return taskBarRect.Y == 0 ? TaskBarLocation.Bottom : TaskBarLocation.Top;
}
else if (taskBarRect.Height == Screen.PrimaryScreen.Bounds.Height)
{
return taskBarRect.X == 0 ? TaskBarLocation.Right : TaskBarLocation.Left;
}
else
{
return TaskBarLocation.Hidden;
}
}
Then to set window location:
switch (GetLocation())
{
case TaskBarLocation.Left:
this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Left, Screen.PrimaryScreen.WorkingArea.Height - this.Height);
break;
case TaskBarLocation.Top:
this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - this.Width, Screen.PrimaryScreen.WorkingArea.Top);
break;
case TaskBarLocation.Right:
case TaskBarLocation.Bottom:
default:
this.Location = new Point(Screen.PrimaryScreen.WorkingArea.Width - this.Width, Screen.PrimaryScreen.WorkingArea.Height - this.Height);
break;
}
Enjoy!
Proper way to handle FormClosing event
Most common way to minimize an application is to override the FormClosing event by setting e.Handled = true; and then proceed to set form as hidden.
This creates a problem when the operating system want to close your application. The application simply refuses to close.
There are lots of solutions for this and in the past I've implemented an override to WndProc() and checked for WM_CLOSE message. This is not a very clean solution.
Today I found e.CloseReason and it's a beauty!
Check this out:
It is also a very clean solution for MDI windows that you simply want to hide.
This creates a problem when the operating system want to close your application. The application simply refuses to close.
There are lots of solutions for this and in the past I've implemented an override to WndProc() and checked for WM_CLOSE message. This is not a very clean solution.
Today I found e.CloseReason and it's a beauty!
Check this out:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)
{
// Minimize to system tray
e.Cancel = true;
this.Visible = false;
this.notifyIcon1.Visible = true;
}
}
The above solution will handle system shutdown etc etc.
It is also a very clean solution for MDI windows that you simply want to hide.
Exposing functions to LUA
Following the previous thread. Here is an example how to expose a C# function to the LUA script:
And the script.lua file:
private readonly Lua lua = new Lua();
static void Main(string[] args)
{
lua.RegisterFunction("talk", this, GetType().GetMethod("Talk"));
lua.DoFile("script.lua");
}
public void Talk(string s)
{
Console.WriteLine(s);
}
And the script.lua file:
talk("Hello World")
Implementing LUA
Adding LUA scripting to your .NET project is really simple.
1. Download LuaInterface
http://luaforge.net/projects/luainterface/
2. Copy LuaInterface.dll and lua51.dll to your project folder.
3. Add a project reference to LuaInterface.dll
Example C# code:
The script.lua file looks like this:
It's also very easy to expose variables, functions, classes and even the whole CLR to LUA. I'll explain how this works in a later post.
1. Download LuaInterface
http://luaforge.net/projects/luainterface/
2. Copy LuaInterface.dll and lua51.dll to your project folder.
3. Add a project reference to LuaInterface.dll
Example C# code:
private readonly Lua lua = new Lua();
lua.DoFile("script.lua");
LuaFunction luaFunction = lua.GetFunction("square");
double ret = (double)luaFunction.Call(5).GetValue(0);
Console.WriteLine(ret.ToString());
The script.lua file looks like this:
function square(x) return (x * x) end
It's also very easy to expose variables, functions, classes and even the whole CLR to LUA. I'll explain how this works in a later post.
Compiled Option In RegEx
There seems to be a bug in .NET RegEx for Windows Vista 64 when using RegexOptions.Compiled option.
If the pattern is a really big string then the actual compilation will get stuck in an infinite loop. I tried with a RegEx that took 20 ms to compile on Windows XP 32 bit, that froze the entire program on Vista 64 bit. I killed the process after 5+ minutes. It had then consumed 300 mb of memory.
Removing the Compiled option made the it run as usual with no delay. It did not happen on Vista 32 bit.
Tried this in framework 2.0, 3.0 and 3.5 with same results.
Regex rex = new Regex(pattern, RegexOptions.Compiled);
If the pattern is a really big string then the actual compilation will get stuck in an infinite loop. I tried with a RegEx that took 20 ms to compile on Windows XP 32 bit, that froze the entire program on Vista 64 bit. I killed the process after 5+ minutes. It had then consumed 300 mb of memory.
Removing the Compiled option made the it run as usual with no delay. It did not happen on Vista 32 bit.
Tried this in framework 2.0, 3.0 and 3.5 with same results.
GetHostEntry.AddressList
The common solution seems to be extracting element 0 and use that:
This causes a SocketException when trying to use "localhost" in Windows Vista and Windows 7. The reason is that the first element is not of type InterNetwork. The cause is probably ipv6 but I've not investigated it further.
Assuming element 0 is a valid address without checking the other seems like a bad idea for anyone.
Here is my solution:
_Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); _EndPoint = new IPEndPoint(Dns.GetHostEntry(host).AddressList(0), Port);
This causes a SocketException when trying to use "localhost" in Windows Vista and Windows 7. The reason is that the first element is not of type InterNetwork. The cause is probably ipv6 but I've not investigated it further.
Assuming element 0 is a valid address without checking the other seems like a bad idea for anyone.
Here is my solution:
private IPAddress GetIPAddress(string host)
{
foreach (IPAddress addr in Dns.GetHostEntry(host).AddressList) {
if (addr.AddressFamily == AddressFamily.InterNetwork) {
return addr;
}
}
throw new SystemException("Invalid hostname.");
}
_Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); _EndPoint = new IPEndPoint(GetIPAddress(host), port);
Convert to VB.NET and back
I may post code for both C# and VB.NET. If you would like to easily convert between the two I recommend this site:
http://www.developerfusion.com/tools/convert/csharp-to-vb/
First!
I've been thinking about sharing my .NET solutions and thoughts for a while. So I decided to create this blogg.
I'll write a little about myself once some material are in.
Welcome!
About Me
Upplagd av
Conny
/
/
Resume
Conny Wallström
Age: 31
Location: Gothenburg, Sweden
E-Mail: conny.wallstrom@gmail.com
Contact me on e-mail for additional contact details.
I am an experienced software developer that has worked professionally for 12 years. I am mostly self-educated, with computers and programming having been my main focus for as long as I can remember. I am an optimist and pride myself on finding solutions where others may only see problems. I am a fast learner, a team player and I love challenges and opportunities for personal and professional growth. Swedish is my native language but I speak and write English fluently.
Other interests include marial arts training and instruction, professional dj'ing, and fishing.
Areas of Expertise
Programming languages
C#, VB.NET, C, C++, Objective-C, JavaScript, ASP, ASP.NET, Perl, PHP, DHTML, PL-SQL, T-SQL, LUA
Operating Systems
Windows 9X/XP/Vista/7, Server NT/2000/2003/2008, OSX, HPUX, Solaris, FreeBSD, Linux
Databases
Microsoft SQL Server 97/2003/2005/2008, Oracle 8/9/10i, MySQL, SQLite
Design
Adobe Photoshop, Adobe InDesign
Planning
Microsoft Project, Microsoft Visio
Methodology
Scrum, XP, GTD
Experience
2007 - Manifact AB Chief of Development/Software Engineer
As one-time part owner of Manifact AB I focused mostly on software engineering. Manifact's two main products are Pitstop, a software efficiency solution for factory maintenance and changeover, and Commander, which is an advanced workflow and ticket management system for the web.
http://www.manifact.com/
2005 - Lindex IT DBA/Project Manager
Along with a partner, I was responsible for implementation and maintenance of the central warehouse databases (Oracle) for all of Lindex. I was also a project manager for technical requirements of the e-commerce venture (rfp).
http://www.lindex.se/
2003 - Freelance Consulting
For two years I ran my own consulting company full-time and worked on a large variety of projects for various companies. These projects included design-work for an advertizing agency called Art Connection, an intranet and website for a newly-started company that rented movies on the internet, and later on in 2007, software development for another company that rents movies through vending machines.
http://www.artcon.se/
http://www.instantdvd.se/
2001 - Qondoc AB Software Developer
Qondoc develops software for IT-documentation. Among other duties, I was responsible for developing advanced software agents to automatically collect data in the networks.
http://www.qondoc.se/
1999 - Sigma eHandel AB Software Developer/Project Manager
During my time as a consultant for Sigma I helped start a large number of the leading e-commerce websites in Sweden. I was often the lead technician and was responsible for project guidelines.
http://www.sigma.se/
Websites included:
http://www.netonnet.se/
http://www.ginza.se/
http://www.ellos.se/
http://www.elektroskandia.se/
1997 - Alingsås Kommun ICT-Coordinator
After completing high school I started working for the local municipality. Responsibilities ranged from workstation installations to network installation, administration and more.
http://www.alingsas.se/
Personal Projects
Genie Client
Genie is an extremely advanced multi-threaded MUD text-based game client geared towards games developed by play.net. Among other advancements, Genie has its own script language, plugin interface and window skinning. I started this project in 2003 and everything is my own creation. It is an immensely popular client with a large user base.
http://www.genieclient.com/
Budvakt
This project launched in May of 2009. It is an auction sniper software for a Swedish website called Tradera.
http://www.budvakt.com/
Time Beacon
This software is my latest creation and has yet to be launched. It is an automatic time tracker, productivity monitor, and statistics engine. Its main purpose is to create accurate time sheets effortlessly.
http://www.timebeacon.com/
Simon Lau Centre Website
I created a quick design and CMS for the martial arts club where I train and teach.
http://www.simonlaucentre.org/
References
Available upon request.
Conny Wallström
Age: 31
Location: Gothenburg, Sweden
E-Mail: conny.wallstrom@gmail.com
Contact me on e-mail for additional contact details.
I am an experienced software developer that has worked professionally for 12 years. I am mostly self-educated, with computers and programming having been my main focus for as long as I can remember. I am an optimist and pride myself on finding solutions where others may only see problems. I am a fast learner, a team player and I love challenges and opportunities for personal and professional growth. Swedish is my native language but I speak and write English fluently.
Other interests include marial arts training and instruction, professional dj'ing, and fishing.
Areas of Expertise
Programming languages
C#, VB.NET, C, C++, Objective-C, JavaScript, ASP, ASP.NET, Perl, PHP, DHTML, PL-SQL, T-SQL, LUA
Operating Systems
Windows 9X/XP/Vista/7, Server NT/2000/2003/2008, OSX, HPUX, Solaris, FreeBSD, Linux
Databases
Microsoft SQL Server 97/2003/2005/2008, Oracle 8/9/10i, MySQL, SQLite
Design
Adobe Photoshop, Adobe InDesign
Planning
Microsoft Project, Microsoft Visio
Methodology
Scrum, XP, GTD
Experience
2007 - Manifact AB Chief of Development/Software Engineer
As one-time part owner of Manifact AB I focused mostly on software engineering. Manifact's two main products are Pitstop, a software efficiency solution for factory maintenance and changeover, and Commander, which is an advanced workflow and ticket management system for the web.
http://www.manifact.com/
2005 - Lindex IT DBA/Project Manager
Along with a partner, I was responsible for implementation and maintenance of the central warehouse databases (Oracle) for all of Lindex. I was also a project manager for technical requirements of the e-commerce venture (rfp).
http://www.lindex.se/
2003 - Freelance Consulting
For two years I ran my own consulting company full-time and worked on a large variety of projects for various companies. These projects included design-work for an advertizing agency called Art Connection, an intranet and website for a newly-started company that rented movies on the internet, and later on in 2007, software development for another company that rents movies through vending machines.
http://www.artcon.se/
http://www.instantdvd.se/
2001 - Qondoc AB Software Developer
Qondoc develops software for IT-documentation. Among other duties, I was responsible for developing advanced software agents to automatically collect data in the networks.
http://www.qondoc.se/
1999 - Sigma eHandel AB Software Developer/Project Manager
During my time as a consultant for Sigma I helped start a large number of the leading e-commerce websites in Sweden. I was often the lead technician and was responsible for project guidelines.
http://www.sigma.se/
Websites included:
http://www.netonnet.se/
http://www.ginza.se/
http://www.ellos.se/
http://www.elektroskandia.se/
1997 - Alingsås Kommun ICT-Coordinator
After completing high school I started working for the local municipality. Responsibilities ranged from workstation installations to network installation, administration and more.
http://www.alingsas.se/
Personal Projects
Genie Client
Genie is an extremely advanced multi-threaded MUD text-based game client geared towards games developed by play.net. Among other advancements, Genie has its own script language, plugin interface and window skinning. I started this project in 2003 and everything is my own creation. It is an immensely popular client with a large user base.
http://www.genieclient.com/
Budvakt
This project launched in May of 2009. It is an auction sniper software for a Swedish website called Tradera.
http://www.budvakt.com/
Time Beacon
This software is my latest creation and has yet to be launched. It is an automatic time tracker, productivity monitor, and statistics engine. Its main purpose is to create accurate time sheets effortlessly.
http://www.timebeacon.com/
Simon Lau Centre Website
I created a quick design and CMS for the martial arts club where I train and teach.
http://www.simonlaucentre.org/
References
Available upon request.
