How do I prevent the Designer-Grid from being drawn on my Container Control during design-time?
You can do so by overriding the DrawGrid property in your custom designer: public class MyContainerDesigner : ParentControlDesigner { protected override /*ParentControlDesigner*/ bool DrawGrid { get { if (!this.disableDrawGrid) return base.DrawGrid; else return false; } } }
How can I show a form without making it active
Normally when you make a Form visible by setting the Visible property to true, it will show the form and set the focus too. In some cases however, you do not want it to take focus until the user clicks on it. To get this behavior, do the following utility code: When you want to show a form without activating it: UtilFuncs.SetVisibleNoActivate(myForm, true); // true to show. When you want to hide it: UtilFuncs.SetVisibleNoActivate(myForm, false); // false to hide. public class UtilFuncs { [DllImport(‘USER32.dll’)] extern public static bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags) ; public const int HWND_TOPMOST = -1; // 0xffff public const int SWP_NOSIZE = 1; // 0x0001 public const int SWP_NOMOVE = 2; // 0x0002 public const int SWP_NOZORDER = 4; // 0x0004 public const int SWP_NOACTIVATE = 16; // 0x0010 public const int SWP_SHOWWINDOW = 64; // 0x0040 public const int SWP_HIDEWINDOW = 128; // 0x0080 public const int SWP_DRAWFRAME = 32; // 0x0020 public static void ShowWindowTopMost(IntPtr handle) { SetWindowPos(handle, (IntPtr)HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_SHOWWINDOW); } public static void SetVisibleNoActivate(Control control, bool visible) { if(visible) { ShowWindowTopMost(control.Handle); control.Visible = true; } else control.Visible = false; } }
When I get the SelectedNode in the treeview’s Click event, it is the old selection. How do I get the newly selected node
Try using the AfterSelect event instead of the Click event. The Click event is inherited from Control.Click and occurs before the new selection is set into SelectedNode. The AfterSelect event is fired after the newly selected node is placed in the SelectedNode property. This code illustrates these events. private void treeView2_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e) { TreeNode node = treeView2.SelectedNode; Console.WriteLine(‘AfterSelect:’ + node.ToString());//from tree Console.WriteLine(‘AfterSelect:’ + e.Node.ToString());//from event args } private void treeView2_Click(object sender, System.EventArgs e) { TreeNode node = treeView2.SelectedNode; if(node == null) Console.WriteLine(‘Click: (none)’); else Console.WriteLine(‘Click: ‘ + node.ToString()); }
I’m trying to make the background of my linklabel transparent so a picturebox will show through it. However, if I set the link label’s BackColor property to Transparent the label still has a white background. Why
Controls with a ‘Transparent’ color actually render their parent’s background, so you’re seeing the White background of the Form, not the PictureBox. Three easy ways to deal with this: Use a Panel with it’s ‘BackgroundImage’ property set instead of a PictureBox, and parent the LinkLabels to the panel (PictureBoxes generally don’t have children) Set the BackgroundImage of the Form to the image (basically the same as 1 above, but avoids the extra control) In code, set the Parent of the LinkLabel to be the PictureBox. You’ll need to update the LinkLabel’s position to match the new origin of the parent if the PictureBox isn’t at (0,0) (Shawn Burke on microsoft.public.dotnet.framework.windowsforms newsgroup)
How can I catch the BeforeNavigate2 event?
This is a known bug. See http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q311298&ID=KB;EN-US; If you are using the second solution from our FAQ ‘How can I host a WebBrowser control in a Windows Form’ you will not have this problem but if you use the automatically generated wrapper classes see the following solution: John Cullen posted the following answer in the microsoft.public.dotnet.framework.interop newsgroup. The problem of the BeforeNavigate2 event not firing in C# applications has been floating around various groups for several months. Microsoft have not yet fixed the problem, although it is documented in the knowledge base. Until they do provide a fix, I suggest the following workaround to the problem which uses the fact the the old Webbrowser_V1 BeforeNavigate event *can* be caught. Note, use of this interface is deprecated, however since there doesn’t appear to be any chance of a fix any time soon… … // define the webbrowser object private AxSHDocVw.AxWebBrowser axDocument; // define an IE3 compatible webbrowser object. private SHDocVw.WebBrowser_V1 axDocumentV1; public Form1() { //… object o = null; axDocument.Navigate(‘about:blank’, ref o, ref o, ref o, ref o); object oOcx = axDocument.GetOcx(); try { axDocumentV1 = oOcx as WebBrowser_V1; axDocumentV1.BeforeNavigate += new SHDocVw.DWebBrowserEvents_BeforeNavigateEventHandler(this.axDocumentV1_BeforeNavigate); } catch (Exception ex) { // ignore errors. If it doesn’t work, there’s not a lot to do! Console.WriteLine(‘Add BeforeNavigate event handler failed with{0}.’, ex.Message); } //… } private void axDocumentV1_BeforeNavigate(string URL, int Flags, string TargetFrameName, ref object PostData, string Headers, ref bool Processed) { Console.WriteLine(‘BeforeNavigateURL= {0}’, URL); //false= allow navigate to continue. //true= cancel navigation. Processed=false; }