I am designing a small application in which I open a new form with some controls. I want to close this form if idle for some time. Let say the form is having many buttons, scroll bars, picture box....if none of them is clicked (within 10 seconds) the form should close.   I have used a timer of 10 seconds , i want to reset it if any of the control is pressed. I can do it individually but would become very cumbersome doing it for all the controls. Can i do it by some simpler way....I read on net:  foreach (Control cc in Controls)   but didn't knew how to use it. Please help.
60113
I have a .NET UserControl (FFX 3.5).  This control contains several child Controls - a Panel, a couple Labels, a couple TextBoxes, and yet another custom Control.  I want to handle a right click anywhere on the base Control - so a right click on any child control (or child of a child in the case of the Panel).  I'd like to do it so that it's maintainable if someone makes changes to the Control without having to wire in handlers for new Controls for example.  First I tried overriding the WndProc, but as I suspected, I only get messages for clicks on the Form directly, not any of its children.  As a semi-hack, I added the following after InitializeComponent:    foreach (Control c in this.Controls)   {     c.MouseClick += new MouseEventHandler(       delegate(object sender, MouseEventArgs e)       {         // handle the click here       });   }   This now gets clicks for controls that support the event, but Labels, for example, still don't get anything.  Is there a simple way to do this that I'm overlooking?
123225
I'm looking for something like alert(), but that doesn't "pause" the script.  I want to display an alert and allow the next command, a form submit(), to continue. So the page will be changing after the alert is displayed, but it won't wait till the user has clicked OK.  Is there something like this or is it just one of those impossible things?
14311
We have a few different forms as part of a web-based medical application. These forms have quite a few fields - 10-20 depending on the form. Each has at least 5 or so required fields. We currently disable the save button until those required fields are all completed.  We've been debating whether it's a better user experience to make the submit button enabled by default and then display an error message (and highlight missing required fields) if the submit button is clicked before all required fields are filled out.  Any research or sound opinions on what might be better? We're leaning towards the latter approach since our forms are pretty long -- allowing them to submit then find errors might be more efficient than the cognitive load of searching through the form to see why the button isn't enabled.
46962
Is there some easy way to handle multiple submit buttons from the same form? For example:  &lt;% Html.BeginForm("MyAction", "MyController", FormMethod.Post); %&gt; &lt;input type="submit" value="Send" /&gt; &lt;input type="submit" value="Cancel" /&gt; &lt;% Html.EndForm(); %&gt;   Any idea how to do this in ASP.NET Framework Beta? All examples I've googled for have single buttons in them.
18334
Take the following C# class:  c1 {  event EventHandler someEvent; }   If there are a lot of subscriptions to c1's someEvent event and I want to clear them all, what is the best way to achieve this? Also consider that subscriptions to this event could be/are lambdas/anonymous delegates.  Currently my solution is to add a ResetSubscriptions() method to c1 that sets someEvent to null. I don't know if this has any unseen consequences.
749
I have a scenario. (Windows Forms, C#, .NET)   There is a main form which hosts some user control. The user control does some heavy data operation, such that if I directly call the UserControl_Load method the UI become nonresponsive for the duration for load method execution. To overcome this I load data on different thread (trying to change existing code as little as I can)   I used a background worker thread which will be loading the data and when done will notify the application that it has done its work.   Now came a real problem. All the UI (main form and its child usercontrols) was created on the primary main thread. In the LOAD method of the usercontrol I'm fetching data based on the values of some control (like textbox) on userControl.    The pseudocode would look like this:  CODE 1  UserContrl1_LoadDataMethod() {     if (textbox1.text == "MyName") // This gives exception     {         //Load data corresponding to "MyName".         //Populate a globale variable List&lt;string&gt; which will be binded to grid at some later stage.     } }   The Exception it gave was     Cross-thread operation not valid: Control accessed from a thread other than the thread it was created on.   To know more about this I did some googling and a suggestion came up like using the following code  CODE 2  UserContrl1_LoadDataMethod() {     if (InvokeRequired) // Line #1     {         this.Invoke(new MethodInvoker(UserContrl1_LoadDataMethod));         return;     }      if (textbox1.text == "MyName") // Now it wont give an exception     {     //Load data correspondin to "MyName"         //Populate a globale variable List&lt;string&gt; which will be binded to grid at some later stage     } }   BUT BUT BUT... it seems I'm back to square one. The Application again  become nonresponsive. It seems to be due to the execution of line #1 if condition. The loading task is again done by the parent thread and not the third that I spawned.  I don't know whether I perceived this right or wrong. I'm new to threading.  How do I resolve this and also what is the effect of execution of Line#1 if block?  The situation is this: I want to load data into a global variable based on the value of a control. I don't want to change the value of a control from the child thread. I'm not going to do it ever from a child thread.   So only accessing the value so that the corresponding data can be fetched from the database.
31322
I am working with a basic  which is a popular modal used on many sites. I noticed that the default template comes with both a close button on the bottom, as well as an x on the top, these two buttons essentially having the same purpose. Are the two redundant and the close button completely unnecessary and just taking up extra space? Or, is having multiple usage options more user friendly?   To make this even more fun, suppose I throw in a Save button:   Is it now clearer that if you don't press save and just press the x, your changes will be canceled, or is there now more of a need for a cancel button for users who are scared that a mistake will become permanent? Update: To clarify for those who feel this question is similar to  - That question is asking if a clickable background is sufficient to close a popup. I'm using buttons and it is just a matter of how many buttons to use. (I do also have a clickable overlay and ESC key enabled, but that is irrelevant to my question)
63471
What do you do to pass information between forms?  Forward is straight forward (sorry) using Properties or maybe parameters in a New() or DoStuff() method, but what about sending something back when the user is done with the second form?  (IE. ID of the item selected) We have used all these:   Passed the calling form into the called form as a ref so the called form could access properties or methods on the calling form.  I really don't like this because the two forms are very dependent of each other.  Passing the calling form as a object only slightly improves this. Use Events This somewhat decouples the code, but the signatures must match on the event handler. Use an Public Interface I'm talking about the .NET built in one, but I suppose you could create your own.  This seems like the best to me.   Now raise the bar, what if the forms are in two different DLLs?  As long as the forms are not dependent on each other, I would think this wouldn't be a big step.
42370
What is the most recommended/best way to stop multiple instances of a setTimeout function from being created (in javascript)?  An example (psuedo code):  function mouseClick() {    moveDiv("div_0001", mouseX, mouseY); }  function moveDiv(objID, destX, destY) {    //some code that moves the div closer to destination    ...    ...    ...     setTimeout("moveDiv(objID, destX, destY)", 1000);    ...    ...    ... }   My issue is that if the user clicks the mouse multiple times, I have multiple instances of moveDiv() getting called.  The option I have seen is to create a flag, that only allows the timeout to be called if no other instance is available...is that the best way to go?  I hope that makes it clear....
5826
I am using the  plugin  I am looking for way to refresh the page when in some circumstances when the dialog is closed.  Is there a way to capture a close event from the dialog?  I know I can run code when the close button is clicked but that doesn't cover the user closing with escape or the x in the top right corner.
76867
Should you set all the objects to null (Nothing in VB.NET) once you have finished with them?   I understand that in .NET it is essential to dispose of any instances of objects that implement the IDisposable interface to release some resources although the object can still be something after it is disposed (hence the isDisposed property in forms), so I assume it can still reside in memory or at least in part?  I also know that when an object goes out of scope it is then marked for collection ready for the next pass of the garbage collector (although this may take time).  So with this in mind will setting it to null speed up the system releasing the memory as it does not have to work out that it is no longer in scope and are they any bad side effects?  MSDN articles never do this in examples and currently I do this as I cannot  see the harm. However I have come across a mixture of opinions so any comments are useful.
90856
Ok, I'm doing a bunch of RIA/AJAX stuff and need to create a "pretty", custom confirm box which is a DIV (not the built-in javascript confirm). I'm having trouble determining how to accomplish a pause in execution to give the user a chance to accept or decline the condition before either resuming or halting execution. (depending upon their answer)   So here's the general flow of logic I'm dealing with:   User selects an item from dropdown and clicks button. In client-side javascript eventhandler for button, I need to check a (this is the key) SERIES of conditions for the item they chose in dropdown.  These conditions could possibly result in not showing any confirmation at all or possibly only some of the conditions may evaluate to true which means I'll need to ask the user to accept or decline the condition before proceeding. Only one confirmation should be show at a time.   To demonstrate the logic:  function buttonEventHandler() {  if (condition1) {   if(!showConfirmForCondition1) // want execution to pause while waiting for user response.      return; // discontinue execution }  if (condition2) {   if (!showConfirmForCondition2) // want execution to pause while waiting for user response.       return; // discontinue execution }  if (condition3) {   if (!showConfirmForCondition3) // want execution to pause while waiting for user response.       return; // discontinue execution }  ...   }    If anybody has dealt with this challenge before and found a solution, help would be greatly appreciated. As a note, I'm also using the MS Ajax and jQuery libraries although I haven't found any functionality that may already be included in those for this problem.
11909
I'm developing an Windows Forms application that requires me to call a separate program to perform a task.  The program is a console application and I need to redirect standard output from the console to a TextBox in my program.    I have no problem executing the program from my application, but I don't know how to redirect the output to my application.  I need to capture output while the program is running using events.    The console program isn't meant to stop running until my application stops and the text changes constantly at random intervals.  What I'm attempting to do is simply hook output from the console to trigger an event handler which can then be used to update the TextBox.  I am using C# to code the program and using the .NET framework for development.  The original application is not a .NET program.  EDIT: Here's example code of what I'm trying to do.  In my final app, I'll replace Console.WriteLine with code to update the TextBox.  I tried to set a breakpoint in my event handler, and it isn't even reached.      void Method()     {         var p = new Process();         var path = @"C:\ConsoleApp.exe";          p.StartInfo.FileName = path;         p.StartInfo.UseShellExecute = false;         p.OutputDataReceived += p_OutputDataReceived;          p.Start();     }      static void p_OutputDataReceived(object sender, DataReceivedEventArgs e)     {         Console.WriteLine("&gt;&gt;&gt; {0}", e.Data);     }
96684
I am struggling with something that I think should be easily (ish).  I have a windows form and a flowgridlayout panel at the bottom of the form.  Inside this form I dynamically populate it with X number of User Controls.  The controls are all the same type.  The goal is when the user hoovers the mouse over the user control it opens another form and positions it where the mouse is.  When mouse leaves the form the opened form disappears.  This almost works great.  The problem is when the User Control has anything like a label or text box inside it.  It is considered to have left the UC so the form disappears.  My thought was then to use the X and Y to tell if it is inside the UC but I can not figure this out.  Can I ask:  1)  What is the best approach to this? 2)  How can I code it, as the UC's are dynamic I can not know exactly where they will be.  Thanks  EDIT  I am trying to figure out the mouse pointers but not getting there.  The code below is within the UC SmallTagBox_MouseLeave event:          Point loc = this.Location;         Point p = this.PointToScreen(this.Location);         Point p2 = this.PointToScreen(this.Parent.Location);          Point ms = MousePosition;         Rectangle screenBounds = new Rectangle(this.PointToScreen(this.Location), this.Size);         if (!screenBounds.Contains(ms))         {             thw.Close();             thw = null;         }    loc {X = 275 Y = 3} System.Drawing.Point p   {X = 808 Y = 908}   System.Drawing.Point p   {X = 808 Y = 908}   System.Drawing.Point p2  {X = 545 Y = 1542}  System.Drawing.Point ms  {X = 574 Y = 914}   System.Drawing.Point screenBounds    {X = 808 Y = 908 Width = 62 Height = 29}    System.Drawing.Rectangle   I do not understand how p2 (its parent) can have a greater Y value relative to the screen.
80656
I want do something like this:  Button btn1 = new Button(); btn1.Click += new EventHandler(btn1_Click); Button btn2 = new Button(); // Take whatever event got assigned to btn1 and assign it to btn2. btn2.Click += btn1.Click; // The compiler says no...   Where btn1_Click is already defined in the class:  void btn1_Click(object sender, EventArgs e) {     // }   This won't compile, of course ("The event 'System.Windows.Forms.Control.Click' can only appear on the left hand side of += or -="). Is there a way to take the event handler from one control and assign it to another at runtime? If that's not possible, is duplicating the event handler and assigning it to another control at runtime doable?  A couple of points: I have googled the heck out of this one for awhile and found no way of doing it yet. Most of the attempted approaches involve reflection, so if you read my question and think the answer is incredibly obvious, please try to compile the code in Visual Studio first. Or if the answer really is incredibly obvious, please feel free to slap me with it. Thanks, I'm really looking forward to seeing if this is possible.  I know I could just do this:  btn2.Click += new EventHandler(btn1_Click);   That's not what I'm looking for here.  This is also not what I'm looking for:  EventHandler handy = new EventHandler(btn1_Click); Button btn1 = new Button(); btn1.Click += handy; Button btn2 = new Button(); btn2.Click += handy;
2275
Is there an easy method to restore a minimized form to its previous state, either Normal or Maximized?  I'm expecting the same functionality as clicking the taskbar (or right-clicking and choosing restore).  So far, I have this, but if the form was previously maximized, it still comes back as a normal window.  if (docView.WindowState == FormWindowState.Minimized)     docView.WindowState = FormWindowState.Normal;   Do I have to handle the state change in the form to remember the previous state?
26624
I have a .NET 2.0 WinForms application with a ToolStrip on my main form. Sometimes, the ToolStrip icons don't respond to the first mouse click, so I have to click the icon twice. It's just a standard ToolStrip with several icons and tooltip texts, I don't do anything special. Is this common?