如何在文本框中单独对齐文本,C#WPF [英] How to align text individually in text box, c# wpf

查看:196
本文介绍了如何在文本框中单独对齐文本,C#WPF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在WPF中设置文本框的对齐属性.我使用下面的代码;

I want to know how to set alignment property of text box in WPF. I used below code;

textBox.TextAlignment=TextAlignment.Center;

但是它会更改文本框中的整个文本对齐方式.我不想要这个.

But it changes entire text alignment in the text box.  I dont want this.

实际上我正在寻找

richTextBox1.SelectionAlignment = HorizontalAlignment.Center; (from winforms)

Similar code in wpf text box.

Similar code in wpf text box.

推荐答案

以前,我试图在文本框中分别实现文本对齐,但是失败了,甚至没有得到正确的解决方案.因此尝试在富文本框中单独实现文本对齐.我进行了很多搜索,但没有找到合适的解决方案.

Previously I was trying to achieve text alignment individually in text box but failed and even didnt get proper solution. So trying to achieve text alignment individually in rich text box.I searched a lot but no proper solution found.

我的要求是允许用户根据需要对齐文本.用户可以将前几行居中对齐,然后再将几行右对齐,再将几行左对齐.但是我想知道在文本框中没有这样的选项称为selectionalignment richtextbox.

My requirement is to allow user to align text as want. User can align first few line in center, then next few line in right alignment and next few lines with left alignment. But I wondered there is no such option called selectionalignment in textbox and richtextbox. 

有什么办法可以在richtextbox中分别设置文本的对齐方式?

Is there any way possible to set alignment of text individually in richtextbox? 

请注意,我正在使用WPF和c#开发此计算机应用程序.

Please note I am developing this computer application using WPF and c#. 


这篇关于如何在文本框中单独对齐文本,C#WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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