ARTICLE

How to create a simple screen sharing application in C#

Posted by Ulricht Von Schnell Articles | Networking September 10, 2010
In this article we will see how to create a simple screen sharing application in C#.
Reader Level:
Download Files:
 

What you'll need:

A host application, and a viewer application

The host:
  1. Add reference, rdpcomapi 1.0 Type Library.

    (pic 4)add_ref.jpg

  2. Add using RDPCOMAPILib;

  3. Add this method

    private
    void Incoming(object Guest)
    {
        IRDPSRAPIAttendee MyGuest = (IRDPSRAPIAttendee)Guest;//???
        MyGuest.ControlLevel = CTRL_LEVEL.CTRL_LEVEL_INTERACTIVE;
    }

  4. Add this class level variable

    RDPSession x = new RDPSession();

Create three new buttons, and a textbox(dont rename the controls, make use of their default names)

Code:

First button:

private void button1_Click(object sender, EventArgs e)
{
    x.OnAttendeeConnected += Incoming;
    x.Open();
}

Second button:

private void button2_Click(object sender, EventArgs e)
{
    IRDPSRAPIInvitation Invitation = x.Invitations.CreateInvitation("Trial", "MyGroup", "", 10);
    textBox1.Text = Invitation.ConnectionString;
}

Third button:

private void button3_Click(object sender, EventArgs e)
{
    x.Close();
    x = null;
}

The viewer:
  1. Right click on toolbox and click Choose items... 

    (pic 1)choose_items.jpg

  2. In the dialog under COM components, check RDPViewer Class, and click OK

    (pic 2)new_items_toolbox.jpg

  3. Drag and Drop RDPViewer object onto form.

    (pic 3)rdpviewerobject.jpg
Create two new buttons, and a textbox.

Code:

First button:

private void button1_Click(object sender, EventArgs e)
{
    string Invitation = textBox1.Text;// "";// Interaction.InputBox("Insert Invitation ConnectionString", "Attention");
    axRDPViewer1.Connect(Invitation, "User1", "");
}

Second button:

private void button2_Click(object sender, EventArgs e)
{
    axRDPViewer1.Disconnect();
}

How to use:
  1. On host click button one, the start button
  2. On host click button two, the get invite button
  3. On host copy the text in the text box
  4. On viewer paste into text box
  5. On viewer click button one, the connect button
  6. To end click the finish button on either side

Full source code:

The viewer:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ScrS_viewer_
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            string Invitation = textBox1.Text;// "";// Interaction.InputBox("Insert Invitation ConnectionString", "Attention");
            axRDPViewer1.Connect(Invitation, "User1", "");
        }
        private void button2_Click(object sender, EventArgs e)
        {
            axRDPViewer1.Disconnect();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            panel1.Height = Screen.PrimaryScreen.Bounds.Height - 100;
        }
    }
}

The host:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using RDPCOMAPILib;

namespace ScrS_server_
{
    public partial class Form1 : Form
    {
        RDPSession x = new RDPSession();
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
        }
        private void Incoming(object Guest)
        {
            IRDPSRAPIAttendee MyGuest = (IRDPSRAPIAttendee)Guest;//???
            MyGuest.ControlLevel = CTRL_LEVEL.CTRL_LEVEL_INTERACTIVE;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            x.OnAttendeeConnected += Incoming;
            x.Open();
        }
        private void button2_Click(object sender, EventArgs e)
        {
            IRDPSRAPIInvitation Invitation = x.Invitations.CreateInvitation("Trial", "MyGroup", "", 10);
            textBox1.Text = Invitation.ConnectionString;
        }
        private void button3_Click(object sender, EventArgs e)
        {
            x.Close();
            x = null;
        }
    }
}

Login to add your contents and source code to this article
post comment
     

help!!

Posted by Mihir Tailor Feb 08, 2013

not working

Posted by Mihir Tailor Feb 08, 2013

thanks

Posted by sami abdullah Jul 21, 2012

Hi, I used your code but it has compilation errors, Guest and Incoming is not declared, can you help me out with that?

Posted by Abid Castaneda Jul 09, 2012

I am trying to "share a single document" just like netmeeting "Share Program", where only one document should be shared at a time to "viewer".If any other "window" popup over the "document" at the "sharer" end then that part should be made "Opaque" at the "Viewer" end (in AxRDPViewer control).If the "document" is minimized at the "Sharer" end whole "AxRDPViewer" should be opaque at the "Viewer" end.Can you please help me out in knowing is there any method or property in AxRDPViewer to do this.Or is there any logic to achieve it.Thanks in advance.

Posted by kuldeep mec Jul 03, 2012
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
Get Career Advice from Experts
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Get Career Advice from Experts