i am doing school project and its my first time using visual studio ,here is a small explanation...!
have log in,form, after click on button -log in- it leads me to main form with 4 buttons where i can go to 3 other forms and exit ...problem is that i need only to make some interactive exe file that will guide professor trough
my system (need to show him how my app will look like)..have some programming experience,and know how to pop-up some form on click ...main problem is that i don't know how to close that 1. log in form after i come to main form trough log in button or how to make program with next and back buttons
Thank you in advance.
give each form a Specific Tag then
class CloseTagedForm
{
public void ZatvoriTagovanuFormu(string myTag)
{
for (int i = Application.OpenForms.Count - 1; i >= 0; i--)//when you have to change the items you should do a reverse loop !
if (Application.OpenForms[i].Tag != null && Application.OpenForms[i].Tag.ToString() == myTag)
Application.OpenForms[i].Close();
}
}
you can close any form from any place in your code
Related
Trying to get the form in program by clicking menu item of an application
Tried this
menu = Application.OpenForms.Cast<Form>()...
Here, I got my control, then I went into menu items for eg, File > New
menu.AccessibilityObject.GetChild(0).GetChild(0).DoDefaultAction(); // void
Default action of this control - menu.AccessibilityObject.GetChild(0).GetChild(0) - is "press".
So, Calling this
menu.AccessibilityObject.GetChild(0).GetChild(0).DoDefaultAction(); // void
opens the form in actual application, but then program pauses until I close the form. (Closing the form continues the program execution (debugging) )
I want to execute the program when the form gets opened, I am not able to debug it because the form is opened and when I close it, I am able to debug next.
I want to get in the form and access the controls, Is there any way to achieve this ?
I searched myself through for about 1 hour only to realise that I might be the biggest beginner, but since everybody must have been at that point in a time, i hope for your patience.
My question: i have an empty Winform which is opened after a button is pressed on a custom created outlook properties button.
the button code:
private void FensterOeffnen(object sender, IRibbonControl control, bool pressed)
{
EinstellungenFenster fenster = new EinstellungenFenster();
fenster.ShowDialog();
}
the Winform code:
public partial class EinstellungenFenster : Form
{
public EinstellungenFenster()
{
InitializeComponent();
Text = "Outlook Add-in Einstellungen";
}
}
the Reason i need a checkbox:
i want to implement a popup (Debug so to say) window on each and every method that i have on my Outlook Add-in if the button is checked, so that if the code stopps working at a certain point after deployment, i can still easily tell where the problem is.
Thanks a lot!
Open the toolbox on vs by going to view and toolbox then expand all windows forms and scroll down to check-box and drag it on to the form.
and then implement the checked procedure by adding on the button clicked
if (Checkboxname.Checked = true)
{
// Do Stuff when checked
}
hope this helps
I want to make a windows form application that I can open multiple times.
When I click the "GO" button on the first form, I want the mouse to perform a series of clicks within the form (given by specific coordinates), while I still have control over the cursor using my hand-held mouse, so essentially there are 2 mice.
If I click the "GO" button on all forms, I want all the mice to perform a series of clicks within the corresponding form (all running in unison, not effecting one another), while I still have control over the hand-held mouse to do what I want I.E. browse the web.
Is this possible to do? IF so where would I start?
You can use PInvoke and call the SendInput API.
http://www.pinvoke.net/default.aspx/user32.sendinput
To the best of my knowledge it is impossible to have two mice on one windows system, if you simulate a click somewhere it normally moves the mouse to that location.
You can try the lib Wolfgang suggested or you can use the code from this question
As for it running multiple times you could just load up multiple threads all running the same code, like this:
static void Main(string[] args)
{
Thread[] threads = new Thread[5]; // replace 5 with how many times you want to run it.
for(int i = 0; i < threads.Length;i++)
{
threads[i] = new Thread(new ThreadStart(MyCode));
threads[i].Start();
}
}
static void MyCode()
{
//put code here
}
I have a large application with several forms, any of them could get a MessageBox (MessageBox.Show()) that is modal and locks the form.
On activation of another form I now need to find this MessageBox and bring the form that has this MessageBox to front. Is there any way to check this?
I know about the Application.OpenForms property, maybe there is something like this for MessageBox?
Edit1 : For example, say that we open Winform1, then a event in Winform1 will go to the mainController that opens Winform2. Lateron Winform1 is getting a MessageBox.Show, But its fully possible to bring Winform2 to front(above Winform1). So now I need to react to the Winform.Activated to check if there is any MessageBox.Show and if so, bring this form that holds the MessageBox to front.
You could find them by using Application.OpenForms like this:
foreach (Form f in Application.OpenForms)
{
if (f.Visible && ! f.CanFocus)
{
// whatever...
}
}
Or: use a different approach altogether:
Make all your forms handle Application.EnterThreadModal and Application.LeaveThreadModal, so that when the app goes modal while that form is current, you add that form onto a list so you can keep track of it, and remove it from the list when it leaves modal...
Then all you need to do is query that list to see if any forms have a modal dialog box open.
Try using one of the Show methods that takes an owner:
MessageBox.Show(this, "My Message");
I tested this on .NET 4 / Windows 7, and when the message box is opened it brings its owner to the front.
I'm aware that this title doesn't say much but it's really hart to explain what I want in few words.
I have two forms (main & help). Once I press button on main form help form pop ups. What I would like to implement is function to block user from doing anything on main form till he close help form.
I would not like to play with visible controls but I would like to have an effect you might have seen on some program that when user tries to click on main form help form "blinks" along with error sound playing. Once user close help form program works as usual
Hope you understand what I meant
This is called a modal dialog, and luckily, the answer is simple; show the child Form with the ShowDialog method instead of using Show. This is a blocking call that will not return until the child form/dialog is closed, so it means that you can check the return value and any properties if needed right after that line of code (probably not useful for a help window, but in most circumstances it is useful to check the user's action).
using( var dlg = new MyHelpDialog() )
{
if( dlg.ShowDialog() == DialogResult.OK )
{
// user chose "OK", do something (?)
// you can also access properties of the form after the fact
string whatever = dlg.SomeStringProperty;
}
}
You're looking for modal forms:
How to: Display Modal and Modeless Windows Forms
The thing you're talking about is called a "Modal Window".
See
How to: Display Modal and Modeless Windows Forms