Im done with my application im making and now just tidying up little bits before i release it for beta but one problem ive came across that i can't work out or find on the internet to fix is:
I Have a About Form and a Change Log form which get selected from the Help Menu.
How can i make it so when i click on the forms it locks them so people cant click on the main form and have to click ok to close the form before they can use the main form again rather then them clicking on the main form and hiding the about and change log form.
If you can just give me a link to somewhere where i can read about it. would be great not asking to do my code unless it just 1 line.
Regards
Richard
15 Replies - 9063 Views - Last Post: 18 July 2009 - 02:12 PM
Replies To: Make Form always on top and can't Focus off
#2
Re: Make Form always on top and can't Focus off
Posted 17 July 2009 - 07:48 AM
to be on top of other app you can put the code below in your form load event
not sure about the focus thing
if i helped you can thank me by clicking the button below saying that this post was helpful for you
this.TopMost = true;
not sure about the focus thing
if i helped you can thank me by clicking the button below saying that this post was helpful for you
This post has been edited by Bocard: 17 July 2009 - 07:49 AM
#3
Re: Make Form always on top and can't Focus off
Posted 17 July 2009 - 09:58 AM
You can use ShowDialog() for showing the form and checking user's input:
MyForm:
It's important to set the DialogResult property of button so the main form knows what DialogResult is returned.
MyForm frm = new MyForm(); if (frm.ShowDialog() == DialogResults.OK) // continue to main form else // close application or something
MyForm:
public partial class MyForm : Form {
public MyForm() {
InitializeComponent();
btnOK.DialogResult = DialogResult.OK;
}
}
It's important to set the DialogResult property of button so the main form knows what DialogResult is returned.
#4
Re: Make Form always on top and can't Focus off
Posted 17 July 2009 - 10:00 AM
i don't think this solves the "form which can't lose focus" problem..
#5
Re: Make Form always on top and can't Focus off
Posted 17 July 2009 - 11:53 AM
Well, it solves it within the current application: you can't click main window if there is another window shown as dialog. And that's what OP was looking for: not being able to focus on main form.
#6
Re: Make Form always on top and can't Focus off
Posted 17 July 2009 - 11:55 AM
janne_panne, on 17 Jul, 2009 - 07:53 PM, said:
Well, it solves it within the current application: you can't click main window if there is another window shown as dialog. And that's what OP was looking for: not being able to focus on main form.
oh, sorry. i thought he wanted not to be able to lose focus at all from his form.
#7
Re: Make Form always on top and can't Focus off
Posted 17 July 2009 - 12:35 PM
i dont want it be be able to lose focus like on certian applications when you click say the about form and you cant do anything else on the main form till you click ok on the about form. ive got the form popping up and closing you btnOK to close the window. but someone can just load up the about form and then click back on the main form and continue what they were doing which makes the about form hide behind the main form
#8
Re: Make Form always on top and can't Focus off
Posted 17 July 2009 - 01:01 PM
there must be an event that fires when the form loses focus.
just put this.TopMost = true; in that event
if there is no event you can make another thread run a loop and set the form topmost, and pause for a few miliseconds so your not using a billion cpu
if this.TopMost = true doesnt work, use the SetForegroundWindow api
just put this.TopMost = true; in that event
if there is no event you can make another thread run a loop and set the form topmost, and pause for a few miliseconds so your not using a billion cpu
if this.TopMost = true doesnt work, use the SetForegroundWindow api
This post has been edited by firexware: 17 July 2009 - 01:02 PM
#9
Re: Make Form always on top and can't Focus off
Posted 17 July 2009 - 01:01 PM
If you want it to stay on top all the time, then go to the properties bar on the form designer and change "TopMost" to True.
As for not being able to click anything else, I think putting everything in a DialogBox would be easiest, but that's just one opinion.
As for not being able to click anything else, I think putting everything in a DialogBox would be easiest, but that's just one opinion.
#10
Re: Make Form always on top and can't Focus off
Posted 17 July 2009 - 01:15 PM
I think you need a modal dialog box.
#11
Re: Make Form always on top and can't Focus off
Posted 17 July 2009 - 02:56 PM
is it me or are you guys just repeating what other users said before?
might be me it's past midnight here..00:56..i'm really tired
might be me it's past midnight here..00:56..i'm really tired
#12
Re: Make Form always on top and can't Focus off
Posted 17 July 2009 - 05:21 PM
Just to clarify. If you want a form, like the OpenDialogForm that when it opens the user can not switch back to the original window, all you have to do is what janne_panne said. You use ShowDialog instead of Show. ShowDialog creates a modal form for the application. The user has to close it before they can get back to working in the original window.
#13
Re: Make Form always on top and can't Focus off
Posted 18 July 2009 - 05:21 AM
#14
Re: Make Form always on top and can't Focus off
Posted 18 July 2009 - 05:52 AM
sry, my first language is not english, what i thought he needed was so nothing can be focused unless the user does sth in that form. not just inside his app.
#15
Re: Make Form always on top and can't Focus off
Posted 18 July 2009 - 05:56 AM
For my about screens I use .ShowDialog() and call this.BringToFront() when the form is shown so it blinks the application window in the task bar. It seems like you're trying to make this dialog very noticeable so perhaps that will help
|
|

New Topic/Question
Reply




MultiQuote







|