Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Time to draw 2 usercontrols on a form is depend on each other.

Time to draw 2 usercontrols on a form is depend on each other.

Scheduled Pinned Locked Moved C#
helpgraphics
15 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L LeHuuTien

    I want to redraw usercontrol 1 and usercontrol 2 follow cycle(usercontrol 1 and usercontrol 2 always redraw follow Timer.Interval of each control), so I use Timer.Elapsed event to do that. It draws line, text, ... Sorry for bad English.

    P Offline
    P Offline
    Pete OHanlon
    wrote on last edited by
    #6

    Perhaps if you could show us a cut down version of the paint code for both controls.

    L 1 Reply Last reply
    0
    • P Pete OHanlon

      Perhaps if you could show us a cut down version of the paint code for both controls.

      L Offline
      L Offline
      LeHuuTien
      wrote on last edited by
      #7

      usercontrol 1 will invoke 2 functions, one of it:

      public void DrawControl(Graphics g)
      {
      int X = 599;
      int Y = 10;
      int Width = 225;
      using (GraphicsPath path = GraphicsHelper.Create(X, Y, 224, 119, 5))
      {
      using (Pen frameWithBlackBgrd = new Pen(CWColors.FrameWithBlackBgrd))
      {
      g.DrawPath(frameWithBlackBgrd, path);
      }
      }

             if (GuiResInfoMng.Instance.Lang != null && GuiResInfoMng.Instance.Param != null)
             {
                 using (SolidBrush fixedTextWithBlackBgrd = new SolidBrush(CWColors.FixedTextWithBlackBgrd))
                 {
                     g.DrawString(GuiResInfoMng.Instance.Lang.GetStr(LangId.IDS\_COM\_TOTALCNT),
                         FontFactory.Instance.GetFont(LangId.FNT\_M2), fixedTextWithBlackBgrd, X, Y);
                     g.DrawString(GuiResInfoMng.Instance.Lang.GetStr(LangId.IDS\_COM\_PASS), FontFactory.Instance.GetFont(LangId.FNT\_M2),
                         fixedTextWithBlackBgrd, X, Y + 23);
                     g.DrawString(GuiResInfoMng.Instance.Lang.GetStr(LangId.IDS\_COM\_NG), FontFactory.Instance.GetFont(LangId.FNT\_M2),
                         fixedTextWithBlackBgrd, X - 1, Y + 46);
                 }
             }
      
             using (SolidBrush variableText = new SolidBrush(CWColors.VariableText))
             {
                 g.DrawString(ParamHelper.GetParamStr(ParamId.TOTALCOUNT).Trim(), FontFactory.Instance.GetFont(LangId.FNT\_M2), variableText, X + Width - 60, Y);
                 g.DrawString(ParamHelper.GetParamStr(ParamId.PASSCOUNT).Trim(), FontFactory.Instance.GetFont(LangId.FNT\_M2), variableText, X + Width - 60, Y + 23);
                 g.DrawString(ParamHelper.GetParamStr(ParamId.NGCOUNT).Trim(), FontFactory.Instance.GetFont(LangId.FNT\_M2), variableText, X + Width - 60, Y + 46);
             }
         }
      
      P 1 Reply Last reply
      0
      • L LeHuuTien

        usercontrol 1 will invoke 2 functions, one of it:

        public void DrawControl(Graphics g)
        {
        int X = 599;
        int Y = 10;
        int Width = 225;
        using (GraphicsPath path = GraphicsHelper.Create(X, Y, 224, 119, 5))
        {
        using (Pen frameWithBlackBgrd = new Pen(CWColors.FrameWithBlackBgrd))
        {
        g.DrawPath(frameWithBlackBgrd, path);
        }
        }

               if (GuiResInfoMng.Instance.Lang != null && GuiResInfoMng.Instance.Param != null)
               {
                   using (SolidBrush fixedTextWithBlackBgrd = new SolidBrush(CWColors.FixedTextWithBlackBgrd))
                   {
                       g.DrawString(GuiResInfoMng.Instance.Lang.GetStr(LangId.IDS\_COM\_TOTALCNT),
                           FontFactory.Instance.GetFont(LangId.FNT\_M2), fixedTextWithBlackBgrd, X, Y);
                       g.DrawString(GuiResInfoMng.Instance.Lang.GetStr(LangId.IDS\_COM\_PASS), FontFactory.Instance.GetFont(LangId.FNT\_M2),
                           fixedTextWithBlackBgrd, X, Y + 23);
                       g.DrawString(GuiResInfoMng.Instance.Lang.GetStr(LangId.IDS\_COM\_NG), FontFactory.Instance.GetFont(LangId.FNT\_M2),
                           fixedTextWithBlackBgrd, X - 1, Y + 46);
                   }
               }
        
               using (SolidBrush variableText = new SolidBrush(CWColors.VariableText))
               {
                   g.DrawString(ParamHelper.GetParamStr(ParamId.TOTALCOUNT).Trim(), FontFactory.Instance.GetFont(LangId.FNT\_M2), variableText, X + Width - 60, Y);
                   g.DrawString(ParamHelper.GetParamStr(ParamId.PASSCOUNT).Trim(), FontFactory.Instance.GetFont(LangId.FNT\_M2), variableText, X + Width - 60, Y + 23);
                   g.DrawString(ParamHelper.GetParamStr(ParamId.NGCOUNT).Trim(), FontFactory.Instance.GetFont(LangId.FNT\_M2), variableText, X + Width - 60, Y + 46);
               }
           }
        
        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #8

        That's the paint routine for one control, not two.

        L 1 Reply Last reply
        0
        • P Pete OHanlon

          That's the paint routine for one control, not two.

          L Offline
          L Offline
          LeHuuTien
          wrote on last edited by
          #9

          usercontrol 2 will invoke draw function:

          public void DrawGraph(Graphics g)
          {
          g.SmoothingMode = SmoothingMode.HighSpeed;
          //Draw background
          _frameXBar.DrawBackground(g, XbarPos);
          _frameNumber.DrawBackground(g, NumberPos);
          _frameRS.DrawBackground(g, RsPos);

                 //Draw XBar
                 DrawXBarBase(g);
                 DrawXbarGraph(g);
          
                 ////Draw RS
                 DrawRSBase(g);
                 DrawRSGraph(g);
          
                 ////Draw Number
                 DrawNumber(g);
             }
          

          DrawGraph function will call some function: Ex:

          private void DrawRSGraph(Graphics g)
          {
          if (IsAllLine)
          {
          if (IsR)
          {
          if (IsFullLine)
          {
          DrawPolyline(_dataAllLineRFullNumber, g, _frameRS.Width, _frameRS.Height, CalculateHeightRS, RsPos);
          }
          else
          {
          DrawPolyline(_dataAllLineRPassNumber, g, _frameRS.Width, _frameRS.Height, CalculateHeightRS, RsPos);
          }
          }
          else
          {
          if (IsFullLine)
          {
          DrawPolyline(_dataAllLineSFullNumber, g, _frameRS.Width, _frameRS.Height, CalculateHeightRS, RsPos);
          }
          else
          {
          DrawPolyline(_dataAllLineSPassNumber, g, _frameRS.Width, _frameRS.Height, CalculateHeightRS, RsPos);
          }
          }
          }
          else
          {
          if (IsR)
          {
          if (IsFullLine)
          {
          DrawPolyline(_dataForLineRFullNumber, g, _frameRS.Width, _frameRS.Height, CalculateHeightRS, RsPos);
          }
          else
          {
          DrawPolyline(_dataForLineRPassNumber, g, _frameRS.Width, _frameRS.Height, CalculateHeightRS, RsPos);
          }
          }
          else
          {
          if (IsFullLine)
          {
          DrawPolyline(_dataForLineSFullNumber, g, _frameRS.Width, _frameRS.Height, CalculateHeightRS, RsPos);
          }
          else
          {
          DrawPolyline(_dataForLineSPassNumber, g, _

          B 1 Reply Last reply
          0
          • L LeHuuTien

            usercontrol 2 will invoke draw function:

            public void DrawGraph(Graphics g)
            {
            g.SmoothingMode = SmoothingMode.HighSpeed;
            //Draw background
            _frameXBar.DrawBackground(g, XbarPos);
            _frameNumber.DrawBackground(g, NumberPos);
            _frameRS.DrawBackground(g, RsPos);

                   //Draw XBar
                   DrawXBarBase(g);
                   DrawXbarGraph(g);
            
                   ////Draw RS
                   DrawRSBase(g);
                   DrawRSGraph(g);
            
                   ////Draw Number
                   DrawNumber(g);
               }
            

            DrawGraph function will call some function: Ex:

            private void DrawRSGraph(Graphics g)
            {
            if (IsAllLine)
            {
            if (IsR)
            {
            if (IsFullLine)
            {
            DrawPolyline(_dataAllLineRFullNumber, g, _frameRS.Width, _frameRS.Height, CalculateHeightRS, RsPos);
            }
            else
            {
            DrawPolyline(_dataAllLineRPassNumber, g, _frameRS.Width, _frameRS.Height, CalculateHeightRS, RsPos);
            }
            }
            else
            {
            if (IsFullLine)
            {
            DrawPolyline(_dataAllLineSFullNumber, g, _frameRS.Width, _frameRS.Height, CalculateHeightRS, RsPos);
            }
            else
            {
            DrawPolyline(_dataAllLineSPassNumber, g, _frameRS.Width, _frameRS.Height, CalculateHeightRS, RsPos);
            }
            }
            }
            else
            {
            if (IsR)
            {
            if (IsFullLine)
            {
            DrawPolyline(_dataForLineRFullNumber, g, _frameRS.Width, _frameRS.Height, CalculateHeightRS, RsPos);
            }
            else
            {
            DrawPolyline(_dataForLineRPassNumber, g, _frameRS.Width, _frameRS.Height, CalculateHeightRS, RsPos);
            }
            }
            else
            {
            if (IsFullLine)
            {
            DrawPolyline(_dataForLineSFullNumber, g, _frameRS.Width, _frameRS.Height, CalculateHeightRS, RsPos);
            }
            else
            {
            DrawPolyline(_dataForLineSPassNumber, g, _

            B Offline
            B Offline
            BillWoodruff
            wrote on last edited by
            #10

            Hi, I'd like to suggest you now go back to your original question here and edit it so it includes the information/code you've shared. cheers, Bill

            «I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.

            1 Reply Last reply
            0
            • L LeHuuTien

              Hi all. I have a problem. really need some help. I have a form contains 2 usercontrols name: usercontrol 1 and usercontrol 2. I use System.Timers.Timer.Elapsed to redraw usercontrol 1 and usercontrol 2 follow interval(interval of usercontrol 1 = 100ms. interval of usercontrol 2 = 1000ms). I measure time to draw usercontrol 1 and usercontrol 2 and I realize that time to draw usercontrol 1 is increase when usercontrol 2 has been drawing, when usercontrol 2 complete, time to draw usercontrol 1 is decrease. Is there anyway to solve it(time to draw usercontrol 1 is stable, it's not depend on the drawing usercontrol 2).

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #11

              How many "cores" does your CPU have? Getting the most out of multi-threading (usually) requires multiple cores. You want control 1 to be "stable" ... What about control 2? If control 1 can be stable at the expense of control 2, then you could implement a "priority" system where control 1 is allowed to preempt control 2 (for drawing), but control 2 is not allowed to preempt control 1. There are various ways of blocking and testing for locks to accomplish this. Be aware that "drawing" has always been a fairly slow operation relative to compute time (that's why it is not wise to update a "progress bar" too frequently when it comes to critical operations). Also, 100ms is (usually) the limit at which a user can detect "lag" in a UI; you might consider raising the interval for control 1 to 200ms and checking the results. And, since the interval of control 2 is a multiple of control 1, you might consider using a single timer, and "dispatching" control 2 once for every n times control 1 is dispatched; i.e. dispatch either control 1 or 2, but not so that both are running at the same time (when redrawing).

              L 1 Reply Last reply
              0
              • L Lost User

                How many "cores" does your CPU have? Getting the most out of multi-threading (usually) requires multiple cores. You want control 1 to be "stable" ... What about control 2? If control 1 can be stable at the expense of control 2, then you could implement a "priority" system where control 1 is allowed to preempt control 2 (for drawing), but control 2 is not allowed to preempt control 1. There are various ways of blocking and testing for locks to accomplish this. Be aware that "drawing" has always been a fairly slow operation relative to compute time (that's why it is not wise to update a "progress bar" too frequently when it comes to critical operations). Also, 100ms is (usually) the limit at which a user can detect "lag" in a UI; you might consider raising the interval for control 1 to 200ms and checking the results. And, since the interval of control 2 is a multiple of control 1, you might consider using a single timer, and "dispatching" control 2 once for every n times control 1 is dispatched; i.e. dispatch either control 1 or 2, but not so that both are running at the same time (when redrawing).

                L Offline
                L Offline
                LeHuuTien
                wrote on last edited by
                #12

                Thank for your reply. My cpu has 2 core. The first I want control 1 to be stable, control 2 still not care. I measure time to draw control 1, AVG value = 15ms-> 20 ms, usually it ~ 10 ms, however when control 2 has been drawing, time to draw control 1 increase up to ~ 200ms. When control 2 complete it decrease down to ~ 10ms.(I want to both control are running at the same time, the drawing of controls is independence)

                L 1 Reply Last reply
                0
                • L LeHuuTien

                  Thank for your reply. My cpu has 2 core. The first I want control 1 to be stable, control 2 still not care. I measure time to draw control 1, AVG value = 15ms-> 20 ms, usually it ~ 10 ms, however when control 2 has been drawing, time to draw control 1 increase up to ~ 200ms. When control 2 complete it decrease down to ~ 10ms.(I want to both control are running at the same time, the drawing of controls is independence)

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #13

                  Your measurements seem to indicate that the controls cannot run at the same time if you expect control 1 to always draw at under 100ms without considering what control 2 is doing (or vice versa).

                  L 1 Reply Last reply
                  0
                  • L Lost User

                    Your measurements seem to indicate that the controls cannot run at the same time if you expect control 1 to always draw at under 100ms without considering what control 2 is doing (or vice versa).

                    L Offline
                    L Offline
                    LeHuuTien
                    wrote on last edited by
                    #14

                    I can confirm that both control are draw at the same time.

                    L 1 Reply Last reply
                    0
                    • L LeHuuTien

                      I can confirm that both control are draw at the same time.

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #15

                      "Should not" then.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups