Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have invisible max button of mdi form of my window application,
Now please help to Prevent double click on title bar of MDI form window so that MDI can 't resize on double click.


How can I do this ,Please help me

Thanks in advance
Posted
Comments
BillWoodruff 18-Feb-12 2:19am    
Dave Auld answered your exact question about double-click, but then, in a later comment ... that you posted as an answer ... you raised issues that, to me, need clarification:

Are you saying you want the MDI Form Window to remain a fixed size ?

Are you saying you want the MDI Form Window (when not Minimized) to always appear at the same location on the Screen ? Or, do you want to allow the user to move the position of the MDI Form Window on the Screen by dragging the TitleBar, as usual ?

Do you want to be able to Minimize the MDI Form Window, then restore it to its fixed size and (fixed or previous) location: by clicking on its TaskBar Icon ?

There are simple ways to handle every variation possible implied by your question, which do not involve Windows API, at all.

If you answer these questions clearly, you can get clear responses.

I have just tried this on both the MDIParent and MDIChild forms, but if you set MaximiseBox property to FALSE, double clicking the titlebar does nothing, setting it to TRUE means a double click causes the clicked window to maximise.
 
Share this answer
 
Comments
DaveAuld 18-Feb-12 1:42am    
especially after 18 months! Were you bored that you were trawling old questions? I thought I fully understood the question, and provided a response to fit......if it wasn't what they wanted, well so be it. Have a nice day :)
BillWoodruff 18-Feb-12 2:23am    
Dave, first ... I have no idea why ... this question showed up as current when I looked at QA questions today; I do not have time to "trawl" for old questions :)

Second, I should have qualified my comment to the OP (which is now revised), that you did answer exactly his first question, and that my comments were meant to apply to other issues raised by the OP in a comment (that he, by mistake, posted as an "answer").

So, my apologies to you ! I voted your answer a #5 because you did give a perfectly valid answer to the original question as asked: and the the OP should have accepted it !

I'm totally baffled by how this question showed up as current as of today or yesterday !
DaveAuld 18-Feb-12 2:29am    
Why did it show up you ask, probably just one of those mysterious things that happen from time to time.........no harm done, and if you thought I was having a dig, sorry, I wasn't just some light hearted 06.30am saturday morning banter. Need it to survive while at work :)
BillWoodruff 18-Feb-12 2:57am    
Hi Dave, not to worry I was only temporarily "mortified" :) Banter is a vitamin we all need !

best, Bill
I think the below might be of some help to someone, since it worked very finely for me...

VB
Protected Overloads Overrides Sub WndProc(ByRef m As Message)
    'Define DoubleClick...
    Const WM_NCLBUTTONDBLCLK As Integer = &HA3
    'Define LeftButtonDown event...
    Const WM_NCLBUTTONDOWN As Integer = 161
    'Define MOVE action...
    Const WM_SYSCOMMAND As Integer = 274
    'Define that the WM_NCLBUTTONDOWN is at TitleBar...
    Const HTCAPTION As Integer = 2
    'Trap MOVE action...
    Const SC_MOVE As Integer = 61456
    'Disable moving TitleBar...
    If (m.Msg = WM_SYSCOMMAND) AndAlso (m.WParam.ToInt32() = SC_MOVE) Then
        Exit Sub
    End If
    'Track whether clicked on TitleBar...
    If (m.Msg = WM_NCLBUTTONDOWN) AndAlso (m.WParam.ToInt32() = HTCAPTION) Then
        Exit Sub
    End If
    'Disable double click on TitleBar...
    If (m.Msg = WM_NCLBUTTONDBLCLK) Then
        Exit Sub
    End If
    MyBase.WndProc(m)
End Sub


Thanks guys
 
Share this answer
 
Comments
BillWoodruff 17-Feb-12 23:35pm    
Glad this works for you, Ravi, but do note your solution is in VB, and this question is tagged C#.
Try this:
C#
private void Form1_Resize(object sender, EventArgs e)
    {
    if (WindowState == FormWindowState.Maximized)
        {
        WindowState = FormWindowState.Normal;
        }
    }
The only slight hassle is that it may flicker: the window will be maximized briefly, and then returned to normal.
 
Share this answer
 
I have already used ur above suggestion
I want to prevent

private void Form1_Resize(object sender, EventArgs e)
private void MainForm_SizeChanged(object sender, EventArgs e)




both events
 
Share this answer
 
Comments
DaveAuld 9-Nov-10 13:22pm    
This is not an Answer; use the add comment feature below the answer you want to respond to.
BillWoodruff 17-Feb-12 23:31pm    
Let me agree with Dave's wise advice to you, Priya, that putting a reply/comment as a comment on the solution you are replying to is an important part of making QA clear to all readers. When multiple solutions are being posted, it's important to know exactly what solution you are responding to.

Dave really did answer your original question, as asked, and the comments you make here bring up other issues which you should clarify. You should have accepted Dave's answer.
Dear BillWoodRuff,

Really fell sorry great degree of misunderstanding.

Given below the same routine in C#...

C#
protected override void WndProc(ref Message m)
    {
         // Define DoubleClick...
         const int WM_NCLBUTTONDBLCLK = 163;
         // Define LeftButtonDown event...
         const int WM_NCLBUTTONDOWN = 161;
         // Define MOVE action...
         const int WM_SYSCOMMAND = 274;
         // Define that the WM_NCLBUTTONDOWN is at TitleBar...
         const int HTCAPTION = 2;
         // Trap MOVE action...
         const int SC_MOVE = 61456;
         // Disable moving TitleBar...
         if (((m.Msg == WM_SYSCOMMAND) 
                     && (m.WParam.ToInt32() == SC_MOVE))) {
             return;
         }
         // Track whether clicked on TitleBar...
         if (((m.Msg == WM_NCLBUTTONDOWN) 
                     && (m.WParam.ToInt32() == HTCAPTION))) {
             return;
         }
         // Disable double click on TitleBar...
         if ((m.Msg == WM_NCLBUTTONDBLCLK)) {
             return;
         }
         base.WndProc(m);
    }


Hope this will be appreciated (at least to boost myself).

Thanks and Regards,
G. Ravikumar
 
Share this answer
 
Comments
Jakub Marczewski 21-May-13 17:59pm    
Very appreciated .. thx.. you may feel boosted! ( also WM_NCRBUTTONDOWN = 0x00A4 for r-click )

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900