我在WinForm里做了个代码,很管用
我拖动xml文件并放到tabPage。
private TextEditorControl AddNewTextEditor(string title)
{
var tab = new TabPage(title);
var editor = new TextEditorControl();
editor.Dock = System.Windows.Forms.DockStyle.Fill;
editor.IsReadOnly = false;
editor.Document.DocumentChanged +=
new DocumentEventHandler((sender, e) => { SetModifiedFlag(editor, true); });
// When a tab page gets the focus, move the focus to the editor control
// instead when it gets the Enter (focus) event. I use BeginInvoke
// because changing the focus directly in the Enter handler doesn't
// work.
tab.Enter +=
new EventHandler((sender, e) => {
var page = ((TabPage)sender);
page.BeginInvoke(new Action<TabPage>(p => p.Controls[0].Focus()), page);
});
tab.Controls.Add(editor);
fileTabs.Controls.Add(tab);
if (_editorSettings == null) {
_editorSettings = editor.TextEditorProperties;
OnSettingsChanged();
} else
editor.TextEditorProperties = _editorSettings;
return editor;
}
但是WPF有点脏。
我可以改变代码为WPF??或其他方式..?谢谢你的帮助。
1条答案
按热度按时间gmxoilav1#
您可以这样做:
假设您有一个
TabControl
,其中包含TabItem
A和B以及一个Button
,用于添加TabItem
单击该按钮后,将添加另一个选项卡项(C)