我在winform上有一个richtextbox。 C# [英] I have a richtextbox on a winform. C#

查看:180
本文介绍了我在winform上有一个richtextbox。 C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我在c#的win表单上放置了一个Richtextbox。我有一个更改字体的问题。这里有一些工作背景。



我添加了一个带有一组按钮和2个组合框的工具条。第一个组合框中填充了计算机上所有已安装字体的名称。第二个组合框用于字体大小。我可以添加项目符号,设置粗体,斜体,下划线的字体样式。我还可以设置文本的右侧,左侧和居中。所有这一切都很好。



当我尝试更改字体或字体大小时,我遇到的问题是在我的richtextbox中。我首先选择要更改字体的文本,然后单击组合框中的相应字体并更改字体。然后,我点击下拉列表的大小,并按预期工作。这是我的问题。现在我已经改变了字体和字体大小。我现在在富文本中选择一个新的文本部分,然后单击字体的下拉列表,现在所有文本都会更改为我刚刚单击的任何字体。它完全忽略了所选择的内容。我在textchange上有一行代码,两个组合框的选定索引都已更改。



这应该只使用richtextbox中已有的sytle和组合框中其他文本部分的大小来改变字体



Hello,

I have a Richtextbox placed on a win form in c#. I have an issue with changing the font. here is some background on what is working.

I have added a toolstrip with a bunch of buttons and 2 combo boxes. the first combo box is filled with the name of all installed fonts on the computer. the second combo box is meant for the size of the font. I can add bullets, Set the font style of bold, Italics, underline. I can also set the right, left and centering of text. All of this is working fine.

The issue I am having is in my richtextbox when I try to change the font or the font size. I first select the text that I want to change the font on click the appropriate font in the combo box and the font changes. I then click on the dropdown for the size and that works as expected. Here is my issue. Now that I have changed the font and the font size. I now select a new section of text in the rich text and i click on the drop down of the font and all text now changes to whatever font I just clicked. It completely ignores what is selected. I have 1 line of code on the textchange and selected index changed for both combo boxes.

This should just change the font with the sytle that is already in richtextbox and the size of the other text portion of the combo box

rtfDirections.SelectionFont = new Font(tcboFonts.Text, (float)Convert.ToDecimal(tcboSize.Text), rtfDirections.SelectionFont.Style);





我尝试了什么:



不知道我应该尝试什么,所以它按预期工作。



What I have tried:

Not sure what I should try to get this so it works as I expect it.

推荐答案

我们需要知道哪些控件应用了字体和大小的变化:它们是独立的吗?将更改应用于选择的行为是否与在组合框中选择字体或大小无关?



您是否在跟踪之前的选择?怎么样?



当用户完成对当前选择的更改后,您是否清除了选择?



在你的代码中放置断点并在每次更改后检查选择:你看到了什么?
We need to know what controls apply the changes in font and size: are they independent ? Is the act of applying the changes to the selection independent of selecting font or size in the comboboxes ?

Are you keeping track of the previous selection ? How ?

When the user is done making changes to the current selection, are you clearing the selection ?

Put breakpoints in your code and examine the selection after each change: what do you see ?


经过很多麻烦后我发现我遇到了2个问题。



首先。将数据绑定到数据源时,我将其绑定到文本字段而不是rtf字段。当控制失去对鼠标的控制时,改变了这一点并修复了不断丢失rtf编码的问题。现在rtf在点击富文本框时停留



秒。当尝试使用2组组合框更改多个不同位置的字体时,最好只使用内置字体对话框。
After a lot of trouble shooting I found I had 2 issues.

First. When binding my data to the datasource I bound it to text field instead of the rtf field. changed this and fixed constantly loosing the rtf coding when control lost control of the mouse. now the rtf stay when clicking off out of the rich text box

Second. When trying to change the font in muliple different locations using 2 sets of combo boxes it was better to just use the built in font dialog box.


这篇关于我在winform上有一个richtextbox。 C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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