Solved

ContextMenuStrip text alignment

Posted on 2010-11-29
2
1,593 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

751 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