C# 图形网络与文本
我的任务是制作一个控件,其行为类似于RichTextBox,但包含一个图形网络。 这张网正在解决的唯一任务就是让人看得见 它应该是重写OnPaint方法的解决方案,但它不是 此代码:C# 图形网络与文本,c#,wpf,controls,richtextbox,C#,Wpf,Controls,Richtextbox,我的任务是制作一个控件,其行为类似于RichTextBox,但包含一个图形网络。 这张网正在解决的唯一任务就是让人看得见 它应该是重写OnPaint方法的解决方案,但它不是 此代码: protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { base.OnPaint(e); ...//drawing a line } protected override void WndProc(ref S
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
base.OnPaint(e);
...//drawing a line
}
protected override void WndProc(ref System.Windows.Forms.Message m)
{
base.WndProc(ref m);
if (m.Msg == 15)
{
Graphics g = this.CreateGraphics();
g.DrawLine(new Pen(Color.White, 1), new Point(0, 0), new Point(400, 400));
}
}
给我一个RichTextBox,没有任何文本
此代码:
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
base.OnPaint(e);
...//drawing a line
}
protected override void WndProc(ref System.Windows.Forms.Message m)
{
base.WndProc(ref m);
if (m.Msg == 15)
{
Graphics g = this.CreateGraphics();
g.DrawLine(new Pen(Color.White, 1), new Point(0, 0), new Point(400, 400));
}
}
有时画额外的线
事实上,由于这两种方法都不起作用,我不知道该尝试什么。
等待您的建议:)
德米特里
另外,我听说过很多关于WPF的好机会,但我对这项技术不是很熟悉,也不知道从什么开始
p.p.S.对不起,我的英语不是我的自然语言。如果你所说的网络是指某种网格线,请看以下内容以开始学习:
<RichTextBox>
<RichTextBox.Document>
<FlowDocument>
<Paragraph Foreground="Red">
<Run>Sample Text...</Run>
</Paragraph>
</FlowDocument>
</RichTextBox.Document>
<RichTextBox.Background>
<VisualBrush TileMode="Tile" Viewport="0,0,20,20" ViewportUnits="Absolute" Viewbox="0,0,20,20" ViewboxUnits="Absolute">
<VisualBrush.Visual>
<Rectangle Stroke="LightGray" StrokeThickness="1" Fill="Transparent" Width="100" Height="100" />
</VisualBrush.Visual>
</VisualBrush>
</RichTextBox.Background>
</RichTextBox>
示例文本。。。
您熟悉ControlTemplates吗?可能就是这样,开始阅读。Thanx:)