How to turn device visibility on/off for Onvif discovery in C#

This example demonstrates in a really simple manner how you can set device visibility on/off for Onvif discovery. To implement this example, you must have OZEKI Camera SDK installed, and a reference to OzekiSDK.dll should be added to your Visual Studio project.

How to turn device visibility on/off for Onvif discovery using C#?

To establish the connection properly between your application and an IP camera you should apply the same code snippet you have used in the example (How to connect to an IP camera device using C#?). Important: you should study this article in order to find out how to setup your Windows Forms/WPF Application correctly.

Getting started

To get started it is recomended to Download and Install the latest version of Ozeki Camera SDK. After installation you can find the example code discussed in this page with full source code in the following location on your harddisk:

Download Ozeki Camera SDK:
Windows forms version: C:\Program Files\Ozeki\Ozeki SDK\\Examples\Other\
WPF version: C:\Program Files\Ozeki\Ozeki SDK\\Examples\Other\

To compile this example you will need Microsoft Visual Studio installed on your computer.

In addition to the methods discussed in the previous tutorials the additional methods of this example are the following:

When we click on the 'Connect' button the application should connect to the Onvif camera and then it's going to check whether the camera is visible or not:


The application is going to set the text of the GUI element in parallel with the previous processes. If the camera is visible the textbox's text will be 'Visible' and if it is not the text will be 'Not visible':


If the state of the checkbox has been changed, we'll change the device visibility as well:


Turning device visibility on/off for Onvif discovery in C#

Windows Form WPF  


using System;
using System.Drawing;
using System.Windows.Forms;
using Ozeki.Media;
using Ozeki.Camera;

namespace ConfigureOnvifCameraRemotely08
    public partial class Form1 : Form
        private IIPCamera _camera;
        private DrawingImageProvider _imageProvider;
        private MediaConnector _connector;
        private VideoViewerWF _videoViewerWf;

        public Form1()
            _connector = new MediaConnector();
            _imageProvider = new DrawingImageProvider();
            _videoViewerWf = new VideoViewerWF();

        private void SetVideoViewer()
            _videoViewerWf.Size = new Size(260, 180);
            _videoViewerWf.BackColor = Color.Black;
            _videoViewerWf.TabStop = false;
            _videoViewerWf.FlipMode = FlipMode.None;
            _videoViewerWf.Location = new Point(30, 30);
            _videoViewerWf.Name = "_videoViewerWf";

        private void button_Connect_Click(object sender, EventArgs e)
            _camera = new IPCamera("", "user", "qwe123");
            _camera.CameraStateChanged += _camera_CameraStateChanged;
            _connector.Connect(_camera.VideoChannel, _imageProvider);

        private void _camera_CameraStateChanged(object sender, CameraStateEventArgs e)
            if (e.State == CameraState.Connected)

        private void CheckVisibility()
            if (_camera.CameraInfo.Discoverable)
                InvokeGuiThread(() =>
                    checkBox_Visible.Text = "Visible";
                    checkBox_Visible.Checked = true;

                InvokeGuiThread(() =>
                    checkBox_Visible.Text = "Not visible";
                    checkBox_Visible.Checked = false;

        private void checkBox_Visible_CheckedChanged(object sender, EventArgs e)

        private void InvokeGuiThread(Action action)

Code 1 - Turning device visibility on/off for Onvif discovery in C#

Please note that none of the cancel and disconnect methods are included in the example because of the demonstrating intent and briefness of the article.


The Graphical User Interface of an application for turning camera visibility on/off for Onvif discovery in C#
Figure 1 - The graphical user interface of your application

After the successful implementation of the functions and the GUI elements, the application will work properly. Pressing the connect button will load the image of the IP camera device connected to your PC into the panel that you can see on the picture. Beside this you can click the checkbox which sets the visibility of the camera.

Below you can find the code that belongs to the interface of the previously presented application. With the help of this section your Windows Forms Application will be able to work properly.


	namespace ConfigureOnvifCameraRemotely08
	    partial class Form1
	        private System.ComponentModel.IContainer components = null;
	        protected override void Dispose(bool disposing)
	            if (disposing && (components != null))
	        private void InitializeComponent()
	            this.groupBox1 = new System.Windows.Forms.GroupBox();
	            this.button_Connect = new System.Windows.Forms.Button();
	            this.CameraBox = new System.Windows.Forms.GroupBox();
	            this.groupBox2 = new System.Windows.Forms.GroupBox();
	            this.checkBox_Visible = new System.Windows.Forms.CheckBox();
	            // groupBox1
	            this.groupBox1.Location = new System.Drawing.Point(10, 10);
	            this.groupBox1.Name = "groupBox1";
	            this.groupBox1.Size = new System.Drawing.Size(155, 60);
	            this.groupBox1.TabIndex = 0;
	            this.groupBox1.TabStop = false;
	            this.groupBox1.Text = "Connect";
	            // button_Connect
	            this.button_Connect.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
	            this.button_Connect.ForeColor = System.Drawing.Color.Black;
	            this.button_Connect.Location = new System.Drawing.Point(40, 20);
	            this.button_Connect.Name = "button_Connect";
	            this.button_Connect.Size = new System.Drawing.Size(75, 25);
	            this.button_Connect.TabIndex = 6;
	            this.button_Connect.Text = "Connect";
	            this.button_Connect.UseVisualStyleBackColor = true;
	            this.button_Connect.Click += new System.EventHandler(this.button_Connect_Click);
	            // CameraBox
	            this.CameraBox.Location = new System.Drawing.Point(10, 75);
	            this.CameraBox.Name = "CameraBox";
	            this.CameraBox.Size = new System.Drawing.Size(320, 230);
	            this.CameraBox.TabIndex = 3;
	            this.CameraBox.TabStop = false;
	            this.CameraBox.Text = "Live camera ";
	            // groupBox2
	            this.groupBox2.Location = new System.Drawing.Point(175, 10);
	            this.groupBox2.Name = "groupBox2";
	            this.groupBox2.Size = new System.Drawing.Size(155, 60);
	            this.groupBox2.TabIndex = 4;
	            this.groupBox2.TabStop = false;
	            this.groupBox2.Text = "Device visibility";
	            // checkBox_Visible
	            this.checkBox_Visible.AutoSize = true;
	            this.checkBox_Visible.Checked = true;
	            this.checkBox_Visible.CheckState = System.Windows.Forms.CheckState.Checked;
	            this.checkBox_Visible.Location = new System.Drawing.Point(50, 25);
	            this.checkBox_Visible.Name = "checkBox_Visible";
	            this.checkBox_Visible.Size = new System.Drawing.Size(56, 17);
	            this.checkBox_Visible.TabIndex = 0;
	            this.checkBox_Visible.Text = "Visible";
	            this.checkBox_Visible.UseVisualStyleBackColor = true;
	            this.checkBox_Visible.CheckedChanged += new System.EventHandler(this.checkBox_Visible_CheckedChanged);
	            // Form1
	            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
	            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
	            this.ClientSize = new System.Drawing.Size(339, 319);
	            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
	            this.MaximizeBox = false;
	            this.Name = "Form1";
	            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
	            this.Text = "Configuring Onvif Camera Visibility";
	        private System.Windows.Forms.GroupBox groupBox1;
	        private System.Windows.Forms.Button button_Connect;
	        private System.Windows.Forms.GroupBox CameraBox;
	        private System.Windows.Forms.GroupBox groupBox2;
	        private System.Windows.Forms.CheckBox checkBox_Visible;

Code 2 - GUI example in C#

DISCLAIMER: Please note that the following features will only work if your IP camera supports the given function. You should check the user manual of your IP camera to make sure it supports the feature that you wish to implement in C#.

Related Pages


Below you can find the answers for the most frequently asked questions related to this topic:

  1. How can I get the URL of the camera?

    You can get the URL from the producer of the camera. (In the 10th tutorial you can find information on how to create an own IP camera discoverer program.)

  2. I have not managed to build the solution. How to solve it?

    • Please set the Target framework property of the project to .NET 4.0.
    • You should add the System.Drawing.dll and the OzekiSDK.dll to the references of the solution.
    • Please import the missing classes.

Ozeki Camera Recorder

If you are not a developer, but you need a great software to view or record your camera, we recommend you to use Ozeki Camera Recorder. This is a great end user product, that allows you to control your cameras from a webbrowser. It's easy and great. You can download it from the following link: Download Ozeki Camera Recorder.

Download link:
Download Ozeki Camera Recorder for Windows

Copyright © 2000- - Ozeki Ltd |
Home > Online manual > Configure Onvif IP cam remotely > Set device visibility
Legal | Privacy | Terms of use | 6576 | | Login