How can I get the directory name for ‘My Documents’ folder and other system directories?
Mark Boulter (Microsoft) gives code in a posting to the DOTNET newsgroup at [email protected]. You can also use the System.Environment class to get at this information. MessageBox.Show(Environment.GetFolderPath(Environment.SpecialFolder.Personal));
How do I get the associated Icon from a file in the file system
Here is a sample prepared by Matthias Heubi that uses interop to access SHGetFileInfo to retrieve icons. You could also use the ExtractIconEx native api via PInvoke to extract the app icon.
How do I overlay one bitmap over another
You can create a Graphics object from the base bitmap, and then use this Graphics object to draw the second bitmap with a transparent color that allows the base bitmap to show through. Bitmap Circle = (Bitmap)Image.FromFile(@’c:\circle.bmp’); Bitmap MergedBMP = (Bitmap)Image.FromFile(@’c:\cross.bmp’); Graphics g = Graphics.FromImage(Circle); MergedBMP.MakeTransparent(Color.White); g.DrawImage(MergedBMP,0,0); g.Dispose(); pictureBox1.Image = Circle;
How can I host a WebBrowser control in a Windows Form?
We have two suggestions with sample projects how you host a WebBrowser control inside a form and display HTML contents and listen to events such as NavigateComplete or BeforeNavigate. Of course there are many other ways to do this. Download htmlviewer.zip for two sample projects for the suggestions discussed below. 1) The first suggestion is to generate an ActiveX wrapper for shdocvw using the aximp tool. The command line for this tool should be as follows: aximp c:\windows\system32\shdocvw.dll This will generate the following assemblies. Generated Assembly: D:\Syncfusion\faq\HtmlBrowser\HtmlViewer2\SHDocVw.dll Generated Assembly: D:\Syncfusion\faq\HtmlBrowser\HtmlViewer2\AxSHDocVw.dll Now you can reference these dlls in your project and use AxWebBrowser. In the attached HtmlViewer2 sample we have derived a HtmlControl class from AxWebBrowser and added some properties that let you specify a CSS Stylesheet and the Html content as a string. 2) Our second sample lets you bypass the generation of a ActiveX wrapper. You don’t have to include and ship shdocvw.dll and axshdocvw.dll. In the attached HtmlViewer sample, we derived from AxHost and attached our own IWebBrowserEvents interface by overriding the CreateSink, AttachInterfaces and DetachSink methods. You can use HtmlControl in your form and specify HTML content by assigning a HTML string to HtmlControl. A cascading style sheet can be specified by assigning a path name to the CascadingStyleSheet property. The sample demonstrates how to use a CSS style sheet that has been embedded as a resource in the assembly.
How do I draw rotated text
private void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Graphics g = e.Graphics; g.TranslateTransform(100.0f, 100.0f); g.RotateTransform(-90.0f); g.DrawString(‘Vertical Text’, Font, Brushes.Blue, 0.0f, 0.0f); g.ResetTransform(); g.TranslateTransform(100.0f, 100.0f); g.RotateTransform(-45.0f); g.DrawString(‘Slanted Text’, new Font(Font, FontStyle.Bold), Brushes.Red, 0.0f, 0.0f); g.ResetTransform(); }