You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
transparent backgrounds for FormsPlot and WpfPlot #286
Hi @envine.
Your problem turned out to be more complicated than it seems at first glance.
Winforms have poor transparency support.
There is possible to simulate transparency for UserControl by some tricks:
Main problem is PictureBox which has it own implementation. I tryed to apply this tricks on it too, but unsuccessfully.
It's possible to remake FormsPlot control to not use PictureBox. plt.GetBitmap() manualy draw to control canvas in OnPaint method. @swharden can reveal the reasons why PictureBox is used now.
Anyway, there is no true transparency solution for Winforms. Can you describe a bit more about
problem which you actually want to solve. Do you want to place FormsPlot over another controls and see them, or something else?
Thanks @StendProg .
I just want to put FormsPlot on my main Form (System.Windows.Forms.Form) of the WinForm application.
The main Form has a BackgoundImage on it, and I want to make this image visible even over FormsPlot by setting the background of FormsPlot transparent.
It's possible to remake FormsPlot control to not use PictureBox. plt.GetBitmap() manualy draw to control canvas in OnPaint method. @swharden can reveal the reasons why PictureBox is used now.
@StendProg I think the reason I did this is because PictureBox has simple and robust support for double buffering. Drawing directly on the control may produce flickering. This is my understanding, but I haven't explored this topic in a while - if you are aware of a better way let me know!
@StendProg and @envine sorry about my confusing initial response. @StendProg described the solution very well. I updated the example, and the code explains itself:
This solution works only for Form background, any control hide under FormsPlot. As you explained there is only flicker ploblem you see in OnPaint render implementation. Maybe i will test this implementation later.
Thanks for your comment @swharden .
I understand the issue on complete transparency is not the matter of ScottPlot implementation.
And, thank you for merging the latest PR by @StendProg and adding nice demo for that.
It works as I expected.
Activity
StendProg commentedon Mar 7, 2020
Hi @envine.
Your problem turned out to be more complicated than it seems at first glance.
Winforms have poor transparency support.
There is possible to simulate transparency for
UserControlby some tricks:UserControlconstructorUserControlCreateParamsmethodMain problem is PictureBox which has it own implementation. I tryed to apply this tricks on it too, but unsuccessfully.
It's possible to remake
FormsPlotcontrol to not usePictureBox.plt.GetBitmap()manualy draw to control canvas inOnPaintmethod. @swharden can reveal the reasons whyPictureBoxis used now.Anyway, there is no true transparency solution for
Winforms. Can you describe a bit more aboutproblem which you actually want to solve. Do you want to place
FormsPlotover another controls and see them, or something else?envine commentedon Mar 7, 2020
Thanks @StendProg .
I just want to put
FormsPloton my mainForm(System.Windows.Forms.Form) of the WinForm application.The main
Formhas aBackgoundImageon it, and I want to make this image visible even overFormsPlotby setting the background ofFormsPlottransparent.StendProg commentedon Mar 7, 2020
If you need transparency only over
FormBackgroundImage:This will be possible after PR #287 will be merged. This PR set internal
pbPlt.BackColortogether withFormsPlot.BackColor.It will be look something like this (formsPlot overlap button control on right, but transparent over

BackgroundImage).envine commentedon Mar 7, 2020
Thank you very much @StendProg .
I have tested your PR, and it works perfectly!
Overriding
BackColorproperty ofPictureBoxused forFormPlotis enough for my use.Thank you again.
create transparent background WinForms demo
swharden commentedon Mar 7, 2020
@StendProg I think the reason I did this is because
PictureBoxhas simple and robust support for double buffering. Drawing directly on the control may produce flickering. This is my understanding, but I haven't explored this topic in a while - if you are aware of a better way let me know!simplify transparent background demo
swharden commentedon Mar 7, 2020
@StendProg and @envine sorry about my confusing initial response. @StendProg described the solution very well. I updated the example, and the code explains itself:
StendProg commentedon Mar 7, 2020
This solution works only for
Formbackground, any control hide underFormsPlot. As you explained there is only flicker ploblem you see inOnPaintrender implementation. Maybe i will test this implementation later.envine commentedon Mar 7, 2020
Thanks for your comment @swharden .
I understand the issue on complete transparency is not the matter of ScottPlot implementation.
And, thank you for merging the latest PR by @StendProg and adding nice demo for that.
It works as I expected.
add transparency support for WPF
[-]WinForms transparent background[/-][+]transparent backgrounds for FormsPlot and WpfPlot[/+]swharden commentedon Mar 7, 2020
For what it's worth, I added support (and a demo) for the WpfPlot control too.
It was hard to track down, but the only change needed was to modify the encoder for
bmp.Save:https://github.com/swharden/ScottPlot/blob/22e7e23e4a6bb8877a0a801ce1a9557e620ceba8/src/ScottPlot.WPF/WpfPlot.xaml.cs#L82-L92
create transparent background WinForms demo
simplify transparent background demo
add transparency support for WPF