neal stublen [email protected]. practice solution create a new solution add a winforms project ...
TRANSCRIPT
DEPLOYMENT
Practice Solution
Create a new solution Add a WinForms project Add a Class Library project Reference the library from the
WinForms project
XCopy
Simple file copy Dependencies must already be installed
(e.g. .NET Framework) Won’t install Start menu icons, etc.
Using XCopy Deployment Defaults of bin\Debug, bin\Release within
project folder $(SolutionDir), $(ProjectDir), etc.
http://msdn.microsoft.com/en-us/library/c02as0cs.aspx
$(SolutionDir)_Output\Debug\$(TargetFileName) $(SolutionDir)_Output\Release\$(TargetFileName) C:\Stage\$(SolutionName)\Debug\$(TargetFileName) C:\Stage\$(SolutionName)\Release\$
(TargetFileName)
ClickOnce
Install from a link on a web page Adds Start menu shortcuts, etc. Adds entry to Programs and Features
for changing and uninstalling the application
Automatic updates
Setup
Create a setup program to be run from the user’s computer
Install components to the GAC (global assembly cache)
Modify the registry Create a setup program when
ClickOnce is not adequate Discontinued after VS2010
WiX Toolset
Windows Installer XML Toolset Alternative to discontinued Setup
projects http://wixtoolset.org
USER CONTROLS
When To Use Them?
Create compound controls Create specialized controls with
modified behavior
User Control Properties Override UserControl properties [Browsable(true)] [EditorBrowsable(EditorBrowsableState.Always)] [DesignerSerializationVisibility
(DesignerSerializationVisibility.Content)] [Bindable(true)]
Code Practice Create a Label that turns into a TextBox
when clicked Create a User Control Library Add a Label to the form Add a TextBox to the form
Visible = false Override Text property of UserControl to
update Label Handle Click event to edit Label Text Handle Enter key to finish editing
Code Practice
Handle Escape key to cancel editing Handle loss of focus to cancel editing Create an event to signal a text change Ensure Text and TextChanged are
visible in the designer
EXTENSION METHODS
Extend Existing Classespublic static class Extensions{ public string ToTitleCase(string inText) { }
public int WordCount(string inText) { }}
string title = Extensions.ToTitleCase(title);int count = Extensions.WordCount(title);
Extend Existing Classespublic static class Extensions{ public static string ToTitleCase(this string inText) { }
public static int WordCount(this string inText) { }}
string title = title.ToTitleCase();int count = title.WordCount();
MULTIPLE THREADS
Thread Class Create a new thread to execute some background
task
Thread t =new Thread(new ThreadStart(ThreadProc_);
t.Start();// Do some other stuff...t.Join();
public static void ThreadProc(){}
Code Practice
Create a new project Create a method that will write the
numbers 1 to 10 to the console Create a secondary thread that will call
this method Start the thread Call the method on the primary thread Join the thread
Code Practice
Modify the method that writes to the console to update a shared integer value 100 times
Run the program and write the counter value to the console
lock Synchronization
The lock statement allows us to guard access to an object
Code Practice
Update the previous example to prevent concurrent access to the counter
BackgroundWorker The BackgroundWorker control provides a
way to add background functionality to a form
Handler to do work on a background thread Handlers to report progress and catch
completion IsBusy confirms background process is
running Call RunWorkerAsync() from primary thread
BackgroundWorker Progress
Call ReportProgress within DoWork handler
Cancel BackgroundWorker Call CancelAsync () from primary thread Check CancellationPending property
within DoWork handler Set Cancel property to true in
DoWorkEventArgs Exit DoWork handler
Code Practice
Create a BackgroundWorker that just updates a progress bar
Async Patternclass Example{ // Synchronous method call public bool LongMethod(string param);
// Asynchronous method call public void LongMethodAsync(string param); public event LongMethodCompletedEventHandler
LongMethodCompleted;}
MDI APPLICATIONS
Multiple Document Interface Word can be changed from SDI (all
documents appear on taskbar) to MDI (single taskbar icon)
Often replaced by separate top-level Windows or a tabbed interface (e.g. Visual Studio)
Using MDI
Set IsMdiContainer to true on parent form
Set MdiParent property on child forms at runtime
Parent’s ActiveMdi property indicates the currently active child form
Parent’s LayoutMdi property can arrange the child forms