469,916 Members | 2,115 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,916 developers. It's quick & easy.

Image Transparency in overlapping PictureBox objects.

I am making an application that streams video from a web camera onto the
client area of a PictureBox on a Windows CLR Form in MS Visual Studio 2005
(using C++).
The streaming video works fine, and now I am trying to create an image
I am assuming that the best way for me to do this is to create a second
PictureBox that lays over the streaming video. I would then need to draw
directly into the bitmap shown in the overlaying PictureBox and have most of
the pixels in that image be transparent (i.e. showing the streaming video
from the underlying picturebox). I have attempted to create a class called
myPictBox that inherits from PictureBox and overrides both the OnPaint and
OnPaintBackground methods, but I really don't know what I am doing. I think
what I want to do is essentially equivalent to the problem of creating a
nonrectangular custom control, though I will not need to respond to mouse
click events as a form control would.

Can anyone offer me any suggestions about this problem?
Am I on the right track, at least?

A stripped down version of how I think this should be solved is shown below
(as is suggested by an article in the MSDN forums). This code results in a
black rectangle overlaying my video stream.

------ File: MyPictBox.h ----------------------
pragma once
#pragma managed

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

namespace v1 {
public ref class MyPictBox: public PictureBox {
protected: virtual property CreateParams^ CreateParams {
CreateParams^ get () override {
CreateParams^ cp = __super::CreateParams;
cp->ExStyle |= 0x20; // WS_EX_TRANSPARENT
return cp;
protected: virtual void OnPaintBackground(PaintEventArgs^ pevent)
override {
// Don't paint the background.
protected: virtual void OnPaint(PaintEventArgs^ pe) override {
// Paint background image
if (this->BackgroundImage != nullptr) {
Bitmap^ bmp = gcnew Bitmap(this->BackgroundImage);
pe->Graphics->DrawImage(bmp, 0, 0);
// Draw opaque portion of control
Pen^ myPen = gcnew Pen(Color::Red,3.0f);
Point point1 = Point(0,50);
Point point2 = Point(50,50);
pe->Graphics->DrawLine(myPen, point1, point2);
delete myPen;
}; // class MyPictBox
} // namespace v1

Jul 28 '08 #1
0 2966

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Simon Harvey | last post: by
10 posts views Thread by Woody Splawn | last post: by
18 posts views Thread by Andrew Christiansen | last post: by
1 post views Thread by M West | last post: by
6 posts views Thread by Rlrcstr | last post: by
4 posts views Thread by ShieldsJared | last post: by
1 post views Thread by Marge | last post: by
8 posts views Thread by Linsolv | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.