GUI using Windows Forms and Powershell

Dave Turnbull 20 Reputation points
2024-09-08T18:03:07.94+00:00

I am building a GUI using Windows Forms in Powershell. I have created 4 Radio Buttons with a line of text to the right of each button to describe the purpose . The text is long (22 Characters) and it is being wrapped onto two lines when I want it to appear in a single line. How do I achieve this ? The GUI box is more than big enough to accomodate the text length.

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,888 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Michael Taylor 54,311 Reputation points
    2024-09-08T20:18:54.2366667+00:00

    Windows is responsible for wrapping the text on the button based upon a variety of things including font size, border width, font scaling, etc. You have little control over the actual wrapping. If the button isn't big enough to hold the text then you have to make the button bigger. If you don't want to do that then change the font of the button to be smaller such that it will fit.

    If you can provide some repro code then perhaps there might be some options available. It is important that you provide the settings for the form as well because most control properties are inherited from the parent form.

    0 comments No comments

  2. KOZ6.0 6,395 Reputation points
    2024-09-11T02:33:28.7266667+00:00

    Try this code.

    using System;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;
    
    public partial class Form1 : Form
    {
        const int EM_SETWORDBREAKPROC = 0xD0;
        const int WB_LEFT = 0;
        const int WB_RIGHT = 1;
        const int WB_ISDELIMITER = 2;
    
        [DllImport("user32")]
        private static extern IntPtr SendMessage(IntPtr hWnd, int msgId, IntPtr wParam, EditWordBreakProc lParam);
        private delegate int EditWordBreakProc(IntPtr ipch, int ichCurrent, int cch, int code);
    
        private EditWordBreakProc breakProc;
    
        public Form1() {
            InitializeComponent();
        }
    
        private void Form1_Load(object sender, EventArgs e) {
            breakProc = EditWordBreak;
            SendMessage(textBox1.Handle, EM_SETWORDBREAKPROC, IntPtr.Zero, breakProc);
        }
    
        private int EditWordBreak(IntPtr ipch, int ichCurrent, int cch, int code) {
            switch (code) {
                case WB_ISDELIMITER:
                    return 0;
                case WB_LEFT:
                    return 0;
                case WB_RIGHT:
                    return cch;
            }
            return 0;
        }
    }
    

    enter image description here


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.