-2

Does anyone know how I can Move Form or panel but when the form. Right To Left = Yes and Right To Left Layout = True, I used that code but when the Form Right To Left = No Can someone convert this code in order for the form to be accepted Right To Left = Yes?

 int movX;
 int moxY;
 bool isMoving;

private void onMouseDown(object sender, MouseEventArgs e)  
{
     // Assign this method to mouse_Down event of Form or Panel,whatever you want
    isMoving = true;
    movX = e.X;
    movY = e.Y;
}

private void onMouseMove(object sender, MouseEventArgs e)
{
     // Assign this method to Mouse_Move event of that Form or Panel
    if (isMoving)
    {
        this.SetDesktopLocation(MousePosition.X - movX, MousePosition.Y - movY);
    }
}

private void onMouseUp(object sender, MouseEventArgs e)
{
   // Assign this method to Mouse_Up event of Form or Panel.
    isMoving = false;
}
Rodi
  • 1
  • Check [this](https://stackoverflow.com/a/60907334/10216583). Direction does not matter. –  Apr 06 '20 at 22:14

1 Answers1

0

Here is your solution. Please find as bonus the title height addition to prevent vertical flicker.

Just change your onMouseDown method.

Pleae note that, if the RightToLeft is inherit, we need to iterate through all the parents to find out which setting is active. But I don't think this is necessary here.

So, for a form with RightToLeft = Yes; use this onMouseDown event:

private void onMouseDown(object sender, MouseEventArgs e)
{
    // Assign this method to mouse_Down event of Form or Panel,whatever you want
    isMoving = true;

    if (RightToLeft == System.Windows.Forms.RightToLeft.Yes)
    {
        movX = ClientRectangle.Right - e.X;
    }
    else
    {
        movX = e.X;
    }

    Rectangle screenRectangle = RectangleToScreen(ClientRectangle);
    int titleHeight = screenRectangle.Top - this.Top;
    movY = e.Y + titleHeight;
}
Oguz Ozgul
  • 6,809
  • 1
  • 14
  • 26
  • Please my friend, can you tell me how I found the solution ,,, I want to become a professional in C # Can you help me I want to understand more in design and how to program special tools Can you write to me on WhatsApp or Facebook – Rodi Apr 08 '20 at 11:18
  • How many years of experience do you have? Expertise comes with time. How did I found the solution? First of all, instead of assuming things, I REPRODUCED your problem. Then I realized that when a RTL form is grabbed by the mouse down and then moved, it jumps unexpectedly. There you can instantly see that the positioning of the mouse pointer on the form is also reversed horizontally. It is not hard to guess that the new position is now taken relative to the right, instead of left. Can you please accept if this solved your problem? – Oguz Ozgul Apr 08 '20 at 11:38
  • I am a university student, you can say that I have an intermediate stage of experience. I am from Syria and our universities do not have much experience, so I am learning from the internet and following courses online. But I want to be an expert in C # design and design programs ,, I studied oop and SQL and a little experience in designing desktop programs so I want to know what the next step is. What should I learn what should I do please help me – Rodi Apr 08 '20 at 21:38
  • Check Pluralsight. It is completely free during April. https://www.pluralsight.com/paths/csharp – Oguz Ozgul Apr 08 '20 at 21:46