간단한 Windows Forms 응용 프로그램을 만들려고합니다. TextBox에 텍스트를 쓰고 그럴 때마다 텍스트가 목록에 푸시되므로 모든 텍스트 조건이 적용됩니다. 그래서 우리는 그것을 사용하기 위해 "BACK"버튼을 가지고 있습니다. buttonBack.Click
잘 작동하지만 ... box.TextChanged
아닙니다. 나는이 이벤트가 나는 텍스트를 변경할 때마다 호출 할Windows Forms TextChanged
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Drawing;
namespace TextBox
{
class Revision
{
public string Text { get; set; }
public int CoursorPosition { get; set; }
}
class MyForm : Form
{
static RichTextBox box = new RichTextBox();
static List<Revision> revisions = new List<Revision>();
static void MakeRevision()
{
revisions.Add(new Revision
{
Text = box.Text,
CoursorPosition = box.SelectionStart
});
}
public MyForm()
{
var buttonBack = new Button()
{
Location = new Point(0, 0),
Size = new Size(ClientSize.Width, 30),
Text = "Back"
};
box.Size = new Size(ClientSize.Width, 100);
box.Multiline = true;
box.Location = new Point(0, buttonBack.Bottom);
box.TextChanged += (sender, args) => MakeRevision();
box.MouseDown += (sender, args) => MakeRevision();
Controls.Add(buttonBack);
Controls.Add(box);
buttonBack.Click += (sender, args) =>
{
box.Text = revisions.Last().ToString();
revisions.RemoveAt(revisions.IndexOf(revisions.Last()));
};
}
public static void Main()
{
var form = new MyForm();
Application.Run(form);
}
}
}
그게 무슨 뜻 이니? –
box.TextChanged + = (보낸 사람, args) => MakeRevision(); 나는 그것을 부른다) –
그것은 어떻게 작동하지 않느냐? –