Issue
- I have around 10+ child forms and all the child forms have the following features
- Close button: on hover displays "close" text and when mouse clicked, shows a message box to confirm the action
- Minimize button: On hover, it displays "minimize" text, when the mouse is clicked, the form gets minimized
- Drag anyway inside the parent form
- I have to avoid using Visual Studio's default style to get a desirable customized form.
-The code below is shared by all the child forms, since the code is the same, is there a way to bind to one place and reference?
code
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);
//Dtrag the form
private void DragPanel(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0);
}
}
#region controlbox
private void minimizebtn_Click(object sender, EventArgs e)
{
WindowState = FormWindowState.Minimized;
}
private void closebtn_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Are you sure you want to Close the window?", "Close", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
Close();
//Application.Exit();
}
}
private void closebtn_MouseHover(object sender, EventArgs e)
{
System.Windows.Forms.ToolTip ToolTip1 = new System.Windows.Forms.ToolTip();
ToolTip1.SetToolTip(this.closebtn, "Close");
}
private void minimizebtn_MouseHover(object sender, EventArgs e)
{
System.Windows.Forms.ToolTip ToolTip1 = new System.Windows.Forms.ToolTip();
ToolTip1.SetToolTip(this.minimizebtn, "Minimize");
}
#endregion
Solution
You could create a base class which itself derives from Form. Your actual forms should then derive from that base class.
Answered By - Romout Answer Checked By - Gilberto Lyons (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.