Home Technical Talk

MAXSCRIPT: Textfield Multiline Scrollbar

interpolator
Offline / Send Message
SimonT interpolator
I can scale up a textfield in Maxscript and it will become a multiline textfield - my problem: it gets no scrollbar when the text is longer than the textfield. :(

Question:

1. How i can add scroll bars to the 3ds max textfield
2. OR: how i use a dotnet textbox?

Replies

  • Swordslayer
    Offline / Send Message
    Swordslayer interpolator
    As for the second part, here's example dotnet textbox:
    try destroyDialog test catch()
    rollout test " .NET Textbox" width:180 height:180
    (
        dotNetControl dncText "System.Windows.Forms.Textbox" width:175 height:170 align:#center
    
        on test open do
        (
            dncText.Font = dotNetObject "System.Drawing.Font" "MS Sans Serif" 8 ((dotNetClass "System.Drawing.FontStyle").Regular)
                dncText.BorderStyle = (dotNetClass "System.Windows.Forms.BorderStyle").FixedSingle
                dncText.BackColor = (dotNetClass "System.Drawing.Color").fromARGB (((colorMan.getColor #background) * 255)[1] as integer) (((colorMan.getColor #background) * 255)[2] as integer) (((colorMan.getColor #background) * 255)[3] as integer)
                dncText.ForeColor = (dotNetClass "System.Drawing.Color").fromARGB (((colorMan.getColor #text) * 255)[1] as integer) (((colorMan.getColor #text) * 255)[2] as integer) (((colorMan.getColor #text) * 255)[3] as integer)
                dncText.MultiLine = true
                dncText.WordWrap = true
                dncText.ScrollBars = (dotNetClass "System.Windows.Forms.ScrollBars").Vertical
                dncText.Text = 
                    "I can scale up a textfield in Maxscript and it will become a multiline textfield - my problem: it gets no scrollbar when the text is longer than the textfield.\r\n\r\n
                    Question:\r\n\r\n
                    1. How i can add scroll bars to the 3ds max textfield\r\n
                    2. OR: how i use a dotnet textbox?"
        )
    )
    createDialog test
    

    To comment what's happening in there:
    dotNetControl dncText "System.Windows.Forms.Textbox" -- this is how you declare the dotnet textbox in case you're using it in regular maxscript rollout; you can as well just say dotNetControl dncText "Textbox"

    dncText.Font -- if you don't like the default one
    dncText.BorderStyle -- I guess you can say what this is; anytime you need to find out more about the properties/methods/events of the control, you can create one and query it:

    showproperties (dotNetObject "TextBox")
    showmethods (dotNetObject "TextBox")
    showevents (dotNetObject "TextBox")
    -- this is useful for assigning event handlers, you can then just say on MouseDoubleClick args dncText do ...

    It also gives you the classes/objects you need to assign to the property to change it. However with the properties there's a shorthand possibility:

    instead of:

    dncText.ScrollBars = (dotNetClass "System.Windows.Forms.ScrollBars").Vertical

    you can just say:

    dncText.ScrollBars = dncText.ScrollBars.Vertical

    The backcolor assignment I use there gets the interface colors, that's why it might look so intimidating. In fact it could be just

    dncText.BackColor = dncText.BackColor.fromARGB 140 150 160

    or something like that. Anyway, there're quite many tutorials around (Paul Neale comes to mind) dealing with donet so even if this doesn't completely make sense, don't worry, ask for details or just search around for ready made scripts using it and you'll master it in no time.
  • SimonT
    Offline / Send Message
    SimonT interpolator
    You are my hero! Thank you very much! The only thing i miss is the AcceptReturn stuff.

    my code:
    rollout unnamedRollout "Untitled" width:389 height:279
    (
    dotNetControl textboxctrl "System.Windows.Forms.TextBox" pos:[16,16] width:232 height:200

    on unnamedRollout open do
    (
    textboxctrl.Multiline = true;
    textboxctrl.AcceptsReturn = true;
    textboxctrl.WordWrap = false;
    textboxctrl.ScrollBars = textboxctrl.ScrollBars.Both;
    )
    )

    createDialog unnamedRollout;

    But it does nothing. I'm not able to make a linebreak.
  • SimonT
    Offline / Send Message
    SimonT interpolator
    Weird!

    .AcceptsReturn: Enter doesn't work, Strg+Enter doesn't work
    .AcceptsTab: Enter doesn't work, Strg+Enter works
  • SimonT
    Offline / Send Message
    SimonT interpolator
    Found the solution:

    1. I had to set AcceptsReturn AND AcceptsTab to true. Only *Return didn't worked
    2. I had to check if Enter was pressed and paste a line break manually

    rollout unnamedRollout "Untitled" width:389 height:279
    (
    dotNetControl textboxctrl "System.Windows.Forms.TextBox" pos:[16,16] width:232 height:200

    on unnamedRollout open do
    (
    textboxctrl.AcceptsReturn = true;
    textboxctrl.AcceptsTab = true;
    textboxctrl.WordWrap = false;
    textboxctrl.Multiline = true;
    textboxctrl.ScrollBars = textboxctrl.ScrollBars.both;
    )

    on textboxctrl keydown pressedKey do
    (
    if (pressedKey.keyvalue == 13) do textboxctrl.paste("\r\n");
    )
    )

    createDialog unnamedRollout;
Sign In or Register to comment.