0

so im creating a gui in c# and i set the border to None (for the flat style look) and i noticed that upon doubleclicking the gui anywhere it maximizes the gui on the entire screen even tho i disabled it in the options.

https://i.stack.imgur.com/FIjxa.png

i tried changing options and adding a doubleclicking function

    private void Form1_DoubleClick(object sender, EventArgs e)
    {
        MessageBox.Show("no", "test");

    }

this doesnt go off when doubleclicking the gui...i dont know what to do at this point.

any ideas anyone? full code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ScrapEX
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

    private void Form1_Load(object sender, EventArgs e)
    {
        MessageBox.Show("no", "test");
    }


    private void Form1_DoubleClick(object sender, EventArgs e)
    {
        MessageBox.Show("no", "test");

    }

    protected override void WndProc(ref Message m)
    {
        switch (m.Msg)
        {
            case 0x84:
                base.WndProc(ref m);
                if ((int)m.Result == 0x1)
                    m.Result = (IntPtr)0x2;
                return;
        }

        base.WndProc(ref m);

    }



}

}

now that i can see that what ive been using to make the window resizeable,could i make it so only a small area acts as the titlebar? like a triangle at the top right or something? sorry for mixing questions but this is related

downrep_nation
  • 432
  • 1
  • 7
  • 16
  • 1
    What does this `WndProc` part? Double clicking window caption has such behavior. Are you playing with non-client region or what? – Sinatr Mar 03 '15 at 13:07
  • Can you try changing your FormBorderStyle to other than None, like Single or something. Check if you can see maximize button. – Gaurav Sharma Mar 03 '15 at 13:45

1 Answers1

1

As @Sinatr indicates, your WndProc is responding to every WM_NCHITTEST query by setting 2, or HTCAPTION, effectively making your entire form act as the title bar.

This makes double-clicking (un)maximize your form.

See also MSDN: WM_NCHITTEST message.

As for your edit, you seem to want to make a custom title bar. See Win api in C#. Get Hi and low word from IntPtr to get a Point with X and Y coordinates, so you can determine when to set 1 (HTCLIENT) or 2 (HTCAPTION).

Community
  • 1
  • 1
CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • oh right..so how can i make the window moveable without causing this? and if i cant. is there an event for doubleclicking the titlebar? – downrep_nation Mar 03 '15 at 13:11
  • Mentioning that you added that override to make your window draggable would have been valuable information in your question. Please include all relevant details. See duplicate for some answers to that question. – CodeCaster Mar 03 '15 at 13:13