Monthly Archives: January 2016

Position a form in the screen’s lower right corner in C#

The Screen.PrimaryScreen.WorkingArea property gives the size of the primary screen’s working area. (For more information, see Get the screen’s working area in C#). The following code subtracts the form’s width and height plus a margin from the working area’s Right … Continue reading

Posted in system | Tagged , , , , , , , , | 2 Comments

Draw rounded rectangles in C#

The GDI+ library provides lots of methods for drawing shapes such as rectangles, ellipses, lines, and arcs. Unfortunately it doesn’t provide a method for drawing rectangles with rounded corners. You can use a pen with LineJoin property set to Rounded … Continue reading

Posted in drawing, graphics | Tagged , , , , , , , , | 8 Comments

Get the screen’s working area in C#

The working area is the part of the screen that an application can normally occupy. This area may be in different parts of the screen depending on the task bar’s size and location. For example, if the task bar is … Continue reading

Posted in system | Tagged , , , , , , , , | 1 Comment

Clip a line segment to a polygon in C#

This example finds the pieces of a line segment that lie inside and outside of a polygon. It draws the parts of the segment that lie outside of the polygon with a pink background and it draws parts of the … Continue reading

Posted in algorithms, drawing, graphics, mathematics | Tagged , , , , , , , , , , , | Leave a comment

Display battery status in C#

Often I’ll be working on my laptop when it isn’t plugged in and suddenly I get a panicked message from Windows telling me that the battery is almost exhausted and if I don’t shut down immediately the world will explode. … Continue reading

Posted in system | Tagged , , , , , , , , | Leave a comment

Enlarge a polygon in C#

This example shows how you can enlarge a polygon by a certain distance. For example, you can use it to move the edges of the polygon outward by 10 pixels. The program lets you use the mouse to define the … Continue reading

Posted in algorithms, drawing, graphics, mathematics | Tagged , , , , , , , , , , , , , | 2 Comments

Print a calendar in C#

This example prints a calendar containing some text for each day. It’s mostly a matter of keeping track of where to draw things, but it also requires you to handle some confusing internationalization issues and there’s one potential gotcha. The … Continue reading

Posted in internationalization, system | Tagged , , , , , , , , , , , , , , | 2 Comments

Get the name of the first day of the week in C#

Different cultures start the week with a different first day of the week. For example, some cultures start the week with Monday and others start it with Sunday. Usually it doesn’t matter which day is the first day of the … Continue reading

Posted in internationalization, system | Tagged , , , , , , , , , , , , , | 2 Comments

Restart the print spooler in C#

Every now and then my computer gets confused and thinks the printer is offline. That wouldn’t be so bad except Windows doesn’t provide a simple way to bring the printer back online. Basically you need to shutdown and restart the … Continue reading

Posted in printing, system | Tagged , , , , , , , , , , | 7 Comments

Display the local time and GMT in C#

This example uses a Timer to execute the following code every half second. // Update the clocks. private void tmrClock_Tick(object sender, EventArgs e) { // Display the local time. DateTime now = DateTime.Now; lblLocalTime.Text = now.ToLongTimeString(); lblLocalDate.Text = now.ToShortDateString(); // … Continue reading

Posted in internationalization, system | Tagged , , , , , , , , , , , , , , | 1 Comment