I am using c# language with windows form. I open the child form on top of the main windows form. Is there a simple way to turn off the draggable feature in both forms? Or is it possible to move it at the same time as the main form?
Loading
I am using c# language with windows form. I open the child form on top of the main windows form. Is there a simple way to turn off the draggable feature in both forms? Or is it possible to move it at the same time as the main form?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Amit MohantyPosted Feb 12, 2024, 6:40 AM
Hey Mehmet Fatih, add the WndProc method in code behond file of your child forms.
Mehmet FatihPosted Feb 12, 2024, 7:26 AM
Thanks Amit.
Mehmet FatihPosted Feb 12, 2024, 6:34 AM
Thanks Amit. How can we add reference to it?
Amit MohantyPosted Feb 12, 2024, 5:56 AM
Use below function in your child form to non draggable.
Sam HobbsPosted Feb 12, 2024, 2:35 AM
Read the cocumentation. There are values you can use for
FormBorderStyle. I was not sure what you meant by not draggable. I could not be sure that you meant that you wanted the child form to not be draggable outside the main form.Mehmet FatihPosted Feb 11, 2024, 7:32 PM
Thank you Sam. I had tried it before but it didn't solve the problem. The child form is still draggable.
Sam HobbsPosted Feb 11, 2024, 5:07 PM
No, the child form is not owned by the main form. You need to use
frm.ShowDialog();to get the child form owned by the main form. Or you can use the Owner property. However that is not likely to solve the problem.MDI is called Multiple-Document Interface. It is designed to support multiple documents, not multiple windows. When MDI is used for multiple general-purpose windows there are problems.
See the following article.
C# Create Child Forms | coding.vision
https://codingvision.net/c-create-child-forms
You can start with that and modify it as needed. The following shows the code from that article with some modifications. The commented out portions are suggestions, you can choose one of the values for `FormBorderStyle`. Since you are not specific with the requirements I cannot be specific with a solution.
Mehmet FatihPosted Feb 11, 2024, 9:49 AM
Thanks for your intrest Sam. Yes, the child form is owned by the main form. I am using it like that
VeliGorusmeF frm = new VeliGorusmeF();
frm.ShowDialog();
I am using MDI but I am openeing the child forms over the main form not inside it.
Sam HobbsPosted Feb 11, 2024, 2:23 AM
I assume you are not using
MDIbut if you are then please say so. If the following does not apply then you probably need to be more specific about what you are doing.Is the child form owned by the main form? When you show the form are you using
Show()orShow(this)?