如何多次在画布上绘制富文本框作为可放置的可编辑对象? [英] How do I draw a richtext box on a canvas as a placeable editable object multiple times ?

查看:93
本文介绍了如何多次在画布上绘制富文本框作为可放置的可编辑对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在努力解决如何在画布上绘制对象(C#/ VB winforms或wpf)的困难时间(失败很严重)我可以保存到图片文件或数据库供以后使用。 (就像一个迷你绘图应用程序)



主要对richtext可编辑和可移动感兴趣,但最终还是其他一些形状线条图像等,但一次只有一步! />


任何人都可以使用一个易于理解的方法或示例应用来解决上述问题吗?

我已经下载了几个演示应用,但没有一个覆盖了richtext ,到目前为止很难遵循!





我不是要重新创建coreldraw或autocad ..但是想要实验使用基本的设计师应用程序来学习定位丰富的文本和形状。



非常感谢任何帮助和解释:-)



Andy T

Hi,
I am having a hard time (failing badly) trying to work out how to draw objects on a canvas (C#/VB winforms or wpf) in a way that I can save to a picture file or a database for later use. (like a mini drawing app)

Mainly interested in richtext editable and moveable, but also eventually some other shapes lines images etc. but one step at a time!

can anyone help with a easy to follow method or sample app to solve the above ?
I have downloaded several demo apps, but none cover richtext, and have been so far difficult to follow!


I'm not trying to recreate coreldraw or autocad.. but want to experiment with a basic designer app to learn positioning richtext and shapes.

many thanks for any help and explanations :-)

Andy T

推荐答案

您不需要任何示例代码。您可以在 Canvas 上放置任何内容。试试看,不要问这样的样品。想一想。假设您有一个示例代码,其中矩形放在Canvas上。您是否需要单独的代码示例才能在同一个Canvas上放置其他内容。如果由于某种原因,你将永远不会自己编写任何合理的代码。希望情况并非如此。



在你的问题中,惊人的话是多次。你明白它的类型是什么,它的实例是什么。你可以在一些容器元素中放置几个​​例如 RichTexBox 的实例,但前提是它们是不同的实例。这是WPF的一个特殊功能,与许多其他UI库不同:检查每个实例只有一个父项。有关WPF父子关系和相关概念的深入理解,请阅读: http://msdn.microsoft.com/en-us/library/ms753391%28v=vs.110%29.aspx [ ^ ]。



-SA
You don't need any sample code. You can place anything on Canvas. Just try it, instead of asking of such samples. Think about it. Suppose you have a sample code where a rectangle is put on Canvas. Would you need a separate code sample to put something else on the same Canvas. If, by some reason, you would, you will never come to writing any sensible code by yourself. Hope this is not the case.

In your question, the alarming words are "multiple times". Do you understand what is the type and what is its instance. You can put several instances of, say RichTexBox in some container element, but only if they are different instances. This is a special feature of WPF different from many other UI libraries: it is checked up that each instance have only one parent. For in-depth understanding of WPF parent-child relationships and related concepts, please read: http://msdn.microsoft.com/en-us/library/ms753391%28v=vs.110%29.aspx[^].

—SA


会员10913969写道:
Member 10913969 wrote:

我想我'我可以提出这个问题,因为它确实没有得到正确的解决!当然,我可以在设计模式下在画布上放置一个richtext并编辑它!

I think I'm going to can this question as it really hasn't come across properly! of course I can drop a richtext on a canvas in design mode and edit it!

只有在这个评论之后我才知道你真正的问题是什么。可能这对于如何编写与某些XAML等效的代码存在一些混淆。并且,而不是深入研究特定于 Canvas RichTextBox 的细节(或者你要问的任何其他内容),我希望为您提供最普遍的建议,几乎适用于所有情况。



首先要了解的是:当您在设计时使用XAML创建窗口或在用户控件中,它在设计时和后续构建期间被完全消耗。使用此类XAML构建项目时,XAML代码将完全转换为C#代码。构建完成后,这个自动生成的代码保留在项目的子目录obj下,你可以轻松找到它。



所以,这里是我的普遍建议:如果你可以在XAML或设计师那里做一些事情并且不确定如何在C#中编写类似的东西(在很多情况下这真的是一种很好的开发方式),你可以做一些简单的事情:在一些示例项目中,在XAML中执行您想要执行的任何操作,构建此项目,查找自动生成的文件并查看此代码的作用。简单,不是吗?这些练习对于理解某些事情非常有用。



-SA

Only after this comment I got an idea what your real problem could be. Probably, this is some confusion on how to write code equivalent to some XAML. And, instead of digging into the detail specific to Canvas or RichTextBox (or whatever else you are asking about), I want to give you the most universal advise which would work in nearly all cases.

First thing to understand is: when you use XAML at design time to create a window or a user control, it is fully consumed during design time and later during build time. When you build your project with such XAML, the XAML code is fully translated into C# code. When the build is complete, this auto-generated code stays under the sub-directory of your project, "obj", you can easily find it.

So, here is my universal advice: if you can do something in XAML or with the designer and not sure how to write similar thing in C# (which is really can be a good way of development, in very many cases), you can do simple thing: in some sample project, do whatever you wanted to do in XAML, build this project, find out auto-generated files and see what this code does. Simple, isn't it? Such exercises are really useful for understanding certain things.

—SA


这篇关于如何多次在画布上绘制富文本框作为可放置的可编辑对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆