How can I display a pop up a confirmation dialog when the user closes the form?
You can listen to the Form’s Closing event, where you can display a MessageBox as show below: [C#] private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (MessageBox.Show('Do you want to close the application?', 'Close Application', MessageBoxButtons.YesNo) == DialogResult.No) e.Cancel = true; } [VB.NET] Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) If MessageBox.Show('Do you want to close the application?','Close Application',MessageBoxButtons.YesNo) = DialogResult.No Then e.Cancel = True End If End Sub
How can I shut down/restart the OS from my Windows Forms Application?
You could do this using the WMI Classes in the .NET Framework or use WindowsController available at http://www.mentalis.org
How can I move a Borderless form?
This code snippet shows how you can move a borderless form. [C#] public const int WM_NCLBUTTONDOWN = 0xA1; public const int HTCAPTION = 0x2; [DllImport('User32.dll')] public static extern bool ReleaseCapture(); [DllImport('User32.dll')] public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam); private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { if (e.Button == MouseButtons.Left) { ReleaseCapture(); SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0); } }
How can I make my form cover the whole screen including the TaskBar?
The following code snippet demonstrates how you can make your form cover the whole screen including the Windows Taskbar. [C#] // Prevent form from being resized. this.FormBorderStyle = FormBorderStyle.FixedSingle; // Get the screen bounds Rectangle formrect = Screen.GetBounds(this); // Set the form’s location and size this.Location = formrect.Location; this.Size = formrect.Size; [VB.NET] ’ Prevent form from being resized. Me.FormBorderStyle = FormBorderStyle.FixedSingle ’ Get the screen bounds Dim formrect As Rectangle = Screen.GetBounds(Me) ’ Set the form’s location and size Me.Location = formrect.Location Me.Size = formrect.Size
How can I word-wrap the Tooltip that is displayed?
Rhett Gong posted a work around using Reflection to achieve this in the microsoft.public.dotnet.framework.windowsforms.controls Newsgroup: [DllImport('user32.dll')] private extern static int SendMessage(IntPtr hwnd,uint msg, int wParam, int lParam); ..... object o = typeof(ToolTip).InvokeMember('Handle',BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.GetProperty,null,myToolTip,null); IntPtr hwnd = (IntPtr) o; SendMessage(hwnd,0x0418, 0, 300); .....