C#

usingSystem;usingSystem.Drawing;usingSystem.Windows.Forms;#endregionnamespaceCSWinFormSplashScreen{publicpartialclassSplashScreen1:Form{Timert=newTimer();boolfadeIn=true;boolfadeOut=false;publicSplashScreen1(){InitializeComponent();ExtraFormSettings();SetAndStartTimer();}privatevoidSetAndStartTimer(){t.Interval=50;t.Tick+=newEventHandler(t_Tick);t.Start();}privatevoidExtraFormSettings(){this.FormBorderStyle=FormBorderStyle.None;this.Opacity=0.5;this.BackgroundImage=CSWinFormSplashScreen.Properties.Resources.SplashImage;}voidt_Tick(objectsender,EventArgse){// Fade in by increasing the opacity of the splash to 1.0if(fadeIn){if(this.Opacity<1.0){this.Opacity+=0.02;}// After fadeIn complete, begin fadeOutelse{fadeIn=false;fadeOut=true;}}elseif(fadeOut)// Fade out by increasing the opacity of the splash to 1.0{if(this.Opacity>0){this.Opacity-=0.02;}else{fadeOut=false;}}// After fadeIn and fadeOut complete, stop the timer and close this splash.if(!(fadeIn||fadeOut)){t.Stop();this.Close();}}}}

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.DirectoryServices;namespaceCSIISAdminADSI{classProgram{staticvoidMain(string[]args){Console.WriteLine("Press any key to create the new web site.");Console.ReadLine();//Connect to IIS ADSI Provider stringServerName="LocalHost";DirectoryEntryW3SVC=newDirectoryEntry("IIS://"+ServerName+"/w3svc");// Create new web site. objectsiteObj;stringsiteID="";stringsiteName="IISADSIDemo";stringhostHeader="www.mytestdomain.com";stringserverBinding1=":8181:";stringserverBinding2=":8282:"+hostHeader;stringrootPath="C:\\inetpub\\IISADSIDemo";object[]siteProperty=newobject[]{siteName,newobject[]{serverBinding1,serverBinding2},rootPath};try{siteObj=(object)W3SVC.Invoke("CreateNewSite",siteProperty);siteID=siteObj.ToString();W3SVC.CommitChanges();}catch(Exceptionex){Console.WriteLine("Fail to create web site with the following exception: \n{0}",ex.Message);}/////////////////////////////////////////////////////////////////////// // Wait for a while to allow ADSI finish the above operations // and then start the web site. Console.WriteLine("Web site created. Starting IISADSIDemo...");System.Threading.Thread.Sleep(1000);DirectoryEntrynewSite=newDirectoryEntry("IIS://"+ServerName+"/W3SVC/"+siteID);newSite.Invoke("Start");Console.WriteLine("Started \n");Console.WriteLine("Create new virtual directory.");// Create new virtual directory. stringmetabasePath=string.Format("/W3SVC/{0}/Root",siteID);DirectoryEntrysite=newDirectoryEntry("IIS://"+ServerName+metabasePath);DirectoryEntriesvdirs=site.Children;DirectoryEntrynewVDir=vdirs.Add("vdir1","IIsWebVirtualDir");newVDir.Properties["Path"][0]="C:\\inetpub\\IISADSIDemo\\vdir1";newVDir.Properties["AccessScript"][0]=true;newVDir.Properties["AppFriendlyName"][0]="vdir1";newVDir.Properties["AppIsolated"][0]="1";newVDir.Properties["AppRoot"][0]="/LM"+metabasePath+"/vdir1";newVDir.CommitChanges();Console.WriteLine("vdir1 created. \n");// List all web sites on the server. Console.WriteLine("List all web sites on server: \n");try{foreach(DirectoryEntrySiteinW3SVC.Children){if(Site.SchemaClassName=="IIsWebServer")Console.WriteLine(Site.Name+" - "+Site.Properties["ServerComment"].Value.ToString());}}catch(Exceptione){Console.WriteLine("Fail to list web sites with the following exception: \n{0}: "+e.ToString());}}}}

C#

// DataSource setup: // // Create a Table named Test and add 2 columns // ID: int // Name: string // DataTabledtTest=newDataTable();dtTest.Columns.Add("ID",typeof(int));dtTest.Columns.Add("Name",typeof(string));dtTest.Rows.Add(1,"John");dtTest.Rows.Add(2,"Amy");dtTest.Rows.Add(3,"Tony");dtTest.Rows.Add(4,"Bruce");dtTest.Rows.Add(5,"Allen");// Bind the ComboBox to the DataTable this.comboBox1.DataSource=dtTest;this.comboBox1.DisplayMember="Name";this.comboBox1.ValueMember="ID";// Enable the owner draw on the ComboBox. this.comboBox1.DrawMode=DrawMode.OwnerDrawFixed;// Handle the DrawItem event to draw the items. this.comboBox1.DrawItem+=delegate(objectcmb,DrawItemEventArgsargs){// Draw the default background args.DrawBackground();// The ComboBox is bound to a DataTable, // so the items are DataRowView objects. DataRowViewdrv=(DataRowView)this.comboBox1.Items[args.Index];// Retrieve the value of each column. stringid=drv["id"].ToString();stringname=drv["name"].ToString();// Get the bounds for the first column Rectangler1=args.Bounds;r1.Width/=2;// Draw the text on the first column using(SolidBrushsb=newSolidBrush(args.ForeColor)){args.Graphics.DrawString(id,args.Font,sb,r1);}// Draw a line to isolate the columns using(Penp=newPen(Color.Black)){args.Graphics.DrawLine(p,r1.Right,0,r1.Right,r1.Bottom);}// Get the bounds for the second column Rectangler2=args.Bounds;r2.X=args.Bounds.Width/2;r2.Width/=2;// Draw the text on the second column using(SolidBrushsb=newSolidBrush(args.ForeColor)){args.Graphics.DrawString(name,args.Font,sb,r2);}};

C#

// Add reference "Windows Script Host Object" from COM tabusingIWshRuntimeLibrary;WshShellClassshell=newWshShellClass();// Choose the path for the shortcutIWshShortcutshortcut=(IWshShortcut)shell.CreateShortcut(@"D:\shotcut.lnk");// Where the shortcut should point toshortcut.TargetPath=Application.ExecutablePath;这一步非常重要，否则从快捷方式启动程序，会崩溃shortcut.WorkingDirectory=@"...";// Description for the shortcutshortcut.Description="Any Description here ";// save it / createshortcut.Save();