What is alpha blending
Alpha-blending refers to allowing a background color to show through a particular color. You use the static Color.FromArgb method to create a alpha-blended color. For example, SolidBrush redBrushSolid = new SolidBrush(Color.FromArgb(255, 255, 0, 0)); SolidBrush redBrushMedium = new SolidBrush(Color.FromArgb(120, 255, 0, 0)); SolidBrush redBrushLight = new SolidBrush(Color.FromArgb(60, 255, 0, 0)); creates three red brushes. The first argument is the alpha-blending value, from 0 to 255. The last three arguments are the RGB values, denoting in this case, red. In the picture below, all three circles use the color red, but each circle has a different alpha blending setting, allowing the white background to show through.
Is there a way to halt a screen from painting until all the controls on the form are initialized
Shawn Burke responded to this question in a posting on microsoft.public.dotnet.framework.windowsforms newsgroup. There is not currently a way to do this built into the framework, but WM_SETREDRAW will do what you’re looking for. It can’t be called recursively, so here’s code for a property you can add to your form to handle it. A VB sample is also available. int paintFrozen; private const int WM_SETREDRAW = 0xB; [DllImport(”User32”)] private static extern bool SendMessage(IntPtr hWnd, int msg, int wParam, int lParam); private bool FreezePainting { get { return paintFrozen > 0; } set { if (value && IsHandleCreated && this.Visible) { if (0 == paintFrozen++) { SendMessage(Handle, WM_SETREDRAW, 0, 0); } } if (!value) { if (paintFrozen == 0) { return; } if (0 == –paintFrozen) { SendMessage(Handle, WM_SETREDRAW, 1, 0); Invalidate(true); } } } }
Where can I find a succinct discussion of Windows Forms
One place to look is Jeff Prosise’s article, Windows Forms: A Modern-Day Programming Model for Writing GUI Applications , from the Feb 2001 MSDN magazine. A second place is Shawn Burke’s article Using the Microsoft .NET Framework to Create Windows-based Applications found in the MSDN Library.
How do I implement Drag and Drop support between two TreeViews
In a posting in the Microsoft.Windows.Forms newsgroup, Brian Roder (Microsoft) gives VB.Net code snippets to handle the DragEnter, ItemDrag and DragDrop events that provide a solution to this problem. You can get C# code in this sample, TreeViewDnD. Here is some sample handlers. private void treeView2_DragDrop(object sender, System.Windows.Forms.DragEventArgs e) { TreeNode newNode; if( e.Data.GetDataPresent(”System.Windows.Forms.TreeNode”, false)) { Point pt; TreeNode destinationNode; pt = treeView2.PointToClient(new Point(e.X, e.Y)); destinationNode = treeView2.GetNodeAt(pt); newNode = (TreeNode) e.Data.GetData(”System.Windows.Forms.TreeNode”); if(!destinationNode.Equals(newNode)) { //destinationNode.Nodes.Add(newNode.Clone()); destinationNode.Nodes.Add((TreeNode) newNode.Clone()); destinationNode.Expand(); //Remove original node newNode.Remove(); } } } private void treeView2_DragEnter(object sender, System.Windows.Forms.DragEventArgs e) { e.Effect = DragDropEffects.Move; } private void treeView2_ItemDrag(object sender, System.Windows.Forms.ItemDragEventArgs e) { DoDragDrop(e.Item, DragDropEffects.Move); }
How do I format numbers, dates and currencies in a TextBox
Each type has a ToString method that can be used to accomplished formatting. Also, you can use the String.Format method to format things as well. To format dates, use the ToString member of DateTime. You may want to use the InvariantInfo setting (see below) to get culture-independent strings.