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. draw on transparent control over a mediaplayer

draw on transparent control over a mediaplayer

Scheduled Pinned Locked Moved C#
graphicshelpquestioncareer
10 Posts 4 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.
  • S Offline
    S Offline
    spAAwn
    wrote on last edited by
    #1

    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

    M A 2 Replies Last reply
    0
    • S spAAwn

      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

      M Offline
      M Offline
      MoustafaS
      wrote on last edited by
      #2

      is the focus transfered to the movie when resuming try transControl.bringToFront() orit is refreshed ? ByMindOnlyYouCanDoIt

      S 1 Reply Last reply
      0
      • M MoustafaS

        is the focus transfered to the movie when resuming try transControl.bringToFront() orit is refreshed ? ByMindOnlyYouCanDoIt

        S Offline
        S Offline
        spAAwn
        wrote on last edited by
        #3

        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

        M D 2 Replies Last reply
        0
        • S spAAwn

          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

          M Offline
          M Offline
          MoustafaS
          wrote on last edited by
          #4

          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

          S 1 Reply Last reply
          0
          • M MoustafaS

            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

            S Offline
            S Offline
            spAAwn
            wrote on last edited by
            #5

            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); } }

            M 1 Reply Last reply
            0
            • S spAAwn

              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

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • S spAAwn

                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); } }

                M Offline
                M Offline
                MoustafaS
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                • S spAAwn

                  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

                  A Offline
                  A Offline
                  ACorbs
                  wrote on last edited by
                  #8

                  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.

                  A 1 Reply Last reply
                  0
                  • A ACorbs

                    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.

                    A Offline
                    A Offline
                    ACorbs
                    wrote on last edited by
                    #9

                    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.

                    S 1 Reply Last reply
                    0
                    • A ACorbs

                      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.

                      S Offline
                      S Offline
                      spAAwn
                      wrote on last edited by
                      #10

                      Thanks alot, I´ll look into it.

                      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