Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#-从构造函数中的资源添加图像文件_C#_Image_Properties_Constructor_Resources - Fatal编程技术网

C#-从构造函数中的资源添加图像文件

C#-从构造函数中的资源添加图像文件,c#,image,properties,constructor,resources,C#,Image,Properties,Constructor,Resources,我在VisualStudio中创建了一个自定义按钮类,我想向构造函数添加一个图像。这些图像位于我的项目的属性/资源中。通常,我会向按钮添加一个图像,如下所示: btnBack.Image = Properties.Resources.back57; 在此场景中,back57是图像文件的名称 这是我的按钮类的当前构造函数: public MenuButton() { this.Font = new System.Drawing.Font("TrsNo__", 18);

我在VisualStudio中创建了一个自定义按钮类,我想向构造函数添加一个图像。这些图像位于我的项目的属性/资源中。通常,我会向按钮添加一个图像,如下所示:

btnBack.Image = Properties.Resources.back57;
在此场景中,back57是图像文件的名称

这是我的按钮类的当前构造函数:

public MenuButton()
    {
        this.Font = new System.Drawing.Font("TrsNo__", 18);
        this.Width = 160;
        this.Height = 40;
        this.FlatStyle = FlatStyle.Popup;
        this.BackColor = System.Drawing.Color.DarkOrange;
        this.ImageAlign = System.Drawing.ContentAlignment.TopLeft;
        this.MouseEnter += new System.EventHandler(mouseEnterCustom);
        this.MouseLeave += new System.EventHandler(mouseLeaveCustom);
        this.SetStyle(ControlStyles.Selectable, false);
    }
如何编辑构造函数,以便从资源中添加图像文件

编辑1:我想它看起来会像这样

public MenuButton(??????)
    {
    this.Image = ?????????
    }
添加新的结构器:

public MenuButton(Bitmap buttonImage)
   : base()
{
   this.Image = buttonImage
}
并创建您的按钮:

MenuButton menuBttn = new MenuButton(Properties.Resources.back57);