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. Making custom (High performance) GUI elements.

Making custom (High performance) GUI elements.

Scheduled Pinned Locked Moved C#
csharpwpfwinformsdata-structuresperformance
3 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
    biojae
    wrote on last edited by
    #1

    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)

    B 1 Reply Last reply
    0
    • B biojae

      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)

      B Offline
      B Offline
      BobJanova
      wrote on last edited by
      #2

      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.

      B 1 Reply Last reply
      0
      • B BobJanova

        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.

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

        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)

        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