Solved

ContextMenuStrip text alignment

Posted on 2010-11-29
2
1,513 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

772 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