简体   繁体   English

文字将替换标题栏中的实际文字

[英]text will replace the actual text in title bar

I have tried like this for adding secondary text to title bar of windows form 我试图这样添加辅助文本到Windows窗体的标题栏

                 formMain.ActiveForm.Text = name; 


         <pre>
        +--+---------------------------------------+----------+
        |  | Main window title          [text]       | _ O x  |
        +--+---------------------------------------+----------+
        |                                                     |

... ...

I want to add the text like above mentioned image .but it does not working properly 我想添加上面提到的图像之类的文本,但无法正常工作

but my problem is it will replaces the actual text in title bar with above secondary text . 但是我的问题是它将标题栏中的实际文本替换为上面的辅助文本。 I don't want like this , I want to add the text to formain title bar on right hand side with out changing the actual text.. 我不想这样,我想在不更改实际文本的情况下,将文本添加到右侧的主标题栏中。

can any one help on this........ 谁能帮上忙........

 formMain.ActiveForm.Text += "   "  + name; 

可以轻松完成您的任务

I think you are going to need to measure the form, and work out how many whitespace characters you need to insert in between the current form text, and the text you need to add to the right hand side. 我认为您将需要测量表单,并计算出需要在当前表单文本之间插入多少空白字符,以及需要添加到右侧的文本。

You would then add your text to the current title. 然后,您可以将文本添加到当前标题。

eg: 例如:

string rightHandText = "[text]";
string whiteSpace = string.Empty.PadLeft( (your calculation for whitespace), ' ');

formMain.Text += String.Format("{0}{1}", whiteSpace, righHandText);

Note the += when setting the form.Text, this adds to the text rather than replacing it. 设置form.Text时请注意+ =,这会添加到文本中而不是替换文本。

You can try 你可以试试

formMain.ActiveForm.Text += "               " + name; 

But this is dirty and undynamic. 但这是肮脏的,没有动力。

i don't know any way you can set the second text with right alignment. 我不知道您能以正确的对齐方式设置第二个文本的任何方式。 If you really want so, I think you have to create a custom Window by your own. 如果确实需要,我认为您必须自己创建一个自定义窗口。

this.Text += " text you want to add";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM