How to Create a Simple Screen Sharing Application in C#

What you'll need

A host application, and a viewer application.

The host

private void Incoming(object Guest)
{
    IRDPSRAPIAttendee MyGuest = (IRDPSRAPIAttendee)Guest; //???
    MyGuest.ControlLevel = CTRL_LEVEL.CTRL_LEVEL_INTERACTIVE;
}
  1. Add reference, rdpcomapi 1.0 Type Library.
    Add reference
  2. Add using RDPCOMAPILib.
  3. Add this method.
  4. Add this class-level variable.
    RDPSession x = new RDPSession();
    

Create three new buttons, and a textbox(don't 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 the toolbox and click Choose items.
     Choose items
  2. In the dialog under COM components, check RDPViewer Class, and click OK.
    RDPViewer
  3. Drag and Drop the RDPViewer object onto the form.
     RDPViewer

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 the host click button one, the start button
  2. On the host click button two, and they get the invite button
  3. On the host copy the text in the text box
  4. On the viewer paste it into the text box
  5. On the 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;
        }
    }
}


Similar Articles