Making custom (High performance) GUI elements.
-
Hello. I am fairly new to C# programming, (I am trying to teach myself), and I would like to know how to make custom (either WinForms, or WPF) components. The components that I am trying to make need to be fairly efficient, as I want to repaint them at least 30 times a second (with new data to display each time). I am fine with using unsafe code blocks if they are needed. The data that is going to be displayed is in the form of 1-dimensional HSL (Hue Saturation Luminescence) pixel data. I want to show a moving display of this data, a graphical FIFO stack (one that discards the first inputs upon overflow).
Working on a digital signal processing article. :) (My first article on this site)
-
Hello. I am fairly new to C# programming, (I am trying to teach myself), and I would like to know how to make custom (either WinForms, or WPF) components. The components that I am trying to make need to be fairly efficient, as I want to repaint them at least 30 times a second (with new data to display each time). I am fine with using unsafe code blocks if they are needed. The data that is going to be displayed is in the form of 1-dimensional HSL (Hue Saturation Luminescence) pixel data. I want to show a moving display of this data, a graphical FIFO stack (one that discards the first inputs upon overflow).
Working on a digital signal processing article. :) (My first article on this site)
There are two parts to this question. You don't actually need very much for a custom control if it is simply output, and in fact I'd be tempted just to use a PictureBox and catch Paint. The correct way to do it though would be to inherit from UserControl and override OnPaint. There's some information about how to write general custom controls in my LineEditor article[^] (scroll about half way down), but you probably don't need the user input parts. The second part is how to draw a 1 dimensional data series (if I'm understanding you correctly, that's just a stripe of pixels?) quickly. 30 fps still gives you 30ms per frame, though you don't want painting to take all of that (obviously), so my gut feeling is that you can just paint normally, with Graphics.FillRectangle, but it depends how many pixels are visible at once. If that is too slow, use one of the fast ways of mucking with bitmap data (a search for Bitmap.LockBits here on CP should find them) to put the frame data into a temporary buffer and then use Graphics.DrawImage to copy it to the control during the paint phase.
-
There are two parts to this question. You don't actually need very much for a custom control if it is simply output, and in fact I'd be tempted just to use a PictureBox and catch Paint. The correct way to do it though would be to inherit from UserControl and override OnPaint. There's some information about how to write general custom controls in my LineEditor article[^] (scroll about half way down), but you probably don't need the user input parts. The second part is how to draw a 1 dimensional data series (if I'm understanding you correctly, that's just a stripe of pixels?) quickly. 30 fps still gives you 30ms per frame, though you don't want painting to take all of that (obviously), so my gut feeling is that you can just paint normally, with Graphics.FillRectangle, but it depends how many pixels are visible at once. If that is too slow, use one of the fast ways of mucking with bitmap data (a search for Bitmap.LockBits here on CP should find them) to put the frame data into a temporary buffer and then use Graphics.DrawImage to copy it to the control during the paint phase.
Thanks! :thumbsup: Yes, you did understand the second part correctly. I have a sensor that is supplying data over ethernet that needs to be displayed on the screen. It reports intensity in HSL values, one strip at a time, kind of like a flatbed scanner. I am making a GUI element that displays this data in a waterfall like display (thus the FIFO stack).
Working on a digital signal processing article. :) (My first article on this site)