Copyright © 2013-2014 MultiMedia Soft

How to perform custom graphic rendering over the control's surface

Previous pageReturn to chapter overviewNext page

Although graphic features and customization possibilities should be already quite rich, at runtime you may have the need to add your own custom graphic rendering over the control's surface; this can be done in two ways:

 

by catching the WaveAnalyzerPaintDone event and by using the handle to the drawing device context passed as a parameter to the event management routine: this event is generated as soon as the rendering of the control has been completed; using this technique is generally faster but, due to the fact that the passed device context is the screen device context, it could cause some flicker.
by using the SetCustomPaintFunction method and providing your own drawing functionalities: this technique could be a little bit slower because the rendering is performed using double-buffering but the final result will be certainly better because it will be completely flicker free.

It's up to you deciding which of these techniques will better fit your needs.

 

Note that you have the possibility to use both of them at the same time but it's important to remember that the function provided through the call to the SetCustomPaintFunction method will be called before generating the WaveAnalyzerPaintDone event.

 

Let's see a sample that demonstrates how to paint a flicker free red ellipse over the button surface:

 

 

Visual Basic example

Write your own function like the one below:

Private Sub MyCustomPaint(ByVal hDC As Int32)

   Dim graphics As Graphics = Graphics.FromHdc(New IntPtr(hDC))

   graphics.FillEllipse(Brushes.Red, 50, 50, 100, 50)

End Sub

Supposing that you have instanced a member variable audioWaveformAnalyzer1 for one of our controls, you will have to call the following line:

 

audioWaveformAnalyzer1.SetCustomPaintFunction(AddressOf MyCustomPaint)

 

Note that you can call the SetCustomPaintFunction method from wherever you want, also passing different drawing function depending upon your rendering needs.

 

 

Visual C# example

Write your own function like the one below:

private void MyCustomPaint(Int32 hDC)

{

   Graphics graphics = Graphics.FromHdc((IntPtr) hDC);

   graphics.FillEllipse(Brushes.Red, 50, 50, 100, 50);

}

Supposing that you have instanced a member variable audioWaveformAnalyzer1 for one of our controls, you will have to call the following line:

 

audioWaveformAnalyzer1.SetCustomPaintFunction(MyCustomPaint);

 

Note that you can call the SetCustomPaintFunction method from wherever you want, also passing different drawing function depending upon your rendering needs.