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. Mesauring paint on a winforms panel

Mesauring paint on a winforms panel

Scheduled Pinned Locked Moved C#
questioncsharpwinforms
8 Posts 2 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.
  • B Offline
    B Offline
    Berlus
    wrote on last edited by
    #1

    Hello, How can I measure the time that controls are being painted on a panel ? Thanks, berlus

    L 1 Reply Last reply
    0
    • B Berlus

      Hello, How can I measure the time that controls are being painted on a panel ? Thanks, berlus

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      If I understand you correctly you have a Form, a Panel on that Form, and some Controls on the Panel. The Controls get painted whenever there is a need to, and you would like to measure how long it takes to paint them. Correct? I could explain how to get the measurement done (or what to change so it can be done), however I'd rather tell you that you asking this tells me (1) it is slow, and (2) you should fix that. Event handlers, including the Paint handler, should execute in a snap, never keeping the GUI thread busy (or waiting) for more than say 20 milliseconds, otherwise the GUI experience would be bad (e.g. a window covering most of your form, then disappearing, would take too long for everything to settle; or you dragging the Form by its title would not follow your mouse smoothly). I suggest you tell more about your current situation: which controls, showing what kind of data (and where it comes from), etc. Plus a detailed symptom description. :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


      Nil Volentibus Arduum


      B 1 Reply Last reply
      0
      • L Luc Pattyn

        If I understand you correctly you have a Form, a Panel on that Form, and some Controls on the Panel. The Controls get painted whenever there is a need to, and you would like to measure how long it takes to paint them. Correct? I could explain how to get the measurement done (or what to change so it can be done), however I'd rather tell you that you asking this tells me (1) it is slow, and (2) you should fix that. Event handlers, including the Paint handler, should execute in a snap, never keeping the GUI thread busy (or waiting) for more than say 20 milliseconds, otherwise the GUI experience would be bad (e.g. a window covering most of your form, then disappearing, would take too long for everything to settle; or you dragging the Form by its title would not follow your mouse smoothly). I suggest you tell more about your current situation: which controls, showing what kind of data (and where it comes from), etc. Plus a detailed symptom description. :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


        Nil Volentibus Arduum


        B Offline
        B Offline
        Berlus
        wrote on last edited by
        #3

        Thanks for your answer. I'm developing a GDI+ (can't use direct draw or open GL) framework, and i'm trying to decide between two alternatives to draw a certain symbol. In order to decide which method to use, i'm creating a PanelWithStopwatch (derived from Panel), and drawing on this panel the desired symbol. I want to use the stopwathc to measure the time that each panel was painted. I hope I have clarified the need for the performance test. Thanks, Berlus

        L 1 Reply Last reply
        0
        • B Berlus

          Thanks for your answer. I'm developing a GDI+ (can't use direct draw or open GL) framework, and i'm trying to decide between two alternatives to draw a certain symbol. In order to decide which method to use, i'm creating a PanelWithStopwatch (derived from Panel), and drawing on this panel the desired symbol. I want to use the stopwathc to measure the time that each panel was painted. I hope I have clarified the need for the performance test. Thanks, Berlus

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          I understood you had Controls on the Panel, now you say it is a symbol, so I'm still confused. If there are no listing controls involved (ListBox, TreeView, DataGridView) and no databases, I doubt it will take more than say one millisecond (unless you are messing with huge images, transparency, ...). Anyway, you could implement one way of painting things, then have a button click handler that contains:

          start stopwatch
          for (onethousand times) Panel.Refresh
          stop stopwatch

          This should repaint your panel all the time, whatever it contains. And then you could repeat it with your alternative way of painting things. When in doubt it really repaints every time, change it a bit, e.g. perform a TranslateTransform. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


          Nil Volentibus Arduum


          B 1 Reply Last reply
          0
          • L Luc Pattyn

            I understood you had Controls on the Panel, now you say it is a symbol, so I'm still confused. If there are no listing controls involved (ListBox, TreeView, DataGridView) and no databases, I doubt it will take more than say one millisecond (unless you are messing with huge images, transparency, ...). Anyway, you could implement one way of painting things, then have a button click handler that contains:

            start stopwatch
            for (onethousand times) Panel.Refresh
            stop stopwatch

            This should repaint your panel all the time, whatever it contains. And then you could repeat it with your alternative way of painting things. When in doubt it really repaints every time, change it a bit, e.g. perform a TranslateTransform. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


            Nil Volentibus Arduum


            B Offline
            B Offline
            Berlus
            wrote on last edited by
            #5

            Thanks, By symbol I mean a GDI+ drawings (such as pen, circle, etc). Do you have any suggestions on how to implement a panel with a textbox, that upon invalidation and repainting, that text box will be updated with the amount of time it took the panel to repaint itself ? Thanks, Berlus

            L 1 Reply Last reply
            0
            • B Berlus

              Thanks, By symbol I mean a GDI+ drawings (such as pen, circle, etc). Do you have any suggestions on how to implement a panel with a textbox, that upon invalidation and repainting, that text box will be updated with the amount of time it took the panel to repaint itself ? Thanks, Berlus

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              Hi, you need to be more accurate when explaining things; you first said Control, then symbol, now drawing; and a pen is not a drawing. I explained how to do it. Here is working code:

              	public void RunTimingTest() {
              		Form f=new Form();
              		Button btn=new Button();
              		btn.Text="Start";
              		btn.Click+=new EventHandler(btn\_Click);
              		btn.Bounds=new Rectangle(20, 20, 200, 40);
              		f.Controls.Add(btn);
              		lbl=new System.Windows.Forms.Label();
              		lbl.Bounds=new Rectangle(20, 80, 400, 30);
              		f.Controls.Add(lbl);
              		p=new MyPanel();
              		p.Bounds=new Rectangle(20, 150, 200, 100);
              		p.BackColor=Color.Yellow;
              		f.Controls.Add(p);
              		f.Show();
              	}
              
              	void btn\_Click(object sender, EventArgs e) {
              		p.Count=0;
              		lbl.Text="";
              		Stopwatch sw=new Stopwatch();
              		sw.Start();
              		int n=100\*r.Next(1, 10);
              		for (int i=0; i<n; i++) {
              			p.Text="MyPanel "+i.ToString();
              			p.Refresh();
              		}
              		sw.Stop();
              		lbl.Text="Did "+p.Count+" paints in "+sw.ElapsedMilliseconds+" msec";
              	}
              
              	public class MyPanel : Panel {
              		public int Count;
              		public string Text;
              
              		protected override void OnPaint(PaintEventArgs e) {
              			Count++;
              			base.OnPaint(e);
              			e.Graphics.DrawString(Text, Font, Brushes.Black, new Point(20, 20));
              		}
              	}
              

              The spoon feeding ends here. :|

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


              Nil Volentibus Arduum


              B 1 Reply Last reply
              0
              • L Luc Pattyn

                Hi, you need to be more accurate when explaining things; you first said Control, then symbol, now drawing; and a pen is not a drawing. I explained how to do it. Here is working code:

                	public void RunTimingTest() {
                		Form f=new Form();
                		Button btn=new Button();
                		btn.Text="Start";
                		btn.Click+=new EventHandler(btn\_Click);
                		btn.Bounds=new Rectangle(20, 20, 200, 40);
                		f.Controls.Add(btn);
                		lbl=new System.Windows.Forms.Label();
                		lbl.Bounds=new Rectangle(20, 80, 400, 30);
                		f.Controls.Add(lbl);
                		p=new MyPanel();
                		p.Bounds=new Rectangle(20, 150, 200, 100);
                		p.BackColor=Color.Yellow;
                		f.Controls.Add(p);
                		f.Show();
                	}
                
                	void btn\_Click(object sender, EventArgs e) {
                		p.Count=0;
                		lbl.Text="";
                		Stopwatch sw=new Stopwatch();
                		sw.Start();
                		int n=100\*r.Next(1, 10);
                		for (int i=0; i<n; i++) {
                			p.Text="MyPanel "+i.ToString();
                			p.Refresh();
                		}
                		sw.Stop();
                		lbl.Text="Did "+p.Count+" paints in "+sw.ElapsedMilliseconds+" msec";
                	}
                
                	public class MyPanel : Panel {
                		public int Count;
                		public string Text;
                
                		protected override void OnPaint(PaintEventArgs e) {
                			Count++;
                			base.OnPaint(e);
                			e.Graphics.DrawString(Text, Font, Brushes.Black, new Point(20, 20));
                		}
                	}
                

                The spoon feeding ends here. :|

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                Nil Volentibus Arduum


                B Offline
                B Offline
                Berlus
                wrote on last edited by
                #7

                Thanks for your answer, I will try to explaing myself better next time. I hope I won't vommit from your spoon , :).... Thanks, Berlus

                L 1 Reply Last reply
                0
                • B Berlus

                  Thanks for your answer, I will try to explaing myself better next time. I hope I won't vommit from your spoon , :).... Thanks, Berlus

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #8

                  Did you solve your problem? What is the outcome? :)

                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                  Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.

                  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