15.02.2015 Views

C# 4 and .NET 4

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Creating a Windows forms application ❘ 1119<br />

meThod/ProPerTy<br />

MessageLoop<br />

StartupPath<br />

AddMessageFilter<br />

DoEvents<br />

EnableVisualStyles<br />

Exit <strong>and</strong> ExitThread<br />

desCriPTion<br />

Returns true if a message loop exists on the current thread; false otherwise.<br />

Similar to ExecutablePath, except that the filename is not returned.<br />

Used to preprocess messages. By implementing an IMessageFilter-based<br />

object, the messages can be filtered from the message loop, or special processing<br />

can take place prior to the message being passed to the loop.<br />

Similar to the Visual Basic DoEvents statement. Allows messages in the queue to<br />

be processed.<br />

Enables XP visual styles for the various visual elements of the application. There are<br />

two overloads that will accept manifest information. One is a stream of the manifest,<br />

<strong>and</strong> the other is the full name <strong>and</strong> path of the location where the manifest exists.<br />

Exit ends all currently running message loops <strong>and</strong> exits the application.<br />

ExitThread ends the message loop <strong>and</strong> closes all windows on the current thread.<br />

Now, what does this sample application look like when it is generated in Visual Studio The first thing to<br />

notice is that two files are created because Visual Studio takes advantage of the partial class feature of the<br />

Framework <strong>and</strong> separates all of the Designer-generated code into a separate file. Using the default name of<br />

Form1, the two files are Form1.cs <strong>and</strong> Form1.Designer.cs. (Unless you have the Show All Files option<br />

checked on the Project menu, you won’t see Form1.Designer.cs in Solution Explorer.) Following is the<br />

code that Visual Studio generates for the two files. First is Form1.cs:<br />

using System;<br />

using System.Collections.Generic;<br />

using System.ComponentModel;<br />

using System.Data;<br />

using System.Drawing;<br />

using System.Linq;<br />

using System.Text;<br />

using System.Windows.Forms;<br />

namespace VisualStudioForm<br />

{<br />

public partial class Form1: Form<br />

{<br />

public Form1()<br />

{<br />

InitializeComponent();<br />

}<br />

}<br />

}<br />

code snippet Form1.cs<br />

This is pretty simple, a h<strong>and</strong>ful of using statements <strong>and</strong> a simple constructor. Here is the code in Form1<br />

.Designer.cs:<br />

namespace VisualStudioForm<br />

{<br />

partial class Form1<br />

{<br />

/// <br />

/// Required designer variable.<br />

/// <br />

private System.ComponentModel.IContainer components = null;<br />

/// <br />

/// Clean up any resources being used.<br />

/// <br />

/// true if managed resources<br />

/// should be disposed; otherwise, false.<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!