Click here to Skip to main content
15,867,312 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello,

I have a myFormClass inherited from System.Windows.Forms.Form class (C# 2013 .Net 4),
and set the RightToLeft property value to Yes and RightToLeftLayout to True from Properties grid window.

Now I inherit the Form1, from myFormClass (that created automatically when I create new project).

Then I set an image for Form1.BackgroundImage and set the BackgroundImageLayout to Stretch, but the image don't show.

After googling, I found a solution from StackOverflow, to override the form OnPaintBackground method. Therefore I override the OnPaintBackground method in myFormClass.

C#
using System.Drawing;
using System.Windows.Forms;

C#
protected override void OnPaintBackground(PaintEventArgs e)
{
    if ((RightToLeftLayout) && (RightToLeft == RightToLeft.Yes))
    {
        Image bgImage = BackgroundImage;
        e.Graphics.DrawImage(bgImage, new Rectangle(Point.Empty, this.ClientSize));
    }
    else
        base.OnPaintBackground(e);
}


So far every thing is OK.

But...
When I place some CommandButtons on Form1, the buttons borders don't display correctly after run project and resize the form.

If I move the mouse cursor on buttons, the borders refreshed and fixed but there is some problems yet.

What is your suggestion?
Posted
Comments
Kornfeld Eliyahu Peter 3-Jan-16 4:12am    
It is not clear why your relate it to the RTL layout...
Reza552 4-Jan-16 0:12am    
I want the form background image, that work correctly everywhere with right to left layout. In the above question, the command button (for example), has some problems when form executed and resized. How could I correct it?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900