我有一个页面,用户可以在其中输入文本区域。当按下按钮时,文本区域的内容将发布到PHP,然后保存在MySQL表中。但是,当我再次加载它时,所有格式都已删除,例如换行符。例如,假设将其键入到textarea中:
using System.Windows;
using System.Windows.Input;
public partial class YourWindow : Window
{
MouseCapturePreview MouseCaptureHandler;
//(...)
private void Window_Loaded(object sender, RoutedEventArgs e)
{
MouseCaptureHandler = new MouseCapturePreview(this);
//(...)
}
public class MouseCapturePreview
{
public MouseCapturePreview(Window element)
{
InputManager.Current.PreProcessInput += (s, e) => {
if (e.StagingItem.Input is MouseButtonEventArgs)
Handler(s, (MouseButtonEventArgs)e.StagingItem.Input);
};
void Handler(object sender, MouseButtonEventArgs e)
{
Console.WriteLine("Event Received");
if (e.LeftButton == MouseButtonState.Pressed) {
Console.WriteLine("Mouse Released");
element.ReleaseMouseCapture();
Mouse.Capture(element);
if (!element.RestoreBounds.Contains(element.PointToScreen(e.GetPosition(element))))
{
Console.WriteLine("Clicked outside");
MessageBox.Show("You clicked outside, time to close.");
//Application.Current.Shutdown();
element.Close();
}
} else {
Console.WriteLine("Mouse Captured");
element.CaptureMouse();
}
}
}
}
private void Window_Activated(object sender, EventArgs e)
{
Console.WriteLine("Activated");
this.CaptureMouse();
}
}
当它被装回时,将显示如下:
Bob
43
Colorado, USA
我不希望用户在文本区域中键入任何HTML,但我确实希望保存换行格式,有什么办法可以做到这一点?