In a winforms application, I'm using a RichTextBox and I'm trying to reduce the output from a '\t' to 4 spaces from whatever the default is.
I have this in the form's OnLoad
_richTextBox.Text = "1\t2\t3\t4\t5";
_richTextBox.SelectAll();
_richTextBox.SelectionTabs = new int[] {100,200,300,400 };
I have a breakpoint before and after this snippet. The SelectionTabs is set to {int[0]} (empty int array) before and after the assignment. Can anyone tell me why my assignment is not going through?
Try setting the SelectionTabs property before putting anything into the text box (and/or selecting anything).
See Modifying default tab size in RichTextBox.
Related
I know this is probably absolutely crazy what I am doing but it is the circumstances that kind of do not leave me any other options right now.
I am putting together a WPF UI using C++/CLI without XAML connected to unmanaged/PURE C++ Direct3D11 elements and it all kind of works as long as you do not stray into the area of UI templates/styling.
However in one part of the UI I really need to change the color of the selected and hover-selected item(s) of a ListBox away from the default windows style the cient simply does not like that bluish colour.
I tried following code but it has zero effect:
System::Windows::Style^ s = gcnew System::Windows::Style((gcnew System::Windows::Controls::ListBoxItem())->GetType());
s->Resources->Add(SystemColors::HighlightBrushKey, gcnew SolidColorBrush(System::Windows::Media::Color::FromRgb(255,0,0)));
s->Resources->Add(SystemColors::ControlBrushKey, gcnew SolidColorBrush(System::Windows::Media::Color::FromRgb(255, 0, 0)));
ListBox^ filelist = gcnew ListBox();
filelist->ItemContainerStyle = s;
But this does basically nothing also assigning the style to the ->FocusVisualStyle property of the ListBox does nothing
Any suggestions on what to do or how to get this working without resorting to XAML resource
Update: It looks like this code works at least partially under Windows 7 but does not do anything under Windows 10 ???
I have a simple user control (just an example): it is 40x100, but resizable. It has two buttons, one anchored at the top, one anchored at the bottom.
It put this control on a form and stretch it to 40x400. This works fine.
But as soon as I switch the form to Localizable = True and change the language to translate any strings, the Designer shows the user control
as if it was 40x100 for both the default an the translated language, i.e. the bottom button is not anchored.
Or better: the bottom button is displayed as if it was not anchored. The control occupies the correct amount of space (40x400), though (see selection highlight). And it displays fine during runtime, this is just a Designer issue.
A picture showing the issue.
Did I miss something here? Is this how it is supposed to work?
Im on VS2010 at the moment, tried the old VS2005 but it's the same there.
Thanks...
I could easily repro this problem by anchoring the second button to the bottom. The Anchor property has a few oddish failure modes, layout isn't always recalculated when it should be. You found one such case. I think the underlying issue is that the Size property is a localizable property as well and the designer fails to fire the required events when it starts a new localization set. Something like that, nothing very trivial.
You'll need to punt this problem and not rely on the Anchor property to get the button positioned correctly. That just takes a one-liner in your UserControl code, like:
protected override void OnResize(EventArgs e) {
button2.Top = this.ClientSize.Height - button2.Height;
base.OnResize(e);
}
I am using .net framework 4.5
I have a WPF project, and I use WPF combobox. The property IsEditable is set to true to allow input values.
But when I input non English character such as "â" (I have to type "aa" to make "â", it becomes "aâ".
When I set property IsTextSearchEnabled = "False", "aa" becomes "â" (This is correct behavior).
Does anyone have solution for this when set IsTextSearchEnabled = "True" for WPF combo box?
Firstly, I don't get this behaviour when I type into a ComboBox. If you have something particular about your ComboBox or your computer that gives you this behaviour, you need to share it with us, so that we can better help you.
All the same, I don't know about typing "aa" to make "â", but I do know that if you press 0226 while holding the Alt key down, it will also give you "â". Maybe you could try using that instead?
You can find out more accent codes from the Windows - Alt Key Numeric Codes page on the PennState University website.
I wrote a window UI by c++ windows form. I'd like to create a string table to localize the Form. My steps are:
1. I set the form localizable=true.
2. Add a new .resx file named (project name).en-US.resx and edit the string table.
3. Set the text of components using the code like
this->button1->Text = resources->GetString("CLOSE");
After I finish setting the text, I build the project and execute it, the button truly show the text. But if I modify the UI(like add component or change the position of the button), the text will disappear after I build again. What's wrong with the code? How can the text always show? Otherwise I need to set again if I modify the form><. Thanks for anybody's help.
Do not make changes to the code that is generated by the designer. Anything inside the InitializeComponent() method. Such changes will disappear when you make another change in the designer and it re-generates the method. Code in the constructor is okay, put it after the InitializeComponent() call.
The better procedure to localize a form is to let the designer generate the .resx file and the code. Change the form's Language property to the desired language, then change the Text property in the property grid. No additional code is required.
I have the following scenario which I thought would have a simple solution, but I'm stumped...
I have constructed a WPF user control with a set of numeric Buttons and a TextBlock to record what buttons have been selected. When the user control opens, the TextBlock is empty. As a button is selected, the digit it represents is appended to the right-hand-side of the displayed text.
What I need is a solution where the digits keep getting appended on the right-hand-side and if that results in exceeding the fixed displayable size of the TextBlock dropping the left-most character. In effect I am after a one-character-at-a-time marque effect.
I can not use scroll bars. Any thoughts would be welcome
Databindings are you friend here.
suppose you got a ViewModel. and in the ViewModel you got a property of string which is binded to the TextBlock Text propetry.
Now you only need to manipulate that string inside the ViewModel using regular c# string methods to display correctly.
HTH
Ariel
There's nothing special at the TextBlock level... Just pass it the string that is formatted correctly using something like string.SubString.
UPDATE: This code should do the trick:
const int maxLength = 8;
string value = "sdfdfdfsdffdsfsdf";
if (value.Length > maxLength)
value = value.Substring(value.Length - maxLength);