How to center label text when length varies in VB? - vb.net

I have recently started a new project in Visual Basic which requires me to have a Preferences box where a user can enter his own text which will display in a label on the main form of the application, once the user has clicked the apply button in the Preferences box.
Whenever I test it out, the label and/or the writing in it shifts over to the right or the left...
I have tried to anchor it to the sides or top but it doesn't work.
How do I set the label up so that the text, no matter how short, always perfectly aligns to the top middle of the application even when the text is then changed to a new one of a different length?
Just like clicking the label and selecting 'Format', then 'Center in Form', then click on 'Horizontally' in the Menu of Visual Basic. But instead of aligning text of new length manually, I want it to automatically do this whenever the user clicks the apply button in the Preferences.
Any ideas will be greatly appreciated. Thanks

Another possible solution would be to perhaps use a Textbox and set it to Read-Only.
Why?
Because the Textbox offers the TextAlign property:
Public Property TextAlign As HorizontalAlignment
Refer link

Change the TextAlign property of the label to TopCenter. Anchoring doesn't justify the text, but rather resizes the label control relative to the change in form dimensions.

Try setting the AutoSize property of your label to "False", then setting TextAlign property to "MiddleCenter" (or wherever it's supposed to align to). Then set the Anchor property to "Left, Right". This worked fine for me. If you need any more information, feel free to reply.

Related

Label display ignoring form boundaries

Is the following possible and if so, what do I do.
I have multi-line text on a hidden label. When a user clicks a button, the label is displayed under a Textbox (It is re-hidden by a second button click). This works fine. However, if the label text is very long, the label is truncated by the form border(s). Is there a way to "ignore" the form borders as a context menu does? I cannot seem to find a property, or method, to accomplish this. I tried BringToFront but that did not help at all.
I used a label as one project form has 3 labels of this type. Also, I am open to suggestions as to a better way of displaying help then a custom label.

maximize listview when form window is strteched at runtime

I am using vb.net, I have created a form and there are two listviews in that form which are getting filled by button event. Every thing is going smooth, but the problem is when my exeute my project and in the form, when I maximize the form window(by clicking maximize button provided in the top right corner) the size of listview remains same while form maximizes, this looks odd, what i need is to maximize the listview also with the increase in the form window size.
I searched in google a lot and i found one property 'dock' of listview which i can set left, full, right,bottom,top or none, but this doesn't serve my purpose.
Snapshot when I am using Anchor property
On Starting:
After Maximizing:
Please guide me in the right direction, what I need to do
when no propety is set then image on maximizing is:
Thank you
With Regards
Better than Dock property, you have to use "Anchor" property. All controls on the Form has Anchor Top,Left by default, but you can change it in the property window or directly by code. You can know more about anchor on this site: http://www.homeandlearn.co.uk/NET/nets13p1.html
Anchoring two Listviews on a form depends on the form design, but SplitContainer control will be really usefull if you want that both Listview changes the size on form resize.

tabpage icon change on text change

I have a tab_control on a form and couple of tab_pages. Each tab_page has some controls like text_box, check_box etc. I have assigned an image list to tab_control and have assigned image_key property with respective image.
Now what I want to achieve is, when the text changes in any of the tab_page the image of respective tab_page should also change.
Please be informed that I am not talking about background image, I am talking about icons of tab_pages.
Thanks

WP8 PhoneAccentBrush doesn't affect TextBox focus border

I'm trying to make my WP7 app work well on WP8 (by compiling it as a WP8 app).
In my app, I'm changing the PhoneAccentBrush's Color which seems to work fine still, however TextBox's in WP8 now seem to show a border around it when the textbox is in focus (this wasn't happening for me on WP7). This border seems to always use the System's accent color instead of using the changed color like every other control.
Any idea what's going on here and how to change it? The red accent (if that's what the user has chosen) really clashes with my app's colors!
I would call overriding the accent color a hack. I would avoid setting the accent color and create a template for your textBlock.
Blend makes this very easy by allowing you to copy the default template and make changes to it.
Right Click the textBox in the Objects and Timeline pane, then select Edit Template -> Edit Current. Then select the States tab and select the Focused FocusState, then edit the border brush. Save and reuse the template as needed.
I did notice the textBox control template has changed in 8 and now defines the focus state border brush, although it does default to the PhoneAccentBrush.

Decrease the Space Between a Menu Item's Icon and its Text

In my .net windows form (I am using XP Pro SP3 and VS 2010), I have created a menustrip. In the menustrip are several menu items, each with a dropdown menu. The menu items in the dropdown menus each have an icon with some text. I want to make the menu more compact by decreasing the horizontal space between the icon and the text. (I added a red arrow to the picture to show the space I am talking about).
So far, I have set the padding of all the menuitems to 0, but this seems only to affect the vertical spacing between one menu item and the next.
I want to use the system rendermode for the menustrip (although the problem persists no matter what rendermode I use. The icons in the menu are 16x16, and have the property sizetofit.
Funny thing is that this very same spacing is just the way I want it in the menustrip - the icon is right next to the text.
This will remove the image margin completely, but it removes the images too; I just want to change the width of the image margin.
For Each menuItem As ToolStripMenuItem In menu_main.Items
DirectCast(menuItem.DropDown, ToolStripDropDownMenu).ShowImageMargin = False
Next
What can I do here?
So, this is kinda cheating, and probably isn't going to look as clean as you'd like, but I was able to do it by making the image have the text and then setting following properties in the designer for the menu item:
DisplayStyle = Image
ImageScaling = None