Solved

ContextMenuStrip text alignment

Posted on 2010-11-29
2
1,566 Views
Last Modified: 2012-05-10
So I am trying to right-align the text items on a context menu strip, but the code below doesn't seem to work, the items are still left-aligned.  Is it possible to do this?

Thanks very much.
Dim cm As New ContextMenuStrip

    Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        cm.Items.Clear()
        Dim tsmi As New ToolStripMenuItem("hello")
        tsmi.TextAlign = ContentAlignment.MiddleRight


        Dim tsmi2 As New ToolStripMenuItem("four score and seven years ago")
        tsmi2.TextAlign = ContentAlignment.MiddleRight


        Dim tsmi3 As New ToolStripMenuItem("abc")
        tsmi3.TextAlign = ContentAlignment.MiddleRight

        cm.Items.Add(tsmi)
        cm.Items.Add(tsmi2)
        cm.Items.Add(tsmi3)

    End Sub

    Private Sub Form2_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
        cm.Show(Me, New Point(e.X, e.Y))
    End Sub

Open in new window

0
Comment
Question by:riceman0
2 Comments
 
LVL 11

Accepted Solution

by:
Deepak Lakkad earned 500 total points
ID: 34236420
Hi

Here is the revised code for your requirement

Dim cm As New ContextMenuStrip

    Private Sub MDIMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        cm.Items.Clear()

        Dim tsmi As New ToolStripMenuItem("hello")
        tsmi.RightToLeft = Windows.Forms.RightToLeft.Yes
        tsmi.TextAlign = ContentAlignment.MiddleRight

        Dim tsmi2 As New ToolStripMenuItem("four score and seven years ago")
        tsmi2.RightToLeft = Windows.Forms.RightToLeft.Yes
        tsmi2.TextAlign = ContentAlignment.MiddleRight


        Dim tsmi3 As New ToolStripMenuItem("abc")
        tsmi3.RightToLeft = Windows.Forms.RightToLeft.Yes
        tsmi3.TextAlign = ContentAlignment.MiddleRight

        cm.Items.Add(tsmi)
        cm.Items.Add(tsmi2)
        cm.Items.Add(tsmi3)
    End Sub

Open in new window


- Deepak Lakkad
0
 

Author Comment

by:riceman0
ID: 34236467

Thanks, that did it!

You get the points, but maybe you know this too:

I am manually changing the width of the menu strip to match what I am opening it next to.  I turn off AutoSize and set the width to the desired dimension.

The right-alignment of the text seems to be stuck on the original width (which turns out to be the middle of my strip).  Do you have any idea how to force it to align to my manual width?

I've been trying different functions to force it but no luck yet.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question