Add white space between 2 string values in ContextMenuStrip items (Windows Forms) RRS feed

  • Question

  • I need to add the white space for that the 2nd string always stands under each other. I'm using a non monospaced font like here on the webpage. As you can see, the 3 is not exactly under the 9.

    Audi           4
    BMW          9
    Mercedes    3 

    String.PadRight is not precise enough. I guess adding a space in SizeF (width) could be precise enough?!.

    An other guy mentioned to use a custom ToolStripRenderer because the white space is always font depended.

    1. Am i the first one who's trying to do that, any code snippets maybe or alternatives? (I'm trying to create a text builder for that a user can select an item's text to build his own combination of a virtual keyboard code within an application.)

    2. If i wants to customize the ToolStrip which looks like a very hard task for me, i think i have to override the OnPaint of the ToolStripItem class and i'm depended on the limited methods for drawing a string what could be a problem again for adding a white space?


    Edit: OMG, i realized that i maybe have to place 3 items to each other in one item, have to calculate the sizing and to customize the selection painting or something like that? (Think i can't do it technically, would take a year?! :))


    • Edited by ChrisHar Wednesday, November 18, 2020 12:44 AM
    • Moved by CoolDadTx Wednesday, November 18, 2020 3:09 PM Winforms related
    Tuesday, November 17, 2020 11:47 PM

All replies

  • This forum is for C# specific questions. Please post Windows Forms related questions in the new Microsoft Q&A forums.

    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, November 18, 2020 3:09 PM
  • Did it, thanks.


    • Edited by ChrisHar Saturday, November 21, 2020 6:37 PM
    Saturday, November 21, 2020 6:26 PM