views:

313

answers:

1

Dialog closes with Cancel result, no exceptions, as if you have pressed its close button.
The only safe place to set RightToLeft property is in the form constructor.

It occured to me that this information might save somebody else's time.
If you are able to elaborate on the issue: if there is an official bug confirmation, what else might cause ShowDialog to end unexpectedly, please, do.

Re: close to tray - MSDN Forums

change Form RightToLeft property at runtime


Quote from the second link:

I have found a second bug in less than two days . This new bug is very critical .

I have Normal Form with RightToLeft property set to its default value ( RightToLeft=False) . Let us show this form with Show Function ( Form1.Show(me) )

At this Form there is a Button which change Form RightToLeft to Yes instead of No:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.RightToLeft = Windows.Forms.RightToLeft.Yes
End Sub

The Form will change its Title successfully to Right Side.

Up To This there is no problem.

Problem Occure as following

If we Display this Form to the user using ShowDialog(Me) Function instead of display it using Show(Me) . Then Click Button which will change Form RightToLeft to Yes instead of No , Form will Close Suddenly with no reasons , and even not throw any exceptions .
This is the new problem & it's exist also in .NET 3.0 ( Orcase ) Too .

+1  A: 

Ok... I have a quick fix for you. It is nasty, it is a hack but it kinda works.

From my answer to the original question:

private bool _rightToLeft;
private void SetRTL(bool setRTL)
{
    _rightToLeft = true;
    ApplyRTL(setRTL, this);
}

private void ApplyRTL(bool yes, Control startControl)
{
    if ((startControl is Panel) || (startControl is GroupBox))
    {
        foreach (Control control in startControl.Controls)
        {
            control.Location = CalculateRTL(control.Location, startControl.Size, control.Size);
        }
    }
    foreach (Control control in startControl.Controls)
        ApplyRTL(yes, control);
}

private Point CalculateRTL(Point currentPoint, Size parentSize, Size currentSize)
{
    return new Point(parentSize.Width - currentSize.Width - currentPoint.X, currentPoint.Y);
}

private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
    if (_rightToLeft)
    {
        _rightToLeft = false;
        e.Cancel = true;
    }
}

The shneaky part it to attach to the form closing event and then tell it to not close if you have just conducted a right to left swap (_rightToLeft). Having told it not close you remove the right to left flag and let life continue on.

*bug: there is a bug that occurs when closing a form open with .Show(this), but I am sure you can fix that!

FryHard
It might work even with Show(), if change it a little: private void SetRTL(bool setRTL) { _rightToLeft = true; ApplyRTL(setRTL, this); _rightToLeft = false; }
eugensk00