Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.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# - Fatal编程技术网

C# 当我从右向左更改布局时,背景图像不会渲染

C# 当我从右向左更改布局时,背景图像不会渲染,c#,C#,我已经为我的表单设置了背景图像,并将“从右到左”属性设置为“否”,将“从右到左”布局设置为“false”,并尝试使用按钮更改这些设置,但当我单击按钮时,我不会渲染,背景为白色。Windows form C using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using Syst

我已经为我的表单设置了背景图像,并将“从右到左”属性设置为“否”,将“从右到左”布局设置为“false”,并尝试使用按钮更改这些设置,但当我单击按钮时,我不会渲染,背景为白色。Windows form C

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication9
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.RightToLeft = RightToLeft.Yes;
            this.RightToLeftLayout = true;
        }
    }
}
检查MSDN上的备注部分

对于Form.RightToLeftLayout属性:

不支持背景图像、不透明度、透明键和绘制事件


当表单从右向左设置布局时,我们似乎无法设置图像,但一种方法是欺骗用户查看图片。使用面板基座填充并设置面板的图像背景,用户只能看到图片。检查代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication10
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.RightToLeft = RightToLeft.Yes;
            this.RightToLeftLayout = true;
            Panel pnl = new Panel();
            pnl.Dock = DockStyle.Fill;
            pnl.BackgroundImage = System.Drawing.Image.FromFile("D:\\Picture\\Graphic\\2\\(1).png");//address of your image
            pnl.BackgroundImageLayout = ImageLayout.Stretch;
            this.Controls.Add(pnl);
        }
    }
}