Lesson 1 Adding and Configuring Windows Forms

This lesson describes how to create and configure Windows Forms. You will learn how to create forms and refer to them in code, alter the visual properties of the form, and control the behavior of the form at run time.

After this lesson, you will be able to:

■ Add a Windows Form to a project at design time.

■ Resize a window at design time or run time.

■ Identify and set the properties that determine a form's appearance and behavior at run time.

■ Refer to the default instance of a form in code.

■ Create a non-rectangular form. Estimated lesson time: 45 minutes

Overview of Windows Forms

Windows Forms are the basic building block of the user interface. They provide a container that hosts controls and menus and allow you to present an application in a familiar and consistent fashion. Forms can receive user input in the form of keystrokes or mouse interactions and can display data to the user through hosted controls. Although it is possible to create applications that do not contain forms, such as console applications or services, most applications that require sustained user interaction will include at least one Windows Form, and complex applications frequently require several forms to allow the program to execute in a consistent and logical fashion.

When you create a new Windows Forms project, a form named Form1 is added to your project by default. You can edit your form by adding controls and other visual elements in the designer, which is a graphic representation of a designable, visual element (such as a Form) that appears in the Visual Studio Integrated Development Environment (IDE). The Visual Studio IDE is shown in Figure 1-1.

WindowsApplicationl - Microsoft Visual Studio

I File Edit View Project Build Debug

Data Tools Window Community Help

* ^ -

-Mm ^ 3 ^

: ft £ =¡1 1 ~ «Q. Ji

ËL-

Toolbox ▼ fll X

Forml.vb [Design] Start Page Object Browser

X

Solution Explorer t ? X

B All Windows Forms

r a a a 3 Si

Pointer jSp BackgroundWorker ifpl BindingNavigator

H Forml ^nr^im

l(Jp WindowsApplicationl

Eäl My Project ps| Forml.vb

BindingSource

@ Button

0 CheckBox

13 CheckedListBox

[fr] ColorDialog

I&H ComboBox

® ContextMenuStrip

jD DataGridView

12] DataSet

^ DateTimePicker

P51 DirectoryEntry

i^l DirectorySearcher

H DomainUpDown

ErrorProvider

|5| EventLog

^•Toolbox |^Server,,, | [J Docume...

Error List

^ ? X

110 0 Errors | 0 Warnings | .j) 0 Messages

Description

File

Line Column Project

jff Properties Solution Explorer |

Figure 1-1 A Windows Form in the Visual Studio IDE

Figure 1-1 A Windows Form in the Visual Studio IDE

Adding Forms to Your Project

Most projects will require more than one form. You can add and configure additional forms at design time, or you can create instances of pre-designed forms in code at run time.

► To add a new form to your project at design time

1. From the Project menu, select Add Windows Form. The Add New Item dialog box opens.

2. Select Windows Form and type a name for the new form in the Name box. Click Add to add the form to the development environment.

You can add and configure as many forms as your application needs at design time. You can also create new instances of forms in your code. This method is most often employed when you want to display a form that has already been designed. In Visual Basic, you can access default instances of a form by referring to that form by name. For example, if you have a form named Form1 in your application, you can refer to it directly by its name, Form1.

► To access the default instance of a form at run time (Visual Basic only)

1. Refer to the form by its name. You can call methods or access properties from this default instance. For example:

Forml.Text = "This is my form" Form1.Show()

2. If referring to a form from within that form's code, you cannot use the default instance. You must use the special keyword Me (Visual Basic) or this (C#) to access the form's properties and methods.

► To access a form's methods and properties from inside its code

1. Use the keyword Me (Visual Basic) or this( C#). For example:

Me.Text = "J and J's Wine Shop - Main Page" // C#

this.Text = "J and J's Wine Shop - Main Page";

2. You can also create new instances of forms at run time by declaring a variable that represents a type of form and creating an instance of that form.

► To add a form to your application at run time

1. Declare and instantiate a variable that represents your form. This example assumes that you have already designed a form named Form1 in your project:

Dim myForm As Forml myForm = New Form1() ' Displays the new form myForm.Show()

Forml myForm; myForm = new Form1(); // Displays the new form myForm.Show();

Properties of Windows Forms

The visual appearance of your user interface is an important part of your application. A user interface that is poorly designed is difficult to learn and will, therefore, increase training time and expense. You can modify the appearance of your user interface by using Windows Forms properties.

Windows Forms contain a variety of properties that allow you to customize the look and feel of the form. You can view and change these properties in the Properties window of the designer, as shown in Figure 1-2.

Properties

B

Forml System,Windows.Forms,Form

-

:: mm-' 1

HI (ApplicationSettings)

*

S (DataBindings)

(Name)

Forml

AcceptButton

(none)

AccessibleDescription

AceessibleName

AccessibleRole

Default

AllowDrop

False

AutoScaleMode

Font

AutoScroll

False

EE AutoScrollMargin

Oj 0

13 AutoScrollMinSize

Oj 0

AutoSize

False

AutoSizeMode

GrowOnly

AutoValidate

EnablePreventFocusChange

BackColor

I | Control

Backgroundlmage

O

BackgroundïmageLayout

Tile

CancelButton

(none)

CausesValidation

True

ContextMenu5trip

(none)

ControlBox

IT,

1 1

1 "¡^Properties ^Solution Explorer

Figure 1-2 The Properties window

Figure 1-2 The Properties window

Table 1-1 summarizes some of the Windows Forms properties that are important in the look and feel of the application. Note that this is not an exhaustive list of all Windows Forms properties but, rather, a selected subset.

Table 1-1 Some Properties of the Form Class

Property

Description

(Name)

Sets the name of the Form class shown in the designer. This property can be set only at design time.

Backcolor

Indicates the background color of the form.

BackgroundImage

Indicates the background image of the form.

BackgroundImageLayout

Determines how the image indicated by the Background-Image property will be laid out on the form. If no background image is selected, this property has no effect.

ControlBox Determines whether the form has a Control/System menu box.

Table 1-1 Some Properties of the Form Class

Property

Description

Cursor

Indicates the cursor that appears when the cursor is moved over the form.

Enabled

Determines whether the form is able to receive user input. If Enabled is set to False, all controls contained by the form are likewise disabled.

Font

Sets the default font for the form. All controls contained by the form will also adopt this font unless their Font property is set separately.

ForeColor

Indicates the forecolor of the form, which is the color used to display text. All controls contained by the form will also adopt this forecolor unless their forecolor property is set separately.

FormBorderStyle

Indicates the appearance and behavior of the form border and title bar.

HelpButton

Indicates whether the form has a Help button.

Icon

Indicates the icon that is used to represent this form.

Location

When the StartPosition property is set to Manual, this property indicates the starting location of the form relative to the upper left-hand corner of the screen.

MaximizeBox

Indicates whether the form has a MaximizeBox.

MaximumSize

Determines the maximum size for the form. If this property is set to a size of (0,0) the form has no upper size limit.

MinimizeBox

Indicates whether the form has a MinimizeBox.

MinimumSize

Determines the minimum size to which the user can resize the form.

Table 1-1 Some Properties of the Form Class

Property

Description

Opacity

Represents the opacity, or conversely the transparency of the form from 0% to 100%. A form with 100% opacity is completely opaque, and a form with 0% opacity is completely transparent.

Size

Gets and sets the initial size of the form.

StartPosition

Indicates the position of the form when the form is first displayed.

Text

Determines the text caption of the form.

TopMost

Indicates whether the form always appears above all other forms that do not have this property set to True.

Visible

Determines whether the form is visible when running.

WindowState

Determines whether the form is minimized, maximized, or set to the size indicated by the Size property when first shown.

Modifying the Look and Feel of the Form

You can use the Property Grid to set properties of the form at design time. Properties set in this manner will retain their values until the application starts, at which time they can be set in code.

Most properties of a form can also be set at run time. The generalized scheme for setting a simple property is to use the assignment operator (=) to assign a value to a property. The following example demonstrates how to set the Text property of a form.

Forml.Text = "This is Form 1";

Some properties, such as the Font or Size properties, are more complex. Their value is represented by an instance of a class or structure. For these properties, you can either set the property to an existing instance of the class, or create a new instance that speci fies any subvalues of the property and assign it to the property as shown in the following pseudocode example:

PropertyY = New Class(value,value) // C#

PropertyY = new Class(value,value);

The (Name) property, which represents the name of the Form class, is an exception. This property is used within the namespace to uniquely identify the class that the Form is an instance of and, in the case of Visual Basic, is used to access the default instance of the form.

Setting the Title of the Form

The name of the form is the name that is used to refer to the Form class or the default instance of a form (Visual Basic only) in code, but it is also useful for the form to have a title that is visible to users. This title might be the same as the name of the form but is more often a description of the form itself, such as Data Entry. The title can also be used to convey information to the user, such as "Processing Entries — My Application" or "Customer Entry — My Application". The title appears in the title bar and on the taskbar.

You can change the title of a form by changing the Text property. To change the title of a form at design time, set the Text property of the form in the Property Grid. To change the title of a form at run time, set the Text property of the form in code, as shown in the following code:

Form1.Text = "Please enter your address" // C#

Form1.Text = "Please enter your address";

Setting the Border Style of the Form

The border style of a form determines how the border of the form looks and, to a certain extent, how a form behaves at run time. Depending on the setting, the FormBorderStyle property can control how the border appears, whether a form is resizable by the user at run time, and whether various control boxes appear (although these are also determined by other form properties). The FormBorderStyle property has seven possible values, which are explained in Table 1-2.

Table 1-2 Values for the FormBorderStyle Property

Value

Description

None

The form has no border and has no minimize, maximize, help, or control boxes.

FixedSingle

The form has a single border and cannot be resized by the user. It can have a minimize, maximize, help, or control box as determined by other properties.

Fixed3D

The form's border has a three-dimensional appearance and cannot be resized by the user. It can have a minimize, maximize, help, or control box as determined by other properties.

FixedDialog

The form has a single border and cannot be resized by the user. Additionally, it has no control box. It can have a minimize, maximize, or help box as determined by other properties.

Sizable

This is the default setting for a form. It is resizable by the user and can contain a minimize, maximize, or help box as determined by other properties.

FixedToolWindow

The form has a single border and cannot be resized by the user. The window contains no boxes except the close box.

SizableToolWindow

The form has a single border and is resizable by the user. The window contains no boxes except the close box.

The FormBorderStyle property can be set at either design time or run time. To change the border style of a form at design time, set the FormBorderStyle property in the Property Grid. To change the border style of a form at run time, set the FormBorderStyle property in code as shown in the following example:

aForm.FormBorderStyle = FormBorderSty1e.Fixed3D // C#

aForm.FormBorderStyle = FormBorderSty1e.Fixed3D;

Setting the Startup State of the Form

The WindowState property determines what state the form is in when it first opens. The WindowState property has three possible values: Normal, Minimized, and Maximized. The default setting is Normal. When the WindowState property is set to Normal, the form will start at the size determined by the Size property. When the WindowState property is set to Minimized, the form will start up minimized in the taskbar. When the WindowState property is set to Maximized, the form will start up maximized. Although this property can be set at run time, doing so will have no effect on the state of the form. Thus, it is useful to set this property in the Property Grid only at design time.

Resizing the Form

When the WindowState property is set to Normal, it will start at the size determined by the Size property. The Size property is actually an instance of the Size structure which has two members, Width and Height. You can resize the form by setting the Size property in the Property Grid, or you can set the Width and Height separately by expanding the Size property and setting the values for the individual fields.

You can also resize the form by grabbing and dragging the lower right-hand corner, the lower edge, or the right-hand edge of the form in the designer. As the form is visibly resized in the designer, the Size property is automatically set to the new size.

The form can be resized at run time by setting the Size property in code. The Width and Height fields of the Size property are also exposed as properties of the form itself. You can set either the individual Width and Height properties or the Size property to a new instance of the Size structure as shown in the following example:

' Set the Width and Height separately aForm.Width = 300 aForm.Height = 200

' Set the Size property to a new instance of the Size structure aForm.Size = New Size(300,200)

// Set the Width and Height separately aForm.Width = 300; aForm.Height = 200;

// Set the Size property to a new instance of the Size structure aForm.Size = new Size(300,200);

Note that if the form's StartPosition property is set to WindowsDefaultBounds, the size will be set to the window's default rather than to the size indicated by the Size property.

Specifying the Startup Location of the Form

The startup location of the form is determined by a combination of two properties. The first property is the StartPosition property, which determines where in the screen the form will be when first started. The StartPosition property can be set to any of the values contained within the FormStartPosition enumeration. The FormStartPosition enumeration values are listed in Table 1-3.

Table 1-3 StartPosition Property Settings

Value

Description

Manual

The starting location of the form is set by the form's Location property. (See the following options.)

CenterScreen

The form starts up in the center of the screen.

WindowsDefaultLocation

The form is positioned at the Windows default location and set to the size determined by the Size property.

WindowsDefaultBounds

The form is positioned at the Windows default location and the size is determined by the Windows default size.

CenterParent

The form's starting position is set to the center of the parent form.

If the StartPosition property is set to manual, the form's starting position is set to the location specified by the form's Location property, which is dictated by the location of the form's upper left-hand corner. For example, to start the form in the upper left-hand corner of the screen, set the StartLocation property to Manual and the Location property to (0,0). To start the form 400 pixels to the right and 200 pixels below the upper-left hand corner of the screen, set the Location property to (400,200).

Keeping a Form on Top of the User Interface

At times, you might want to designate a form to stay on top of other forms in the user interface. For example, you might design a form that presented important information about the program's execution that you always want the user to be able to see. You can set a form to always be on top of the user interface by setting the TopMost property to True. When the TopMost property is True, the form will always appear in front of any forms that have the TopMost property set to False, which is the default setting. Note that if you have more than one form with the TopMost property set to True, they can cover up each other.

Opacity and Transparency in Forms

You can use the Opacity property to create striking visual effects in your form. The Opacity property sets the transparency of the form. When set in the Property Grid, the opacity value can range from 0% to 100%, indicating the degree of opacity. An opacity of 100% indicates a form that is completely opaque (solid and visible), and a value of 0% indicates a form that is completely transparent. Values between 0% and 100% result in a partially transparent form.

You can also set the Opacity property in code. When the Opacity property is set in code, it is set to a value between 0 and 1, with 0 representing complete transparency and 1 representing complete opacity. The following example demonstrates how to set a form's opacity to 50%:

aForm.Opacity = 0.5;

The Opacity property can be useful when it is necessary to keep one form in the foreground but monitor action in a background form or create interesting visual effects. In most cases, a control inherits the opacity of the form that hosts it.

Setting the Startup Form

If your Windows Forms application contains multiple forms, you must designate one as the startup form. The startup form is the first form to be loaded on execution of your application. The method for setting the startup form depends on whether you are programming in Visual Basic or C#.

In Visual Basic, you can designate a form as the startup form by setting the Startup Form project property, which is done in the project Properties window, as shown in Figure 1-3:

Basic Setting Form
Figure 1-3 The Visual Basic project Properties window

► To set the Startup form in Visual Basic

1. In Solution Explorer, click the name of your project. The project name is highlighted.

2. In the Project menu, choose applicationName Properties, where applicationName represents the name of your project.

3. On the Application tab, under Startup form, choose the appropriate form from the drop-down menu.

Setting the startup form in C# is slightly more complicated. The startup object is specified in the Main method. By default, this method is located in a class called Program.cs, which is automatically created by Visual Studio. The Program.cs class contains, by default, a Main method, as follows:

static void Main() {

Appl ication. EnableVi sualStyles();

Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1());

The startup object is indicated by the line

Application.Run(new Form1());

You can set the startup form for the project by changing this line in the Program.cs class to the form that you want to start the application. For example, if you wanted a form called myForm to be the startup form, you would change this line to read as follows:

App1ication.Run(new myForm()); ► To set the Startup form in C#

1. In Solution Explorer, double-click Program.cs to view the code. The code window opens.

2. Locate the Main method, and then locate the line that reads:

App1ication.Run(new Form());

where Form represents the name of the form that is currently the startup form.

3. Change Form to the name of the form you want to set as the startup form.

Making the Startup Form Invisible

At times you might want the startup form to be invisible at run time. For example, you might want a form to execute a time-consuming process when starting and not appear until that process is complete. The Visible property determines whether a form is visible at run time. You can set the Visible property either in the Property Grid or in code. If you set Visible to False in the property window, the form will be invisible at startup.

To make a form invisible during execution, set the Visible property to False in code, as shown in the following example:

aForm.Visible = false;

Quick Check

1. How can you specify the Startup Location of a Form?

2. How do you set the Startup Form? Quick Check Answers

1. Use the Form.StartPosition to indicate the starting position of a Form.

2. In Visual Basic, you can set the Startup form by setting the value in the Application tab of the project properties. In C# you must locate the Appli-cation.Run method and change the startup form there.

Creating Non-Rectangular Windows Forms

For advanced visual effects, you might want to create forms that are non-rectangular. For example, you might want to create an oval form or a form in the shape of your company's logo. Although creating a non-rectangular form is easy, there are several considerations for the final look and feel of the form.

You can create a non-rectangular form by setting the Region property of the form in the Form_Load event handler. Because the change in shape of the form actually occurs at run time, you are unable to view the form in its actual shape at design time. Thus, you might have to start the application and view the form several times as you fine-tune the appearance and placement of controls.

The Region property is an instance of System.Drawing.Region. This class represents an area of the screen that is the interior of a graphics shape defined by rectangles and graphics paths. The easiest way to create a non-rectagular region is to create a new instance of the GraphicsPath class, and then create the new Region from it. The following code demonstrates a simple example.

Dim myPath As New System.Drawing.Drawing2D.GraphicsPath

' This line of code adds an ellipse to the graphics path that inscribes the

' rectangle defined by the form's width and height myPath.AddEl1ipse(0, 0, Me.Width, Me.Height)

' Creates a new Region from the GraphicsPath

Dim myRegion As New Region(myPath)

' Sets the form's Region property to the new region

Me.Region = myRegion

System.Drawing.Drawing2D.GraphicsPath myPath = new System.Drawing.Drawing2D.GraphicsPath();

// This line of code adds an ellipse to the graphics path that inscribes

// the rectangle defined by the form's width and height myPath.AddEl1ipse(0, 0, this.Width, this.Height);

// Creates a new Region from the GraphicsPath

Region myRegion = new Region(myPath);

// Sets the form's Region property to the new region this.Region = myRegion;

The System.Drawing and System.Drawing.Drawing2D classes will be discussed in further detail in Chapter 14, "Creating Windows Forms Controls."

Because non-rectagular forms will have limited borders (if any), it is generally a good idea to set the FormBorderStyle property of the form to None. This prevents any parts of the form that intersect the original rectangle edges of the form from having a different and unwanted appearance. However, with the FormBorderStyle property set to

None, there will be no way for the user to resize, move, or close the form, and you must build these features into your design. A simple non-rectangular form is shown in Figure 1-4.

Figure 1-4 An elliptical form with a Close Form button

► To create a non-rectangular form

1. In the Property Grid, set the FormBorderStyle to None.

2. Double-click the form in the designer to open the default Form_Load event handler.

3. In the Form_Load event handler, create a new instance of the Region class as shown in the previous example.

4. If desired, add close, move, or resize functionality to the form because the user might not be able to access the form's borders or title bar.

5. Set the form as the startup form and press F5 to view the form. Fine-tune the appearance and placement of controls as necessary.

Lab: Customizing a Windows Form

In this lab, you will practice customizing a Windows Form by applying techniques that you learned in the preceding lesson. In Exercise 1, you will create a Windows Form and customize the appearance by setting properties and writing code. In Exercise 2, you will create a form with a non-rectangular shape. This lab guides you through the steps involved. If you prefer to do an unguided lab, please see the "Case Scenarios" section at the end of this chapter.

► Exercise 1: Customize a Rectangular Windows Form

1. Open Visual Studio 2005 and create a new Windows Forms project. The project opens with a default form named Form1 in the Designer.

2. In the Designer, select the form. The properties for the form are displayed in the Property Grid.

3. In the Property Grid, set the following properties to the values specified in the following table:

Property

Value

Text

Trey Research

FormBorderStyle

Fixed3D

StartPosition

Manual

Location

100,200

Opacity

75%

4. From the Toolbox, drag three buttons onto the Form and position them conveniently.

5. Select each button in turn and, in the Properties window, set the Text property of the buttons to Border Style, Resize, and Opacity. When finished, your form should look similar to Figure 1-5.

Snl Trey Research

QUI®]

| Border Style ]

[ Resize ]

[ Opacity ]

Figure 1-5 The practice form

Figure 1-5 The practice form

6. In the designer, double-click the button labeled Border Style to open the code window to the event handler for Button1.Click. Add the following line of code to this method:

Me.FormBorderStyle = FormBorderStyle.Sizable // C#

this.FormBorderStyle = FormBorderStyle.Sizable;

7. Return to the Designer, and then double-click the Resize button and add the following line:

8. Return to the Designer, and then double-click the Opacity button and add the following line:

this.Opacity = 1;

9. Press F5 to run the application. Click each button and observe the effect on the appearance of the form.

► Exercise 2: Create a Non-Rectangular Windows Form

1. In this exercise, you will create a triangular Windows Form.

2. Open Visual Studio 2005 and create a new Windows Forms project. The project opens with a default form named Form 1 in the designer.

3. In the Property Grid, set the FormBorderStyle property to None and the Back-Color property to Red. This will make the form easier to see when you test the application.

4. Drag a Button from the Property Grid to the upper left-hand corner of the form.

Set the Text property of the button to Close Form.

5. Double-click the Close Form button and add the following code to the Button1_Click event handler:

6. In the Designer, double-click the form to open the Form1_Load event handler. Add the following code to this method. This code sets the form's region to the shape of a triangle by defining a polygon with three corners.

Dim myPath As New System.Drawing.Drawing2D.GrapliicsPatliO

myPath.AddPo1ygon(New Point() { New Point(0, 0), New Point(0, Me.Height), _

New Point(Me.Width, 0) }) Dim myRegion As New Region(myPath) Me.Region = myRegion

System.Drawing.Drawing2D.GraphicsPath myPath = new

System.Drawing.Drawing2D.GraphicsPath(); myPath.AddPo1ygon(new Point[] { new Point(0, 0), new Point(0, this.Height), new Point(this.Width, 0) }); Region myRegion = new Region(myPath); this.Region = myRegion;

Press F5 to run the application. A triangular-shaped form is displayed.

Lesson Summary

Forms are the basic building blocks of a Windows application and serve as the foundation for the user interface. The form can act as a host for controls and can contain methods, properties, and events. Forms can be added at design time, or new instances of forms can be added in code at run time.

■ You can alter the look, feel, and behavior of a form by changing the form's properties. Properties such as Text, FormBorderStyle, WindowState, Size, StartPosition, TopMost, Visible, and Opacity allow you to create a variety of visual styles and effects.

■ You can designate the startup form in the project properties window for Visual Basic or by changing the startup form in the Main method. This method is usually found in the Program.cs class, which is auto-generated.

■ You can create non-rectangular forms by creating a new instance of the Region class and then setting the form's Region property to that new instance.

Lesson Review

The following questions are intended to reinforce key information presented in this lesson. The questions are also available on the companion CD if you prefer to review them in electronic form.

NOTE Answers

Answers to these questions and explanations of why each answer choice is correct or incorrect are located in the "Answers" section at the end of the book.

1. Which of the following code snippets demonstrates how to add a new instance of a Windows Form named Form 1 at run time?

Dim myForm As Form1 myForm = Form1.CreateForm()

Form1 myForm;

myForm = Form1.CreateForm();

Dim myForm As Form1 myForm.Show()

Form1 myForm; myForm.Show();

myForm = Form1 myForm.Show()

myForm = Form1; myForm.Show();

Dim myForm As Form1 myForm = New Form1()

Form1 myForm; myForm = new Form1();

2. Which of the following code snippets correctly demonstrates how to set a form to a non-rectangular shape?

Dim aPath As New System.Drawing.Drawing2D.GraphicsPath aPath.AddEllipse(0, 0, Me.Width, Me.Height) Me.Region = New Region();

System.Drawing.Drawing2D.GraphicsPath aPath = new System. Drawing.Drawing2D.GrapliicsPatliO; aPath.AddEllipse(0, 0, Me.Width, Me.Height); this.Region = new Region();

Dim aPath As New Systeiii.Drawing.Drawing2D.GrapliicsPatli aPath.AddE11ipse(0, 0, Me.Width, Me.Height)

System.Drawing.Drawing2D.GraphicsPath aPath = new System.Drawing.Drawing2D.GraphicsPathC); aPath.AddEllipse (0, 0, Me.Width, Me.Height);

Dim aPath As New System.Drawing.Drawing2D.GraphicsPath aPath.AddE11ipse(0, 0, Me.Width, Me.Height) Me.Region = New Region(aPath)

System.Drawing.Drawing2D.GraphicsPath aPath = new System.Drawing.Drawing2D.GraphicsPathO; aPath.AddE11ipse(0, 0, Me.Width, Me.Height); this.Region = new Region(aPath);

Dim aPath As New System.Drawing.Drawing2D.GraphicsPath aPath.AddE11ipse(0, 0, Me.Width, Me.Height) Me.Region = aPath

System.Drawing.Drawing2D.GraphicsPath aPath = new System.Drawing.Drawing2D.GraphicsPath(); aPath.AddE11ipse(0, 0, Me.Width, Me.Height) this.Region = aPath;

3. Which of the following code samples correctly sets the title, border style, size, and opacity of a form?

Me.FormBorderStyle = FormBorderSty1e.Fixed3D Me.Size = New Size(300, 300) Me.Opacity = 0.5

this.FormBorderStyle = FormBorderSty1e.Fixed3D; this.Size = new Size(300, 300); this.Opacity = 0.5;

Me.Text = "My Form" Me.BorderStyle = "Fixed3D' Me.Size = New Size(300, 300) Me.Opacity = 0.5

this.BorderStyle = "Fixed3D"; this.Size = new Size(300, 300); this.Opacity = 0.5;

Me.FormBorderStyle = FormBorderSty1e.Fixed3D Me.Size = (300,300) Me.Opacity = "100%"

this.FormBorderStyle = FormBorderSty1e.Fixed3D; this.Size = (300,300); this.Opacity = "100%";

Me.Title = "My Form"

Me.FormBorderStyle = FormBorderSty1e.Fixed3D Me.Size = New Size(300,300) Me.Opacity = "100%"

this.FormBorderStyle = FormBorderSty1e.Fixed3D; this.Size = new Size(300,300); this.Opacity = "100%";

Was this article helpful?

0 0

Responses

  • nathanial
    How to set starting form visual basic?
    8 years ago
  • jolanda
    How to inscribe there on a button box in the form in visual basic?
    8 years ago

Post a comment