用程序创建表单并在表单中显示位图

本文关键字:表单 显示 位图 程序 创建 | 更新日期: 2023-09-27 18:21:39

平台:UBUNTU
IDE:MonoDevelop 2.8.6.3
语言:C#.NET

我创建了一个函数,它制作一个屏幕截图,并将该屏幕截图作为位图返回。像这样:

/*用于在*/
中存储位图数据的变量位图bmp;

/*创建屏幕截图。将结果返回到变量"bmp"*/
getScreenShot(bmp);

我的问题是:

如何创建一个显示屏幕截图(即bmp数据)的窗体/窗口(或任何有意义的窗口)?我想用程序来做。

我试着这样做:

    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();



    }

我也试过了,但没用。

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();

用程序创建表单并在表单中显示位图

添加一个停靠在表单中的PictureBox。然后显示如下屏幕截图:

pictureBox1.Image=bmp;

"我如何创建一个显示屏幕截图(即bmp数据)的窗体/窗口(或任何有意义的东西)?我想以编程方式完成。"

尝试:
(编译以下内容应显示您的Bitmap,研究代码并询问任何问题):

//# 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;