简体   繁体   中英

How to make a object transparent in windows forms app

I have a simple use case. I have a preview window on which I am displaying a usb webcam. Now this preview window is not clickable ie does not detect on click event. As result I want to put a transparent object on top of this preview window. So that I can add on click event to it. Is there a way to make any object truly transparent so that it display whatever is going on behind it ?

I had a similar problem to this. Solved my problem but might not yours.

I used: Timer interval was 30ms. Picture Box Camera Feed.

I had a timer and on every tick i set it to capture the image from the webcam feed and sent it to a picture box and set the captured image to the picturebox.Image. The picture box filled the view to act as a preview window.

I had click event on the picture box which then let me click on the view and then proceed.

You can hook into your LiveDeviceSource to catch the messages sent to it using this technique:

public class Form1 : Form { 
   public Form1(){
      InitializeComponent();
      proc = new LiveDeviceSourceProc();
      Load += (s,e) => {            
         proc.AssignHandle(yourLiveDeviceSource.Handle);
      }; 
      proc.Click += (s,e) => {
         //you can also process your code here
      };
   }
   LiveDeviceSourceProc proc;
   public class LiveDeviceSourceProc : NativeWindow {
     protected override void WndProc(ref Message m){
        if(m.Msg == 0x202)//WM_LBUTTONUP   <=> Left Mouse Click
        {
            //process your code here
            if(Click != null) Click(this,EventArgs.Empty);
        }
        base.WndProc(ref m);
     }
     public event EventHandler Click;
   }
}

First of all, in your form, you have Enabled property, and you can do:

this.Enabled = false;

to make the entire form disabled.

Second, but not recommended, you can create your own transparent control - read about it here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM