Exploring the GrabAPicture Application (Part 3)

In the previous post, Exploring the GrabAPicture Application (Part 2), you created frmMain, the first form that the user sees when using GrabAPicture in GUI mode. Someone wrote in to tell me that I forgot to include the form settings in the table. I looked back and found they’re correct, so here’s the settings you need for frmMain:

Control Property Value
Form1 (Name) frmMain
  AcceptButton bntOK
  CancelButton btnCancel
  FormBorderStyle FixedDialog
  Size 328, 269
  Text GrabAPicture

The form also sports an Icon property setting that I’ll discuss in a separate post for all three forms. Notice that the form uses the FixedDialog style, which is something you should consider for any form like this one that doesn’t include re-sizable elements. To make the form keyboard friendly, make sure you always include the AcceptButton and CancelButton settings so that the form reacts as expected when the user presses Enter or Escape.

On to the frmConfigure form. This form contains the list of local and remote settings. I had originally thought about creating just one list. However, there are times where a person works without an Internet connection or would prefer to use Internet sources for the desktop wallpaper than local sources. A local source is one that the user can access through a local drive or a network connection, while a remote source requires a URL for access. The URL can be anything that the .NET Framework can process, including the output from a Web service as long as that output is an image. You can’t use an entire Web page as a source because the Web page would contain non-graphic elements, but you can access a particular image on the Web page. Here’s how the form appears in the designer.

GrabAPicture0301

As you can see, there are separate sets of controls for local and remote sources. The following table tells how to configure these controls.

Control Property Value
Form2 (Name) frmConfigure
  CancelButton btnCancel
  FormBorderStyle FixedDialog
  ShownInTaskbar False
  Size 425, 301
  Text Configure a Random Source
Button1 (Name) btnCancel
  DialogResult Cancel
  Location 336, 8
  Modifiers Friend
  Size 75, 23
  TabIndex 0
  Text Cl&ose
Label1 (Name) lblLocal
  Location 8, 8
  Modifiers Friend
  Size 100, 23
  TabIndex 1
  Text Local So&urces:
ListBox1 (Name) lstLocal
  Location 8, 32
  Modifiers Friend
  Size 232, 95
  TabIndex 2
Button2 (Name) btnLAdd
  Location 240, 32
  Modifiers Friend
  Size 75, 23
  TabIndex 3
  Text &Add
Button3 (Name) btnLEdit
  Location 240, 56
  Modifiers Friend
  Size 75, 23
  TabIndex 4
  Text &Edit
Button4 (Name) btnLDelete
  Location 240, 80
  Modifiers Friend
  Size 75, 23
  TabIndex 5
  Text De&lete
Button5 (Name) btnLSelect
  Location 240, 104
  Modifiers Friend
  Size 75, 23
  TabIndex 6
  Text &Select
Label2 (Name) lblRemote
  Location 8, 144
  Modifiers Friend
  Size 100, 23
  TabIndex 7
  Text &Remote Sources
ListBox2 (Name) lstRemote
  Location 8, 160
  Modifiers Friend
  Size 232, 95
  TabIndex 8
Button6 (Name) btnRAdd
  Location 240, 160
  Modifiers Friend
  Size 75, 23
  TabIndex 9
  Text A&dd
Button7 (Name) btnREdit
  Location 240, 184
  Modifiers Friend
  Size 75, 23
  TabIndex 10
  Text Ed&it
Button8 (Name) btnRDelete
  Location 240, 208
  Modifiers Friend
  Size 75, 23
  TabIndex 11
  Text Dele&te
Button9 (Name) btnRSelect
  Location 240, 232
  Modifiers Friend
  Size 75, 23
  TabIndex 12
  Text Sele&ct

In this case, the form doesn’t include an AcceptButton entry because there isn’t any default accept action available. One alternative would be to make the AcceptButton entry the same as the CancelButton entry.

Notice that this form isn’t displayed in the Taskbar. The ShownInTaskbar setting is set to False. You only want to display the main form in the Taskbar to avoid confusing the user.

The third, and final form, is a multiuse form. The application uses frmAddEdit in four different ways, but could potentially use it in other ways:

 

  • Add a Local Entry
  • Edit a Local Entry
  • Add a Remote Entry
  • Edit a Remote Entry

There isn’t any way to predict which task the user will perform most often, so the form uses the Add a Local Entry task as the focus for the controls. The calling form, frmConfigure, will change the frmAddEdit as needed to meet a specific need. The basic form looks like this.

GrabAPicture0302

This form has a few extras on it that you’ll learn more about when you write the code. For example, the ellipses (…) button only appears for local resources. It works with an OpenFileDialog control that isn’t shown on the form to help a user find a local resource on a local drive or the network. The following table contains the settings for this form.

Control Property Value
Form3 (Name) frmAddEdit
  AcceptButton btnAddEdit
  CancelButton btnCancel
  FormBorderStyle FixedDialog
  ShownInTaskbar False
  Size 300, 266
  Text Add Local Resource
Button1 (Name) btnAddEdit
  DialogResult OK
  Location 208, 8
  Modifiers Friend
  Size 75, 23
  TabIndex 0
  Text &Add
Button2 (Name) btnCancel
  DialogResult Cancel
  Location 208, 40
  Modifiers Friend
  Size 75, 23
  TabIndex 1
  Text &Cancel
Label1 (Name) lblName
  Location 8, 8
  Modifiers Friend
  Size 100, 23
  TabIndex 2
  Text &Name
TextBox1 (Name) txtName
  Location 8, 32
  Modifiers Friend
  Size 184, 20
  TabIndex 3
Label2 (Name) lblLocation
  Location 8, 64
  Modifiers Friend
  Size 100, 23
  TabIndex 4
  Text &Location
TextBox2 (Name) txtLocation
  Location 8, 88
  Modifiers Friend
  Size 160, 20
  TabIndex 5
Button3 (Name) btnGetResource
  Location 168, 88
  Modifiers Friend
  Size 24, 23
  TabIndex 6
  Text
GroupBox1 (Name) grpStyleSelect
  Location 8, 128
  Modifiers Friend
  Size 192, 100
  TabIndex 7
  Text Style Selection
RadioButton1 (Name) rbStretched
  Checked True
  Location 16, 24
  Modifiers Friend
  Size 104, 24
  TabIndex 0
  TabStop True
  Text &Stretched
RadioButton2 (Name) rbCentered
  Location 16, 48
  Modifiers Friend
  Size 104, 24
  TabIndex 1
  TabStop True
  Text &Centered
RadioButton3 (Name) rbTiled
  Location 16, 72
  Modifiers Friend
  Size 104, 24
  TabIndex 2
  TabStop True
  Text &Tiled
OpenFileDialog1 (Name) OFD
  Filter BMP Files|*.BMP|JPG Files|*.JPG|GIF Files|*.GIF|PNG Files|*.PNG|All Graphics Files|*.BMP;*.JPG;*.GIF;*.PNG
  Modifiers Friend

Notice that this form can have an AcceptButton and a CancelButton setting because there are default actions for both. As with frmConfigure, frmAddEdit doesn’t appear in the Taskbar.

Some people are thrown by the use of the GroupBox control in this part of the example. The Location property is relative to the location within the GroupBox when working with the three RadioButton controls. Likewise, the TabIndex is local to the GroupBox, so the numbering starts over with 0. There are several ways to determine whether the RadioButton is a tab stop. You can choose to set the GroupBox as the tab stop, the default RadioButton as the tab stop, or all of the RadioButton controls as potential tab stops. This example takes the last action, but you should try all three forms to see what you like best. The GroupBox also lacks a hot key because you’ll never select it directly—the focus is on the controls within the GroupBox, so that’s where the hot keys are.

The next installment will begin by discussing the icon used for this example. It’s nothing fancy, but there are some tricks you need to know about when working with icons. Let me know if you have any questions at John@JohnMuellerBooks.com. You can see the next post in this series at Exploring the GrabAPicture Application (Part 4).