How do I add a context menu to a control

The frame will manage a context menu for you if you set the control’s ContextMenu property. Here is some code adding a context menu to a Label. //Add Menus in your form’s constructor… this.pictureContextMenu = new ContextMenu(); this.pictureContextMenu.MenuItems.Add(‘&Color’, new EventHandler(Color_Clicked)); this.pictureContextMenu.MenuItems.Add(‘&Font’, new EventHandler(Font_Clicked)); label1.ContextMenu = this.pictureContextMenu; // // TODO: Add any constructor code after InitializeComponent call // } private void Font_Clicked(object sender, System.EventArgs e) { . . . } private void Color_Clicked(object sender, System.EventArgs e) { … }

How can I save a temporary disk file from an embedded string resource

//usage: string s = CopyResourceToTempFile(GetType(), ‘showcase.txt’); //where showcase.txt is an embedded resource static string CopyResourceToTempFile(Type type, string name) { string temp = ”; string nsdot = type.Namespace; if (nsdot == null) nsdot = ”; else if (nsdot != ”) nsdot += ‘.’; Stream stream = type.Module.Assembly.GetManifestResourceStream(nsdot + name); if (stream != null) { StreamReader sr = new StreamReader(stream); temp = Path.GetTempFileName(); StreamWriter sw = new StreamWriter(temp, false); sw.Write(sr.ReadToEnd()); sw.Flush(); sw.Close(); } return temp; }

How do I maximize my main window

To maximize the main window, you can get the handle of the main window in the new process, and then send a SC_MAXIMIZE system command message to it. You can get the handle through the Process.MainWindowHandle property. To send a message you should use the DllImportAttribute attribute to import the API function. This is a sample code: public class WinAPI { public const int WM_SYSCOMMAND = 0x0112; public const int SC_MAXIMIZE = 0xF030; [DllImportAttribute (‘user32.dll’)] public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam); } Process p = new Process(); p.StartInfo.FileName = @’D:\Program Files\test.exe’; p.Start(); WinAPI.SendMessage(p.MainWindowHandle, WinAPI.WM_SYSCOMMAND, WinAPI.SC_MAXIMIZE,0); (from [email protected] on microsoft.public.dotnet.framework.windowsforms)