How to create a simple screen sharing application in C#


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

Up Next
    Ebook Download
    View all
    Learn
    View all