Category: Winforms


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

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

Check your InitializeComponent method

September 29th, 2007 — 02:13 pm
I previously wrote about a problem with a custom form’s property.
Since then I found problems with additional properties, including the form’s default location.
As it turns out the cause was a missing call to the InitializeComponent method in the initializer of a parent class.

1 comment » | Winforms

Beware of the AutoScaleBaseSize property

September 13th, 2007 — 10:58 am

I have had a problem recently with some of the form in my application, which were descendants of a custom form class (not the classic Windows.Forms.Form class).
The form would look fine in design mode, but during run time it appeared to have shrunk, with all the controls in it being affected similarly.

It took a lot of digging to find out what was wrong, but after noticing that setting the AutoScale property to “false” seemed to solve the problem the culprit was found - While in a “normal” form the “initializecomponents” method contained this line:
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
In the new forms it has somehow changed to:
this.AutoScaleBaseSize = new System.Drawing.Size(7, 17);
Thus affecting all such forms.

Now I need to fix this line, but I’m still troubled by not knowing what caused it to change in the first place….

Comment » | Winforms

Page faults using GDI+

August 25th, 2007 — 11:02 am

I’m working on a C4I application using GIS maps.
The map is refreshed (redrawn) by calling the Control.Invalidate() method.
What got my attention was seeing few thousands of page faults on each refresh, resulting in CPU usage of 3-6%.

After some research, this is the response I got from Hans Passant in the MSDN forums:
GDI+ bitmaps use memory mapped files. The bitmap data gets loaded into memory through page faults.

Now if I only could figure out why in older versions of the application there were no page faults, especially if he is right and this is the normal mode of operation.

Comment » | Winforms

     Next Entries »