ray_code
asked on
Clicking on title bar in an mdichild form c#
I have a mdiparent with mdichild forms within it.
I found some code in this forum to help me handle when a form title bar is clicked (Reference A).
The mdiparent dynamically loads various forms (possible up to 100) and assigns them as mdi childs and manually assigning Reference A code in each would be inconvient.
I want to assign the code to each form when they load somehow of the mdichild, so they can detect when the titlebar is clicked.
How can achieve this.
Thanks for any assistance.
Reference A:
protected override void WndProc(ref Message m)
{
const Int32 WM_NCLBUTTONCLK = 161;
const Int32 WM_NCLBUTTONDBLCLK = 163;
if (m.Msg == WM_NCLBUTTONCLK)
{
TitleBarClicked(); // Implement this function and do what you need to do in this function
}
if (m.Msg == WM_NCLBUTTONDBLCLK)
{
TitlebarDoubleClicked(); // Implement this function and do what you need to do in this function
}
base.WndProc(ref m);
}
(Credited to k_swapnil)
I found some code in this forum to help me handle when a form title bar is clicked (Reference A).
The mdiparent dynamically loads various forms (possible up to 100) and assigns them as mdi childs and manually assigning Reference A code in each would be inconvient.
I want to assign the code to each form when they load somehow of the mdichild, so they can detect when the titlebar is clicked.
How can achieve this.
Thanks for any assistance.
Reference A:
protected override void WndProc(ref Message m)
{
const Int32 WM_NCLBUTTONCLK = 161;
const Int32 WM_NCLBUTTONDBLCLK = 163;
if (m.Msg == WM_NCLBUTTONCLK)
{
TitleBarClicked(); // Implement this function and do what you need to do in this function
}
if (m.Msg == WM_NCLBUTTONDBLCLK)
{
TitlebarDoubleClicked(); // Implement this function and do what you need to do in this function
}
base.WndProc(ref m);
}
(Credited to k_swapnil)
Do TitleBarClicked() and TitlebarDoubleClicked() need to run in the MdiParent or the MdiChild? What do those methods need to do?
ASKER
Mdichild so , basically when they click on the mdichild title bar, I can handle those whatever methods.
I only need the WM_NCLBUTTONCLK singleclick.
I only need the WM_NCLBUTTONCLK singleclick.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Can you get away with just knowing when the active MdiChild has changed?
The MdiChild (Form2):
public partial class Form2 : Form
{
private int counter = 0;
public Form2()
{
InitializeComponent();
}
public void MdiChildActivated()
{
counter += 1;
this.Text = "MdiChildActivated: " + counter.ToString();
}
}
The MdiParent (Form1):
The MdiChild (Form2):
public partial class Form2 : Form
{
private int counter = 0;
public Form2()
{
InitializeComponent();
}
public void MdiChildActivated()
{
counter += 1;
this.Text = "MdiChildActivated: " + counter.ToString();
}
}
The MdiParent (Form1):
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.MdiParent = this;
f2.Show();
}
private void Form1_MdiChildActivate(object sender, EventArgs e)
{
Form frm = this.ActiveMdiChild;
if (frm != null)
{
System.Reflection.MethodInfo mi = frm.GetType().GetMethod("MdiChildActivated");
if (mi != null)
{
mi.Invoke(frm, new Object[] { });
}
else
{
Console.WriteLine("MdiChildActivated() not found in MdiChild Form");
}
}
}
}
}
ASKER
Thanks Idle Mind you demonstrated what I wanted to achieve.