0

Platform: UBUNTU
IDE: MonoDevelop 2.8.6.3
Language: C#.NET

I have created a function which makes a screenshot and returns that screenshot as a Bitmap. Like this:

/* Variable to store bitmap data in */
Bitmap bmp;

/* Create screenshot. Return result to variable 'bmp' */
getScreenShot(bmp);

My question is:

How do I create a form/window (or whatever makes sense) which displays the screenshot (i.e. the bmp data) ? I want to do it programmatically.

I tried to do it like this:

    public static void Main (string[] args)
    {

        Bitmap bmp = null;
        Form form = new Form
        {
            Name = "Screenshot Displayer",
            Size = new System.Drawing.Size(800, 800),
                            Location = new System.Drawing.Point(140, 170),
                             Visible=true
        };



        /* Get screenshot */
        Gdk.Global.InitCheck(ref args);
                    screenCapture.getScreenShot(bmp);

        form.BackgroundImage = bmp;
        form.Show();






    }

I tried this as well and it doesn't work.

PictureBox P = new PictureBox();  
Bitmap bmp = null;  
Form form = new Form  
{  
    Name = "Screenshot Displayer",  
    Size = new System.Drawing.Size(800, 800),  
    Location = new System.Drawing.Point(140, 170),  
    Visible=true  
};  

bmp = new Bitmap("screenshot0.bmp");  
P.Image = bmp;  
form.Controls.Add (P);  
form.Show();
user1884325
  • 2,530
  • 1
  • 30
  • 49

2 Answers2

1

Add a PictureBox that docks fill in the form.Then display screenshot like this:

pictureBox1.Image=bmp;
user2492798
  • 589
  • 1
  • 4
  • 8
  • Can you show me an example? I tried what you suggested but it doesn't work. – user1884325 Jul 10 '13 at 00:49
  • PictureBox P = new PictureBox(); Bitmap bmp = null; Form form = new Form { Name = "Screenshot Displayer", Size = new System.Drawing.Size(800, 800), Location = new System.Drawing.Point(140, 170), Visible = true }; bmp = new Bitmap(@"example.bmp"); P.Image = bmp; P.Dock = DockStyle.Fill; form.Controls.Add(P); form.Show(); – user2492798 Jul 10 '13 at 01:15
  • what if you do not want to have a picture boxes on the form and want to draw it on the background like on the form – Doug Hauf Feb 27 '14 at 19:31
  • 1.Generate bitmap.You can draw or get from file.eg:Bitmap bmp = new Bitmap(@"example.bmp"); 2.Set bmp as background of the form.eg:form.BackgroundImage=bmp; – user2492798 Feb 27 '14 at 23:54
0

"How do I create a form/window (or whatever makes sense) which displays the screenshot (i.e. the bmp data) ? I want to do it programmatically."

Try :
(compiling the below should display your Bitmap, study the code and ask anything) :

//# Declare a PictureBox (as bitmap container)
PictureBox pbx;

//# Setup the PictureBox
pbx = new PictureBox
{
    Name = "pictureBox99",
    Size = new Size(640, 480),
    Location = new Point(0, 0),
    Visible=true
};

//# Link PictureBox to code for reference
this.Controls.Add(pbx);

// Add your Bitmap as source
pbx.Image = your_Bitmap_object;
VC.One
  • 14,790
  • 4
  • 25
  • 57