Solved

ContextMenuStrip text alignment

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
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.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now