0

I have a C# form, primarily covered by panels. I put a red border around the form. This is the only visible part of the form. The panels visibly cover the rest of the form. Whenever I move my mouse over the form, the red border is the only part it recognizes as the form. If I move my mouse over the panels, which are also on the form, it doesn't recognize that the mouse is still over the form. Is there a way I can manipulate the form object so they will be considered as, "part of the form?"

Here is how I am trying to achieve this:

NOTE: this is a portion of the code I have. If you need more, I am surely willing to add it.

private void rightClickMenu_Paint(object sender, PaintEventArgs e)
{
    ControlPaint.DrawBorder(e.Graphics, this.ClientRectangle,
        Color.Red, 1, ButtonBorderStyle.Solid,
        Color.Red, 1, ButtonBorderStyle.Solid,
        Color.Red, 1, ButtonBorderStyle.Solid,
        Color.Red, 1, ButtonBorderStyle.Solid);
}
private bool MouseInControl(Control ctrl)
{
    mouseInControl = ctrl.ClientRectangle.Contains(PointToClient(Control.MousePosition));
    if(mouseInControl)
    {
        rcmTimer.Stop();
        rcmTimer.Interval = 500;
    }
    else
    {
        CustomForm.rightclickmenuform.Hide();
    }
    Console.WriteLine(mouseInControl);
    return mouseInControl;
}
private void rightClickMenu_MouseEnter(object sender, EventArgs e)
{
    MouseInControl(this);
}
private void rightClickMenu_MouseLeave(object sender, EventArgs e)
{
    MouseInControl(this);
}

As I state earlier, they red border around the form is the only thing be detected by this event. Once you leave the border, the code considers you to be outside of the form, even if you aren't.

PS: I found this method from this question: https://stackoverflow.com/a/31157183/6804700

Community
  • 1
  • 1
  • any code to show? [mcve] –  May 11 '17 at 13:05
  • @MickyD I will add what I have so far. – Bradley William Elko May 11 '17 at 13:06
  • @MickyD I added the code to the question. Do you think that will be sufficient enough for a possible explanation? – Bradley William Elko May 11 '17 at 13:13
  • Thats much better thanks! –  May 11 '17 at 13:23
  • You are fighting the way Winforms is designed too hard. Why are the panels there in the first place? Why is it important that the Form class can see the mouse moving? Why did you not use the top-voted solution offered in the linked question? Only if you give insight in those design decisions can you get the best answer. – Hans Passant May 11 '17 at 13:26
  • @HansPassant I am using this form to replicate a context menu. I use the panels to act as sections in this "Custom Context Menu." I don't like how the context menu is structured and so I want to do something similar to it but have more control. I need the form objects to be considered as part of the form because they take up most of the form. I initially wanted to group up the form and its controls and use a mouse event on it. I am not that good with C#, however, so an answer that I can grasp would help. The top voted solution won't help me with my form because I barely understand it – Bradley William Elko May 11 '17 at 13:37
  • I don't think anyone is going to be able to give you any tips by looking what is in this question. I'd be willing to help you out if you want to post the whole code to GitHub (or a small project that just replicates the problem) – caesay May 12 '17 at 01:39
  • @caesay I'm not very good at using GitHub, but I'll send you it when I make it. – Bradley William Elko May 12 '17 at 12:08
  • @caesay Here it is https://github.com/BradElko/PanelForm – Bradley William Elko May 12 '17 at 12:25

0 Answers0