<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'gui in c#' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'gui in c#' posted on the 'C#' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Wed, 19 Jun 2013 07:33:13 -0700</pubDate>
    <lastBuildDate>Wed, 19 Jun 2013 07:33:13 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>gui in c#</title>
      <link>http://www.programmersheaven.com/mb/csharp/326660/326660/gui-in-c/</link>
      <description>hi i have gui with two buttons&lt;br /&gt;
&lt;br /&gt;
button1  button2&lt;br /&gt;
&lt;br /&gt;
when i press button1 the programs starts loop&lt;br /&gt;
&lt;br /&gt;
for (;)&lt;br /&gt;
dosomthing(var)&lt;br /&gt;
&lt;br /&gt;
i want to press button2 and then that var will be changed the problem is during the run the button 2 seems locked i want to press several time button2 and see thing changing &lt;br /&gt;
should i define somthing about button2 or for the gui&lt;br /&gt;
&lt;br /&gt;
thanks&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/csharp/326660/326660/gui-in-c/</guid>
      <pubDate>Mon, 16 Jan 2006 02:36:22 -0700</pubDate>
      <category>C#</category>
    </item>
    <item>
      <title>Re: gui in c#</title>
      <link>http://www.programmersheaven.com/mb/csharp/326660/326703/re-gui-in-c/#326703</link>
      <description>: hi i have gui with two buttons&lt;br /&gt;
: &lt;br /&gt;
: button1  button2&lt;br /&gt;
: &lt;br /&gt;
: when i press button1 the programs starts loop&lt;br /&gt;
: &lt;br /&gt;
: for (;)&lt;br /&gt;
: dosomthing(var)&lt;br /&gt;
: &lt;br /&gt;
: i want to press button2 and then that var will be changed the problem is during the run the button 2 seems locked i want to press several time button2 and see thing changing &lt;br /&gt;
: should i define somthing about button2 or for the gui&lt;br /&gt;
: &lt;br /&gt;
: thanks&lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;
As long as a loop is looping, the program will not respond, because the eventmessage loop(the code which handles MouseClick etc.; automatic generated) can't continue looping. You have to give your program time to react on events.&lt;br /&gt;
&lt;br /&gt;
I always use a Timer based loop:&lt;br /&gt;
- declare the variables used in the "for"-loop as privates of the Form.&lt;br /&gt;
- put the "dosomthing"-code in the Timer_Tick&lt;br /&gt;
&lt;br /&gt;
If the "dosomthing"-code needs no much time and you have to run the loop fast, you can also put the "dosomthing"-code between a "timestoper"-loop:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
object var = GIVEmeTHEstartVAR(); // your var classwide available

Timer.Interval = 1; // choose like you want

void Button1_Click()
{
    // start and stop the loop
    if(Timer.Enabled)
        Timer.Stop();
    else
        Timer.Start();
}

void Button2_Click()
{
    // change var even while loop is looping
    var = GIVEmeAotherVAR(var);
}

void Timer_Tick()
{
    // "timestoper"-loop, ends than "dosomething"-code ran enough for this step( 50 ms )
    DateTime DT = DateTime.Now;
    while((DateTime.Now - DT).TotalMilliseconds &amp;lt; 50)
    {
        DOsomething(var);
        DOevenMORE();
    }
    // the loop step ends and the program can respond to other events, like Button1_Click, Button2_Click or Form_Close
    // After Timer.Intervall-Milliseconds the Timer_Tick is going to run again
}
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Maybe there is a more elegant or difficult(multithreading) method, but this works and is fast.&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/csharp/326660/326703/re-gui-in-c/#326703</guid>
      <pubDate>Mon, 16 Jan 2006 08:37:05 -0700</pubDate>
      <category>C#</category>
    </item>
  </channel>
</rss>