FAQ'S ON EVENT HANDLING

How do I provide the event handling for my form and controls using VS.NET?

Adding Event Handling You can provide event handling for forms and controls by implementing their respective event handlers. To implement an event handler for a form or control, go to Events tab of the properties window, and double click the desired event handler name.

The form designer will add the event handler for the selected event in the source code of the application and take you there. If you want to implement a default event handler of the form or control, simply double click it.

C# Version

Write the code to close the application (Application.Exit()) in the event handler. The IDE in fact has not only created the event handler but also has registered it with the Exit button’s Click event.

How event handling is implemented in win form and .NET form controls with C#?

Adding Event Handling A control exposes an event by defining its delegate. We can add our own event handler for the event by writing an event handler method and adding it to the event’s delegate.

How event handling is implemented in win form and .NET form controls with VB.NET?

Adding Event Handling A control exposes an event by defining its ‘delegate’. We can add our own event handler for the event by writing an event handler method and adding it to the event's delegate. Let's add a button labeled 'Exit' to the form.

The 'Exit' button will close the application when it is clicked. In .Net, Push Buttons are instances of the System.Windows.Forms.Button class. To associate some action with the button click, we need to create an event handler and register (or add) it to the Button's Click event.

What are the lifetime events of a form?

Some important lifetime events of a form include:

Load: This event is fired when the form is first loaded in the program. It is called when the Form.Show() or Form.ShowDialog() method is called for the first time.
Activated: This event is triggered whenever the form gets the application focus. It is fired when the form is first loaded (along with Load event), when the form is brought in front, or when the form is restored from the minimized state.

VisibleChanged:

It is called whenever the Visible property of the form is changed or the form is hidden or shown.

Deactivated:

This event is triggered whenever the form loses the application focus. It is fired when the form is closed, when the form is brought into background, or when the form is minimized.


Closing:

It is fired when the application wishes to be closed, or the application is in the process of close but has not yet closed.

Closed: It is raised when the application is finally closed.

How do I change the title of my window?

Use the Text property of the Form to change the title of the form.

How do I change the application name?

To change the application name, change the name of the startup project by right clicking the project node in the solution explorer and selecting properties. It will show the property pages for the project. Here in the Common Properties -> General, you can change the assembly name to change the resulting executable (.exe) file name.

How do I set the startup position of the form?

To change the startup position of the form, select the form in the designer and change its StartPosition property. The StartPosition is an enumeration and has the following useful properties:

CenterScreen:

The form should be displayed at the center of the screen

WindowsDefaultLocation:

The form's startup position should be selected by the Windows Operating System

CenterParent:

The form should be displayed at the center of the parent form. This option is useful when you are building an MDI (Multiple Document Interface) application. The MDI child form can be set, in this way, to be displayed at the center of the MDI parent form.

How do I set the initial (startup) size of the form?

The size property can be used to set the startup size of the form. The data type of the size property is System.Drawing.Size. The size can be set as:

C# Version

myForm.Size = new System.Drawing.Size(400, 300);

VB.NET Version

myForm.Size = New System.Drawing.Size(400, 300)

What does it mean by Startup Window State of the form? How do I set the startup window state of the form?

The startup window state specifies whether the form should be displayed in normal, maximized or minimized state. It can be set using the WindowState property of the form. The data type of this property is System.Windows.Forms.FormWindowState enumeration, which has three members; Maximized, Minimized and Normal.

What is the difference between modal and non-modal dialogs?

The modal form, when displayed on the screen, does not allow you to go and select any other form of the window. The typical example of the Modal form is the Message Box; you must select OK (or other appropriate) button to go back to other forms of the applications.

The Non modal form, on the other hand, does not prevent you from accessing other form windows of the application, when they are present on the screen using the Show() method of the form.

RELATED POST

ASP.NET INTERVIEW QUESTIONS AND ANSWERS PART ONE

ASP.NET INTERVIEW QUESTIONS AND ANSWERS PART TWO

ASP.NET INTERVIEW QUESTIONS AND ANSWERS PART THREE

ASP.NET INTERVIEW QUESTIONS AND ANSWERS PART FOUR

ASP.NET INTERVIEW QUESTIONS AND ANSWERS PART FIVE

ADO.NET INTERVIEW QUESTIONS AND ANSWERS PART ONE

ADO.NET INTERVIEW QUESTIONS AND ANSWERS PART TWO

You can also learn the concept of frame work concept in detail with questions and answers in the following place.

MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART ONE

MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART TWO

MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART THREE

MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART FOUR

MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART FIVE

MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART SIX

MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART SEVEN

MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART EIGHT

MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART NINE

MICROSOFT DOT NET FRAME WORK QUESTIONS AND ANSWERS PART TEN

No comments:

Post a Comment