private String CoordinatesToString(MouseEventArgs e) { return "Координаты мыши: х=" + eXToString() + "; y=" + eYToString(); } private void Form1_MouseMove(object sender, MouseEventArgs e) { //отображение текущих координат мыши в заголовке окна Text = CoordinatesToString(e); } private void Form1_MouseClick(object sender, MouseEventArgs e) { //определим какую кнопку мыши нажал пользователь String message = ""; if (e.Button == MouseButtons.Right) { message = "Вы нажали правую кнопку мыши."; } if (e.Button == MouseButtons.Left) { message = "Вы нажали левую кнопку мыши."; } message += "\n" + CoordinatesToString(e);//ЧТО ПРОИСХОДИТ В ЭТОЙ СТРОКЕ //выведем сообщение в диалоговое окно String caption = "Клик мыши"; MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Information); } 
  • What does "explain the syntax" mean? - selya
  • message + = "\ n" + CoordinatesToString (e); // what happens here? The syntax is incomprehensible - Proshka
  • Please edit your question (so that the topic is useful to other members of the community), and I will answer. - selya

2 answers 2

In the string message += "\n" + CoordinatesToString(e); the messge variable messge "added" to the end of the "\ n" , which is equivalent to a newline, and the result of the CoordinatesToString function with argument e . Those. the function is called, and the string that this function returns is added to the string, i.e. in essence, this is equivalent to:

 message += "\n" + "Координаты мыши: х=" + eXToString() + "; =" + eYToString(); 
  • It's clear. Unclear record: message + = In this case, confuses + - Proshka
  • Understood, thanks. It turns out message = message + "\ n" + CoordinatesToString (e) // concatenation of strings with the total value recorded in message. Right? - Proshka
  • Yes, in simple language, += - add, a = - overwrite, and since operation + is more priority than + = and = , then all + will be executed first, and after it will be increased / rewritten - selya
  • Thanks for the help. - Proshka

The message variable is incremented by the value returned by the CoordinatesToString function (MouseEventArgs e), described at the beginning of the code above, with preliminary concatenation with a new line "\ n". The CoordinatesToString function, accepting a mouse event, returns a string like "Mouse coordinates: x = (horizontal coordinates); y = (vertical coordinates)"

  • message = CoordinatesToString (e); // but will this record be correct? - Proshka
  • where is this + = - Proshka
  • Why not? True, but the result will be different. In the first case, if the message variable already contained some value, then a new line would be added to it. And in this case, the value of the message variable will be overwritten. + = add to string, simply = - assign new value - Iceman
  • Thanks for the help! - Proshka
  • @Proshka, Operator + = (C # Reference) - Alex Krass