Non-breaking characters in WinForms labels? - winforms

In WinForms, is there a way to add a non-breaking hyphen to a System.Windows.Forms.Label control?
e.g. Don't break like this:
======================
| VB is SO un- |
| cooperative! |
======================
Instead break like this!
======================
| VB is SO |
| un-cooperative! |
======================

If you want to use the Forms Designer you could select the Label's Text property. Click on the dropdown arrow on the far right and type your text. You could break it at the desidered position by pressing SHIFT+ENTER.
In code it is simply
label1.Text = "VB is SO\nun-cooperative!";
or in VB.NET
label1.Text = "VB is SO" & Environemnt.NewLine & "un-cooperative!"

Check this, its working properly
text does not break after or before '-'. i have tested in my testing project and its working properly. even i reduce the width of label it get cut from the right side as displayed in my screenshot.
still getting problem then you have another option is that create custom user control for label and write some code for word wrap there are lot of code exist on internet for wordwrap process. available in VB.net also. btw windows form does not allow any event or override method that you can handle it for wrap text.

Related

WPF MVVM Event Notification from User Control to Window

I have a window control that contains four user controls (screens) in a wizard style environment. (i.e. only one user control will be viewable at all times) The window control has a series of buttons that act as the primary navigation between all the user controls.
----------------------------------
| |
| SCREEN x of 4 |
| |
----------------------------------
| |
| Back Next Cancel |
----------------------------------
The wizard will build a profile of information as the user completes each screen. I have defined a Profile type that implements INotifyPropertyChanged that will contain the information the user provides. So far, so good.
My question is: When the first user control (Screen 1 of 4) modifies the Profile type, how do I alert the Window? I'm trying to use MVVM and not use code-behind.
I tried setting up an event on the first user control. The window would be the subscriber to that event, but that's not working.
Is there a better approach for a user control to alert the main window that something has happened?
MVVM uses Commands instead of Click handlers. So you should have an implementation of ICommand interface ready to use or you can get it from any MVVM oriented Framework
If you want to keep things simple, here is the link how to use commands
What MVVM framework are you using? Most of them have an implementation of the Mediator pattern to handle communication between view models.
I use Cinch V2 and here you can find an explanation of how it implements the pattern and also see some code showing how to use it.
If you are not using a specific MVVM framework take the ideas from the implementation above and apply to you code!

Checkedlistbox, Textboxes, Output

I'm a novice in programming and I'm seeking advice on my program in visual basic (visual studio 2010).
I'll describe my aims of the program and how I've created a mock up.
My main interface will have several tabs. Within each tab, there will consist of a few textboxes for entering data and a few checkedlistboxes with a list of items in each of them.
What I'd like to do is to gather all the information inputted and/or clicked by a user of the program and to assimilate the information to a pre-formatted text box, that will give me the option to output it to a file. I'd like the pre-formatted textbox to gather the data from the different textboxes and checkedlistboxes from the various tabs. I can give an example (non-code) of what I mean:
Tab 1 of application:
textbox asking for name
textbox asking for date
checkedlistbox with items ("green", "blue", "red")
Tab 2 of application:
textbox asking for name of country
textbox asking for citizenship
checkedlistbox with items ("north", "south", "east", "west")
Tab 3 of application:
textbox that is "preformatted" to grab the data from the first two tabs so that I can save it to a textfile that would look like this
My name is Billy
Today's date is 31JAN2010.
I like: green blue red,
I come from United States of America.
I am American.
I am from the region of South
As of now, the method I'm using is largely inefficient. I'm just not knowledgable enough yet to do what I want do I've resorted to this strategy:
For checkedlistitems, I output the list of items to a textbox. I make this box invisible to the user. I then call this box in my tab 3, which has a button and text area. The button portion automatically codes the "preformatted" text and its a matter of referencing the invisible textbox which contains the item lists that were checked. One problem with this, or how I've programmed the checkedlist box, is that If I check something, and then uncheck it, it still appears in my tab 3 textbox.
For example, If I was a user using the 2nd tab and I clicked "South" but then unclick it and click "North", the textbox says
I am from the region of South North
I'm not sure which property or where in my code I need to alter so that it can remove items. I'm using a for loop to grab the items and don't have my code on hand.
In general, I'm just looking for strategies for programming something like this that will be efficient compared to what I have. Any suggestions / examples / code is well appreciated.
For your checkedlistbox, you can use the even SelectedIndexChanged that way when you change the selection, you won't have that problem:
example of how to use:
If you have a simple label for example :
Label1.Text = "I am from the region of " & checkedlistbox1.selecteditem.value
Btw in your case I don't think a for loop is necessary.
If you wish for information try w3schools or msdn.
Regards

Style ComboBox Popup to include additional item

What is the easiest way to change a ComboBox, in WPF, so that the Popup has an additional row that could be used to perform a function. For example,
--------------------------
| [Button Add New Item] |
| Item 1 |
| Item 2 |
| Item 3 |
--------------------------
I know that the ComboBox has the "PART_Popup" that might be able to reuse. But it feels like rewriting the entire style or combo box control is overkill.
Any help would be greatly appreciated. Thanks!
You'll need to edit the controltemplate, and since you've found PART_Popup, you know where to look. Drop a button inside the DropDownScrollViewer above the ItemsPresenter. You might have to play with the template a bit to make it exactly how you want it to look, but you're on the right track.

How to do Selection Alignment using the RichTextBox in Silverlight 4?

I cannot seem to figure out how to do a Selection Alignment in the new RichTextBox, I have an idea that I need to convert the selection into the Paragraph type which supports alignment, but cannot seem to figure this out. None of the Silverlight examples have this, but I'm sure it is possible.
I have this code, that does not work - as I think I need the selection to be a Paragraph as it always returns and Exception "Value does not fall within the expected range".
Editor.Selection.SetPropertyValue(Paragraph.TextAlignmentProperty, TextAlignment.Left)
I make sure I check for a Valid Selection first, code like the following works for "Bold":
If Editor.Selection.Text.Length > 0 Then ' Text Selected
If TypeOf Editor.Selection.GetPropertyValue(Run.FontWeightProperty) Is FontWeight _
AndAlso DirectCast(Editor.Selection.GetPropertyValue(Run.FontWeightProperty), FontWeight) = FontWeights.Normal Then
Editor.Selection.SetPropertyValue(Run.FontWeightProperty, FontWeights.Bold)
Else
Editor.Selection.SetPropertyValue(Run.FontWeightProperty, FontWeights.Normal)
End If
End If
Editor.Focus()
Example in XAML:
<Paragraph TextAlignment="Right">Example</Paragraph>
The above works in the contents of a RichTextBox however I need to do this programatically based on a selection - like in WordPad.
Using silverlight 4 released version, this is how I did it.
Editor.Selection.ApplyPropertyValue(Paragraph.TextAlignmentProperty, TextAlignment.Left)
That assumes that your text that you will be justifying is currently selected.
Looks like the RichTextArea does not support this as yet in the Silverlight 4 beta, although it is possible to populate a RichTextArea with Paragraph elements with a particular TextAlignment in code and XAML you cannot do it on a Selection as this does not expose the "Block" or "Paragraph" element selected just the "Run".

Displaying controls on an alpha-blended form

I tried the Visual C# Kicks code for an alpha-blended form. This works (as soon as I remove the TransparencyKey property); that is, I can use the W3C's PNG alpha test image and see other windows underneath, but makes all controls on the form invisible. Presumably, they simply aren't painted, as OnPaint is overridden. I tried calling the superclass's OnPaint:
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
UpdateFormDisplay()
MyBase.OnPaint(e)
End Sub
, but this didn't change anything. (Calling MyBase.OnPaint first doesn't make any difference either.)
Unfortunately most articles about alpha-blended forms focus on pure splash screens without any controls on them — but we need a panel which first shows sign-in fields, then a progress bar.
The controls, by the way, do not need transparency; it's only on the outer edges that the PNG's transparency truly matters. So faking this by adding another form on top of this all (with the two always moving in tandem) might suffice, but I'd prefer a smoother solution.
Try putting this in your form ctor after InitializeComponents();
base.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);

Resources