Monthly Archives: May 2016

Define and implement an interface in C#

(This example doesn’t do anything. It just shows how to define an interface.) An interface defines properties, methods, and events for a class but doesn’t provide an implementation for them. A class that implements the interface must provide code for … Continue reading

Posted in interfaces, OOP | Tagged , , , , , , , , , | Leave a comment

Display Google Maps for the computer’s location in C#

This example combines the techniques of the following two posts to display the computer’s current location in Google Maps: Use the Location API to find the computer’s latitude and longitude in C# Display Google maps for an address inside a … Continue reading

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

Use the Location API to find the computer’s latitude and longitude in C#

Before you try this, note the following caveats: This only works in .NET Framework 4.0 or later and Windows 7 or later. The operating system can grant or deny access to location information for a program. If the application is … Continue reading

Posted in internet, miscellany, system | Tagged , , , , , , , , , , , , , | 11 Comments

Display Google Maps for an address inside a form in C#

This was a lot easier until changes to Google Maps and the WebBrowser control added some rather annoying complications. The idea is simple. You use the techniques described in Display Google Maps for an address in C# to get a … Continue reading

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

Display Google Maps for an address in C#

This example shows how to make Google Maps look up an address and display a map in the system’s default browser. A Google Maps URL can use the following format. http://maps.google.com/maps?q=QUERY&t=TYPE&z=ZOOM Where: QUERY is the query. If it begins with … Continue reading

Posted in graphics, internet, system | Tagged , , , , , , , , , , , , , | 3 Comments

List birthdays in C#

Adding values to dates is kind of tricky. For example, you cannot simply add 365 days to a date to get the same date next year because not all years have 365 days. When you enter a date and click … Continue reading

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

Use file dialog filters in C#

The OpenFileDialog and SaveFileDialog components have a Filter property that lets the user look for specific kinds of files. The property’s value should be a pipe symbol (|) separated list of alternating filter names and patterns. Each pattern can include … Continue reading

Posted in dialogs, files | Tagged , , , , , , , , , , , , | Leave a comment

Override a parent class method in C#

One of the coolest features of object-oriented programming is virtual methods. If a parent class declares a method as virtual, a child class can provide a new implementation for the method. When the program calls the method for a child … Continue reading

Posted in classes, OOP | Tagged , , , , , , , , , , , , | 1 Comment

Make an initializing constructor for a child class in C#

An initializing constructor is a constructor that takes parameters to make it easy to initialize an object’s properties. This example shows how to reuse a class’s initializing constructor for a child class. The following Person class has an initializing constructor. … Continue reading

Posted in classes, OOP | Tagged , , , , , , , , , , , , , , | Leave a comment

Set the MessageBox default button in C#

The fifth parameter to MessageBox.Show indicates the default button. The following code shows how the program displays a MessageBox with the second button as the default so it is initially selected when the message box appears. // Display a message … Continue reading

Posted in dialogs, MessageBox | Tagged , , , , , , , , , | 2 Comments