draw on transparent control over a mediaplayer
-
Hi! Im using a custom made doublebuffer transparent control over a mediaplayer-control. I would like to be able to pause the movie and then draw red marker rectangles on the transparent control. I would like to be able to see these rectangles while playing the movie. Everything works fine except for the last part, the rectangles dissappear as soon as I resume the movie. This is a test onPaint method in my transparent control: protected override void OnPaint(PaintEventArgs e) { if(_backBuffer==null) { _backBuffer=new Bitmap(this.ClientSize.Width,this.ClientSize.Height); } Graphics g=Graphics.FromImage(_backBuffer); //Copy the back buffer to the screen e.Graphics.DrawImageUnscaled(_backBuffer,0,0); // Get the graphics object Graphics gfx = e.Graphics; // Create a new pen that we shall use for drawing the line Pen myPen = new Pen(Color.Red); // Loop until the coordinates reach 250 (the lower right corner of the form) for(int i = 0; i < 250; i = i + 50) { // Draw a 50x50 pixels rectangle gfx.DrawRectangle(myPen, i, i, 50, 50); } g.Dispose(); gfx.Dispose(); } Any tips? THanks for your help /Rickard
-
Hi! Im using a custom made doublebuffer transparent control over a mediaplayer-control. I would like to be able to pause the movie and then draw red marker rectangles on the transparent control. I would like to be able to see these rectangles while playing the movie. Everything works fine except for the last part, the rectangles dissappear as soon as I resume the movie. This is a test onPaint method in my transparent control: protected override void OnPaint(PaintEventArgs e) { if(_backBuffer==null) { _backBuffer=new Bitmap(this.ClientSize.Width,this.ClientSize.Height); } Graphics g=Graphics.FromImage(_backBuffer); //Copy the back buffer to the screen e.Graphics.DrawImageUnscaled(_backBuffer,0,0); // Get the graphics object Graphics gfx = e.Graphics; // Create a new pen that we shall use for drawing the line Pen myPen = new Pen(Color.Red); // Loop until the coordinates reach 250 (the lower right corner of the form) for(int i = 0; i < 250; i = i + 50) { // Draw a 50x50 pixels rectangle gfx.DrawRectangle(myPen, i, i, 50, 50); } g.Dispose(); gfx.Dispose(); } Any tips? THanks for your help /Rickard
-
is the focus transfered to the movie when resuming try transControl.bringToFront() orit is refreshed ? ByMindOnlyYouCanDoIt
Hi! Thanks for your answer, bringToFront() makes no difference. refresh() does, but only temporary, it seems like i need to refresh the transControl continuously while the movie is playing, and I dont like that solution, also it makes the rectangles flicker. /Rickard
-
Hi! Thanks for your answer, bringToFront() makes no difference. refresh() does, but only temporary, it seems like i need to refresh the transControl continuously while the movie is playing, and I dont like that solution, also it makes the rectangles flicker. /Rickard
try to make the style of the control it self to this this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque,true); try this,this would make the control paint will be only in the paint OVERRIDED method and the second flag makes its background is the control that is lying behind it as it won't paint its own packground so now u won't need to make tha back color transparent also ByMindOnlyYouCanDoIt
-
try to make the style of the control it self to this this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque,true); try this,this would make the control paint will be only in the paint OVERRIDED method and the second flag makes its background is the control that is lying behind it as it won't paint its own packground so now u won't need to make tha back color transparent also ByMindOnlyYouCanDoIt
No wont work either, unless im doing something wrong, here´s my entire transpanel class: using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; public class TransPanel : Panel { private Bitmap _backBuffer; public TransPanel() { this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque,true); } protected override CreateParams CreateParams { get { CreateParams cp=base.CreateParams; cp.ExStyle|=0x00000020; //WS_EX_TRANSPARENT return cp; } } protected void InvalidateEx() { if(Parent==null) return; Rectangle rc=new Rectangle(this.Location,this.Size); Parent.Invalidate(rc,true); } protected override void OnPaint(PaintEventArgs e) { if(_backBuffer==null) { _backBuffer=new Bitmap(this.ClientSize.Width,this.ClientSize.Height); } Graphics g=Graphics.FromImage(_backBuffer); //Copy the back buffer to the screen e.Graphics.DrawImageUnscaled(_backBuffer,0,0); Font fnt = new Font("Verdana", 16); Graphics gf = e.Graphics; gf.DrawString("GDI+ World", fnt, new SolidBrush(Color.Red), 14,10); g.Dispose(); //base.OnPaint (e); //optional but not recommended } protected override void OnPaintBackground(PaintEventArgs pevent) { //do not allow the background to be painted } protected override void OnSizeChanged(EventArgs e) { if(_backBuffer!=null) { _backBuffer.Dispose(); _backBuffer=null; } base.OnSizeChanged (e); } }
-
Hi! Thanks for your answer, bringToFront() makes no difference. refresh() does, but only temporary, it seems like i need to refresh the transControl continuously while the movie is playing, and I dont like that solution, also it makes the rectangles flicker. /Rickard
It would seem that the Media Player is overwriting your boxes on top of it. This would be because the video that Media Player paints is being repainted, after your boxes are painted, with every frame of video. In other words, your constantly being painted over by the Media Player. I don't think your going to be able to get around this little problem considering Media Player paints (I think!) directly to the frame buffer, but I could be wrong. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
No wont work either, unless im doing something wrong, here´s my entire transpanel class: using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; public class TransPanel : Panel { private Bitmap _backBuffer; public TransPanel() { this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque,true); } protected override CreateParams CreateParams { get { CreateParams cp=base.CreateParams; cp.ExStyle|=0x00000020; //WS_EX_TRANSPARENT return cp; } } protected void InvalidateEx() { if(Parent==null) return; Rectangle rc=new Rectangle(this.Location,this.Size); Parent.Invalidate(rc,true); } protected override void OnPaint(PaintEventArgs e) { if(_backBuffer==null) { _backBuffer=new Bitmap(this.ClientSize.Width,this.ClientSize.Height); } Graphics g=Graphics.FromImage(_backBuffer); //Copy the back buffer to the screen e.Graphics.DrawImageUnscaled(_backBuffer,0,0); Font fnt = new Font("Verdana", 16); Graphics gf = e.Graphics; gf.DrawString("GDI+ World", fnt, new SolidBrush(Color.Red), 14,10); g.Dispose(); //base.OnPaint (e); //optional but not recommended } protected override void OnPaintBackground(PaintEventArgs pevent) { //do not allow the background to be painted } protected override void OnSizeChanged(EventArgs e) { if(_backBuffer!=null) { _backBuffer.Dispose(); _backBuffer=null; } base.OnSizeChanged (e); } }
The last thing that you can try is to make another thread to the control to draw in and don't make that in the paint method and use thread timers to make it infinite or as u wish u can make it as the lenght of the vedio in this method u cac write private void drawingMethod(object o) { //make this call at all the first this.BringToFront(); //and then call it agai and again (but in a separate thread)//the timer will make this separate thread for u or u can make an instance of the thread class ex. Thread urThread = new Thread(new ThreadStart(medothname)); } ByMindOnlyYouCanDoIt
-
Hi! Im using a custom made doublebuffer transparent control over a mediaplayer-control. I would like to be able to pause the movie and then draw red marker rectangles on the transparent control. I would like to be able to see these rectangles while playing the movie. Everything works fine except for the last part, the rectangles dissappear as soon as I resume the movie. This is a test onPaint method in my transparent control: protected override void OnPaint(PaintEventArgs e) { if(_backBuffer==null) { _backBuffer=new Bitmap(this.ClientSize.Width,this.ClientSize.Height); } Graphics g=Graphics.FromImage(_backBuffer); //Copy the back buffer to the screen e.Graphics.DrawImageUnscaled(_backBuffer,0,0); // Get the graphics object Graphics gfx = e.Graphics; // Create a new pen that we shall use for drawing the line Pen myPen = new Pen(Color.Red); // Loop until the coordinates reach 250 (the lower right corner of the form) for(int i = 0; i < 250; i = i + 50) { // Draw a 50x50 pixels rectangle gfx.DrawRectangle(myPen, i, i, 50, 50); } g.Dispose(); gfx.Dispose(); } Any tips? THanks for your help /Rickard
With this set: CreateParams cp=base.CreateParams; cp.ExStyle|=0x00000020; //WS_EX_TRANSPARENT You need to determine when to redraw the control. Windows will not let you know. Other then a timer constantly repainting you controls, I see only one .Net way. Remove your CreateParams for the control and use a custom shape to do what you want. Simply create a control that is a box with no center. I will try to upload an example in a few.
-
With this set: CreateParams cp=base.CreateParams; cp.ExStyle|=0x00000020; //WS_EX_TRANSPARENT You need to determine when to redraw the control. Windows will not let you know. Other then a timer constantly repainting you controls, I see only one .Net way. Remove your CreateParams for the control and use a custom shape to do what you want. Simply create a control that is a box with no center. I will try to upload an example in a few.
http://www.vivantlabs.com/Controls/BoxControl.zip This project has a control and a form showing it in use. This should help you do what you want.
-
http://www.vivantlabs.com/Controls/BoxControl.zip This project has a control and a form showing it in use. This should help you do what you want.