fork download
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. namespace textboxact
  5. {
  6. static class Program
  7. {
  8. [STAThread]
  9. static void Main()
  10. {
  11. Application.EnableVisualStyles();
  12. Application.SetCompatibleTextRenderingDefault(false);
  13. Application.Run(new Form1());
  14. }
  15. }
  16. public class Form1 : Form
  17. {
  18. TextBox Atex = new TextBox(), Btex=new TextBox();
  19. public Form1()
  20. {
  21. Atex.Location = new Point(15, 15);
  22. Atex.Multiline = true;
  23. Atex.Size = new Size(270, 110);
  24. Atex.WordWrap = false;
  25. //Atex.KeyDown += Atex_KeyDown;
  26. Atex.KeyPress += _KeyPress;
  27. Btex.Location = new System.Drawing.Point(15, 140);
  28. Btex.Multiline = true;
  29. Btex.Size = new Size(270, 110);
  30. Btex.WordWrap = false;
  31. this.AutoScaleDimensions = new SizeF(6F, 12F);
  32. this.ClientSize = new Size(300, 300);
  33. this.Controls.Add(Btex); this.Controls.Add(Atex);
  34. Atex.GotFocus += text_gotfocus;
  35. Atex.LostFocus += text_lostfocus;
  36. Btex.GotFocus += text_gotfocus;
  37. Btex.LostFocus += text_lostfocus;
  38. }
  39. private void text_gotfocus(object sender, EventArgs e)
  40. {
  41. TextBox tb = sender as TextBox;
  42. if (null == tb) return;
  43. tb.BackColor = SystemColors.Window;
  44. }
  45. private void text_lostfocus(object sender, EventArgs e)
  46. {
  47. TextBox tb = sender as TextBox;
  48. if (null == tb) return;
  49. tb.BackColor = Color.Red;
  50. }
  51. //private void Atex_KeyDown(object sender, KeyEventArgs e)
  52. //{ e.SuppressKeyPress = true; Btex.Select(); }
  53. private void _KeyPress(object sender, KeyPressEventArgs e)
  54. { e.Handled = true; Btex.Select(); }
  55. }
  56. }
  57.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(3,22): error CS0234: The type or namespace name `Forms' does not exist in the namespace `System.Windows'. Are you missing `System.Windows.Forms' assembly reference?
prog.cs(16,22): error CS0246: The type or namespace name `Form' could not be found. Are you missing an assembly reference?
prog.cs(18,1): error CS0246: The type or namespace name `TextBox' could not be found. Are you missing an assembly reference?
prog.cs(53,39): error CS0246: The type or namespace name `KeyPressEventArgs' could not be found. Are you missing an assembly reference?
Compilation failed: 4 error(s), 0 warnings
stdout
Standard output is empty