-3
private void CmdPositionRel_Click(object sender, EventArgs e)
{
CmdTest.Location = new Point(
    CmdTest.Location.X = + 20, CmdTest.Location.Y);

What I am trying to achive is that by pressing the button CmdPosition the button CmdTest goes 20 pixels in the positive direction of X.

According to the bock I am learning from this code is right...

Problem : CS1612 Cannot modify the return value of control.Location because it is not a variable

In all the other threads the answer was to add "new Point". I have that but still the problem appears.

Sorry I am a complete beginner, in programming and on StackOverflow. Hope you can help me. Thanks

H H
  • 263,252
  • 30
  • 330
  • 514
Lmntron
  • 1
  • 3
  • isn't this the same as other problems – Scott Weaver Dec 16 '18 at 17:19
  • 1
    Welcome to stack Overflow. Take the [tour](https://stackoverflow.com/tour). Please see [here](https://stackoverflow.com/help/how-to-ask) on how to ask a good question. [Here](https://stackoverflow.com/help/asking) are some useful links on how to complete a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) –  Dec 16 '18 at 17:21
  • Typo, it is just + not =+ – Steve Dec 16 '18 at 17:23
  • Possible duplicate of [Cannot modify the return value error c#](https://stackoverflow.com/questions/1747654/cannot-modify-the-return-value-error-c-sharp) – Ňɏssa Pøngjǣrdenlarp Dec 16 '18 at 17:23
  • First law of _Coding Club_....the computer is always right. Well usually... ;) –  Dec 16 '18 at 17:47

1 Answers1

0

you are trying to make assignment to CmdTest.Location. check my fix

CmdTest.Location = new Point(
    CmdTest.Location.X + 20, CmdTest.Location.Y);
Derviş Kayımbaşıoğlu
  • 28,492
  • 4
  • 50
  • 72
  • 1
    Considering OP is probably new to programming, maybe expand upon _"make assignment to CmdTest.Location"_. i.e. mention the `=` sign; where it can and can't be used. Otherwise the difference is subtle –  Dec 16 '18 at 17:50