Show options
The code determines how the dialog box will be loaded into memory and displayed. The following table describes the various types of display tasks and the keywords used to perform them.
The Show method loads the form and sets its Visible property to True. The parameters passed to the Show method identify the type of dialog box. If the style parameter is omitted or set to vbModeless or 0 (default), the dialog box is modeless. If the style parameter is vbModal or 1, the dialog box is modal.
When selecting "OK" or "Cancel" to exit the dialog box, you can use the Unload statement or the Hide method. For example:
UnloadfrmAbout
-or-
frmAbout.Hide
The Unload statement deletes the dialog box from memory, while the Hide method simply deletes it from the window by setting the dialog box's Visible property to False. When a form is unloaded, the form itself and its controls are unloaded from memory (including any controls that were loaded at run time). When a form is hidden, the form and its controls remain in memory. When you need to save memory space, it is best to unload the form because unloading the form frees up memory. If you use the dialog box frequently, you can choose to hide the form. Hiding a form can still retain any data associated with it, including property values, printout, and dynamically created controls. After the form is hidden, you can continue to reference the properties and controls of the hidden form from code.
Designs for various display types
Microsoft Windows is device independent - window-based applications can run on many computers with different display resolutions and color intensities. Likewise, applications written in Visual Basic will run on different types of monitors, and this needs to be taken into account when designing the application.
Design resolution-independent forms
By default, Microsoft Visual Basic does not change the size of forms and controls when changing screen resolutions. This means that a form designed on a screen with a resolution of 1024×768 will extend beyond the boundaries of the screen when run on a screen with a resolution of 640×480. If you want to create forms and controls that have the same proportions regardless of the screen resolution used, you must design the form at the lowest resolution or add code that changes the form to your program.
The easiest way to avoid size issues is to design your form at a resolution of 640×480. If you prefer to work at a higher resolution, you still need to consider how the form will appear at a lower resolution. The way to do this is to use the "FormLayout" window to preview the size and position of the form. You can also use "ResolutionGuides" to observe which parts of the screen are visible at low resolutions. To switch to "ResolutionGuides", you can right-click the mouse in the "FormLayout" window and select the "ResolutionGuides" menu item from the pop-up menu.
At run time, Visual Basic places the form based on its design-time position. If you design to run at a resolution of 1024×768 and place the form in the lower right corner of the screen, the form may not be visible when it is run at a lower resolution. In order to avoid this situation, you can select the "StartupPosition" menu item from the pop-up menu of the "FormLayout" window to set the start position of the form during design. Likewise, you can set the form's position at run time using the following code in the FormLoad event:
PRivateSubForm_Load()
Me.Move0,0
EndSub
Although setting both the Left and Top properties of the form to 0 can have the same effect, the Move method can be completed in one step.
Visual Basic uses a device-independent unit of measurement, the twip, which is the unit used to calculate size and position. The two properties of the Screen object, TwipsPerPixelX and TwipsPerPixelY, can be used to determine the display size at runtime. Using these properties, you can write code to adjust the size and position of forms and controls.
PrivateSubSetControls()
DimXAsInteger
DimYAsInteger
X=Screen.TwipsPerPixelX
Y=Screen.TwipsPerPixelY
SelectCaseX,Y
Case15,15
'Resize and move controls.
txtName.Height=200
txtName.Width=500
txtName.Move200,200
'Add code written for other resolutions.
…
EndSub
You also need to know the location of Visual Basic's own window at design time. If you move the Project window to the right side of the screen at a high resolution, you will find that it is no longer accessible when you open the project at a low resolution.
Design different concentrations of color
When designing an application, you also need to consider the possible color display capabilities of the computer running the application. Some computers can display 256 or more colors, while others can only display 16 colors. If you design a form using a 256-color palette, dithering (a method of simulating invalid colors) will cause some elements on the form to disappear when displayed on 16 colors.
To avoid this, it's best to limit the colors used by your application to the standard 16 colors of Windows. These colors are represented by Visual Basic color constants (such as vbBlack, vbBlue, vbCyan, etc.). If you need to use more than 16 colors in your application, you should still stick to standard colors for text, buttons, and other interface elements.
Design with the user in mind
Unless you create a Visual Basic application solely for your own use, the value of your creation can only be evaluated by others. The user interface of an application has a huge impact on users - no matter how technically brilliant the code is, or how well optimized it is, if users find the application difficult to use, then they will be less likely to accept it well.
As a programmer, there is no doubt that you are very familiar with computer technology. It's easy to forget that most users don't understand (and perhaps don't care about) the technology hiding behind the application. Think of an application as a tool for an end: a way to accomplish a task that is imaginatively easier than it would be without the computer's help.
A well-designed user interface isolates the user from the underlying technology, making it easy to complete intended tasks. When designing your application user interface, you need to keep the user in mind. How can you discover the application's various features without guidance? How does the application respond when an error occurs? What does it offer to help or assist the user? Does the design delight the user with an artistic beauty? The above The answers to these questions, as well as other issues related to user-centered design, are covered in this section.
Basics of interface design
You don’t have to be an artist to create user interfaces—most of the principles of user interface design are the same as those of basic design taught in any introductory art class. Basic design principles of composition, color, etc., apply just as well to a computer screen as they do to paper or painting.
Although Visual Basic makes it easy to create user interfaces by simply dragging and placing controls on a form, a little planning before designing can make a big difference in the usability of your application. You may want to start designing by drawing the form on paper, deciding which controls are needed, the relative importance of different elements, and the relationships between controls.
Composition: The look and feel of your application
The composition or layout of a form not only affects its aesthetics but also greatly affects the usability of the application. Composition includes factors such as the placement of controls, consistency of elements, movement, use of white space, and simplicity of design.
The location of the control
In most interface designs, not all elements are equally important. Careful design is necessary to ensure that the more important elements appear to the user quickly. Important or frequently accessed elements should be placed in a prominent position, while less important elements should be demoted to a less prominent position.
In most languages we are used to reading from left to right and top to bottom on a page. The same is true for computer screens. Most users' eyes will focus on the upper left part of the screen first, so the most important elements should be placed in the upper left part of the screen. For example, if the information on the form relates to a customer, its name field should appear where it will be seen first. Buttons, such as "OK" or "Next", should be placed in the lower right part of the screen; users usually will not access these buttons before completing operations on the form.
It's also important to group elements and controls. Try to group information logically by function or relationship. Because their functions are related to each other, the buttons for locating the database should be grouped visually rather than scattered throughout the form. The same is true for information. Name fields and addresses are usually grouped together because they are closely related. In many cases, you can use frame controls to help strengthen the connection between controls.
Consistency of interface elements
In user interface design, consistency is a virtue. A consistent look and feel creates harmony within an application, making everything look coordinated. If the interface lacks consistency, it is likely to cause confusion and make the application look very confusing, disorganized, less valuable, and may even raise doubts about the reliability of the application.
To maintain visual consistency, create a design strategy and type conventions before you start developing your application. Design elements such as control type, control size, grouping criteria, and font selection should all be determined in advance. Design templates can be created to assist with design.
There are a large number of controls available in Visual Basic, which may cause someone to want to use them all. To avoid this temptation, choose a subset of controls that are a good fit for your specific application. Although controls such as list boxes, combo boxes, grids, and trees can all be used to represent lists of information, it is best to use one type whenever possible.
Also, try to use controls appropriately. Although the TextBox control can be set to read-only and used to display text, the Label control is usually better suited for this purpose. Be consistent when setting properties for controls. If you use a white background for editable text in one place, don't use a gray background elsewhere unless you have a good reason.
Maintaining consistency between different forms in an application plays a very important role in its usability. If you use a gray background and three-dimensional effects on one form and a white background on another form, the two forms will appear unrelated. Pick a genre and keep it consistent throughout the application, even if it means redesigning some features.
Dynamic: the form matches its function
Movement is a visible clue to an object's functionality. While the term may not be familiar to you, examples of dynamism are everywhere. The handlebars on a bicycle, when you put your hands on them, the movement will reveal the fact that the handlebars are tightened with your hands. Pressing buttons, turning knobs, and turning on light switches can all be animated, and their purpose is obvious as soon as you see them.
The user interface also uses motion. For example, the three-dimensional effect used on command buttons makes them appear to be pressed. If you design a command button with a flat border, you will lose this dynamic feeling and therefore cannot clearly tell the user that it is a command button. In some cases, flat buttons may be appropriate, such as in gaming or multimedia applications; as long as they are consistent throughout the application, this is fine.
Text boxes also provide a sense of movement, and users can expect boxes with borders and a white background that contain editable text. It is also possible to display a text box without a border (BorderStyle=0), which makes it look like a label and does not obviously prompt the user that it is editable.
Use of white space
Using white space in user interfaces helps elements stand out and improve usability. White space doesn't have to be white—it's considered the empty space between and around the form's controls. Too many controls on a form can lead to a cluttered interface, making it difficult to find a field or control. White space needs to be inserted into a design to highlight design elements.
Consistent spacing between controls and alignment of vertical and horizontal elements also make the design more usable. Just like the text in a magazine, it is arranged in neat rows and rows with consistent spacing, and a neat interface will make it easy to read.
Visual Basic provides several tools that make it easy to adjust the spacing, arrangement, and size of controls. Commands such as Arrange, Make Same Size, Horizontal Spacing, Vertical Spacing, and Center in Window can all be found in the Format menu.
Keep the interface simple
Perhaps the most important principle of interface design is simplicity. For an application, if the interface looks difficult, the program itself may be difficult, too. A little deeper thought can help create interfaces that look (and are) simple to use. From an aesthetic perspective, a clean, simple design is often preferable.
A common mistake in interface design is to try to use the interface to imitate real-world objects. For example, imagine an application that requires the creation of a complete insurance policy. The natural reaction is to design an interface on the screen exactly like an insurance policy. There are several problems with doing this: the shape and size of the insurance policy is very different from what it looks like on the screen, and trying to replicate such a table perfectly would limit it to text boxes and checkboxes without really being useful to the user. benefits.
It would be better to design your own interface that also provides a printed copy of the original insurance policy (with print preview). By creating logical groups of fields from the original policy and using a tabbed interface or several linked forms, it is possible to display all the information without requiring scrolling. You can also use additional controls, such as a list box with preloaded selections, that can reduce typing effort.
You can also simplify many applications by taking out less commonly used functions and moving them into their own forms. Providing defaults can also sometimes simplify an application; if nine out of ten users select bold text, make the text bold as the default instead of asking users to select it each time (don't forget to provide an option This default can be overridden). Wizards also help simplify complex or infrequently used tasks.
The best test of simplification is to observe the application in action. If a representative user cannot immediately accomplish what they want without online help, then the design needs to be rethought.
Use color and images
Using color in an interface can increase visual appeal, but abuse often occurs. Many monitors are capable of displaying millions of colors, making it easy to use them all. Color, like other basic design principles, can present many problems if not carefully considered when starting a design.
Everyone's preference for color is very different, and users' tastes will also vary. Colors can trigger strong emotions, and if you are designing a program for a global audience, certain colors may be culturally significant. Generally speaking, it's best to stay traditional and use some muted, more neutral colors.
Of course, the intended reader and the tone and mood you are trying to convey will also influence your choice of color. Bright reds, greens and yellows work well in apps used by young children, but in a banking app it's less likely to bring financial responsibility.
A small amount of bright color can effectively highlight or draw attention to important areas. As a rule of thumb, try to limit the variety of colors used in your application, and the tone should be consistent. If possible, it's best to stick to a standard 16-color palette; when viewed on a 16-color monitor, dithering can prevent some other colors from showing up. Another issue to consider when working with color is color blindness. Some people cannot tell the difference between different combinations of primary colors (such as red and green). For people with this condition, red text on a green background becomes invisible.
Images and Icons
The use of images and icons can also add visual interest to an application, but careful design is also essential. Images can convey information visually without text, but often different people interpret images differently.
A toolbar with icons representing various functions is a useful interface device, but it can backfire if the function the icon represents cannot be easily identified. When designing toolbar icons, you should look at other applications to see what standards have been created. For example, many applications use a piece of paper with curled corners to represent the New File icon. There may be a better metaphor to represent this functionality, but using other representations would cause confusion among users.
It is also important to consider the cultural significance of the image. Many programs use a pastoral mailbox with a flag (Figure 6.21) to represent mail functionality. This is originally an icon for the United States; users in other countries or cultures may not recognize it as a mailbox.
When designing your own icons and images, try to keep them simple. Complex images with multiple colors do not fit well as 16×16 pixel toolbar icons or when displayed on high-resolution screens.
Select font
Fonts are also an important part of user interfaces because they often convey important information to users. Choose fonts that are easy to read on different resolutions and types of monitors. It’s best to stick to simple sans-serif or serif fonts whenever possible. Often handwritten or other decorative fonts look better in print than on a screen, and the smaller the font size, the harder it is to read.
Unless you plan to configure fonts per application, you should stick to standard Windows fonts such as Arial, NewTimesRoman, or System. If the user's system does not contain the specified font, the system will use an alternative font, and the results may be completely different than expected. If you are designing for an international audience, investigate what fonts are available in the intended languages. Also, when designing for other languages, you need to consider the expansion of text - in some languages, text strings can take up more than 50% more space.
Also, when choosing a font, consistency in design is very important. In most cases, you should not use more than two fonts in an application. Too many fonts can make an application look like a penalty ticket.
->