Archive for October 2007


Drawing rounded rectangles

October 31st, 2007 — 02:19 pm

I needed rounded-corners panels for the application I’m working on.

Some search showed there is no built-in solution, and the way to go is using GDI+, and drawing the control’s border manually, meaning you need to draw 4 arcs and 4 lines:


GraphicsPath gp=new GraphicsPath();

gp.AddLine(X + radius, Y, X + width - (radius*2), Y);

gp.AddArc(X + width - (radius*2), Y, radius*2, radius*2, 270, 90);

gp.AddLine(X + width, Y + radius, X + width, Y + height - (radius*2));

gp.AddArc(X + width - (radius*2), Y + height - (radius*2), radius*2, radius*2,0,90);

gp.AddLine(X + width - (radius*2), Y + height, X + radius, Y + height);

gp.AddArc(X, Y + height - (radius*2), radius*2, radius*2, 90, 90);

gp.AddLine(X, Y + height - (radius*2), X, Y + radius);

gp.AddArc(X, Y, radius*2, radius*2, 180, 90);

You can find the raw code in Bob Powell’s GDI+ FAQ site, and a set of rounded controls, including panels, in an article by Hesham Desouky in CodeProject.

Comment » | Winforms

Setting image transparency

October 26th, 2007 — 11:36 am

There are many cases in which you need to embed an image in a winform control (such as a button), and usually you’ll need the image to have a transparent background.
Someone showed me recently an easy way to do this:

1) Set the area surrounding the image to a uniform color which is different from the image’s colors.

2) Open Powerpoint, and add the picture to the presentation:

3) Show the image editing toolbar and choose the transparancy tool.

4) Click on the background.

Comment » | Tools

Blondes have more WCF

October 21st, 2007 — 03:07 pm


I went to a “Fundamentals of WCF Security” lecture by Michele Leroux Bustamante (dasBlonde) from IDesign, which came after a full day seminar given by her at Microsoft Israel.

Michele is an IDesign Chief Architect, Microsoft Regional Director for San Diego, Microsoft MVP for Connected Systems and hold a long list of additional titles. She specializes in training, mentoring and high-end architecture consulting services focusing on scalable and secure architecture design for .NET, federated security scenarios, web services, interoperability and globalization architecture.

The event was a joint venture of 3 user groups, and attracted many participants - so many the organizers had actually to dismantle the wall separating two lecture halls and merge them into one.

The event started a bit late due to traffic, and than about an hour of WCF fundamentals due to request from half of the audience. Personally I think it was unnecessary, since I suspect this intro was too complex (too fast compared to the normal “ABC” approach) for people with no WCF knowledge, and boring for those with prior knowledge.

The main part involved covering security principles, different approaches and the cost for each of them, and many hands-on samples, and was much more interesting. It was also followed by a short Q&A session, but the audience was exhausted at this point (unlike the speaker - incredible energy), so not many questions were asked.

I recommend listening to her 15-parts webcast series, and you can find the code/slides from the lecture here.

My favourite quote: “I don’t blog very often, I’m not Scott Hanselman“.

Comment » | Events, WCF

Reduce your workplace electric consumption

October 17th, 2007 — 08:37 am

Blog action day got me thinking about saving energy.
I already wrote about how I try to reduce my effect on the environment at home, but what about work?
  • Do you turn off the lights in your office when you leave?
  • Do you turn off air condition?
  • What about your computer?

Each of these actions can save money over time, but more important - reduce the pollution caused by power plants.

A study done in 2002 in the U.S. showed that applying “green” technologies to the workplace can save up to 40 terawatt-hours.
Another thing to avoid is setting the air condition to a constant temperature mode instead of heating/cooling - it means the system never stops working.

So turn off the lights and the air condition when you leave work, it’s easy.

Comment » | Environment

Deadlock from hell

October 17th, 2007 — 08:15 am

Thread 1:
lock (a)
{

lock (b)
{
lock (c)
{
//some code
}

}

}

Thread 2:
lock (d)
{

lock (c)
{
lock (b)
{
//some code
}

}

}

Main thread:
lock (a)
{
//important code
}

Comment » | Uncategorized

Every n matters

October 13th, 2007 — 01:58 pm

When you study computer science and you start learning algorithms, you are introduces to the O(n) concept, meaning there is a different between an algorithm that takes linear time (1 second for 1000 items, 2 seconds for 2000 items and so on) and an algorithm that takes exponential (2 to the power of n) time, meaning it’s a very inefficient algorithm.

Although this lesson is important, there is a darker side to this kind of thinking - you tend to ignore efficiencies with the same order of magnitude, meaning an algorithm with 10n efficiency and 80n efficiency are the same to you, even the first is 8 time faster than the second. This means that if you choose the first a certain procedure may cause the user to wait 250 milliseconds, while the second will delay the user for 2 whole seconds - big difference.

So don’t consider to n values to be similar just because they are within the same order of magnitude.

Comment » | Programming

Changing ComboBox height in Syncfusion control

October 11th, 2007 — 02:51 am

I am using a ComboBoxAdv control from Syncfusion, and in version 3.2 I have noticed that the control doesn’t allow you to change the height beyond a minimum value (depending on the font).

There is a PreventHeightChange property, but it doesn’t seem to work.

The solution - override the DetermineHeightsBasedOnFont method with a blank method.

Comment » | Winforms

« Previous Entries