Jump to content

What is the best way to show a multiline text in a GUI?


Recommended Posts

Hello

I used GUICtrlCreateEdit function to show my "sometext.txt" file contents in a GUI. But it does not give me a good interface and i have some problems with it.

One of problems in GUICtrlCreateEdit function is that when the text appears in editbox, whole text has been selected at first time !! and i must click once to get out it from selected state.

Other my problem is: i can not set just a vertical scrolbar. I want to use just vertical scrolbar not horizontal. I want to it fits to editbox's width horizontally but scrol vertically.

$myfile = FileOpen("Last10PMs.txt")
$PM10Text = FileRead($myfile)
$hgui = GUICreate("Title",800,600,-1,-1,-1)
GUICtrlCreateEdit($PM10Text, -1, -1, 800, 600)

When i use GUICtrlCreateLabel function to show text file, the state comes so bad from Editbox.

 

Thanks for any suggestion to view a text file in a better UI or resolving my problems.

Edited by mohammadezazi
Link to comment
Share on other sites

Hi, you can do something like this:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 623, 442, 192, 124)
$Edit1 = GUICtrlCreateEdit("", 56, 16, 489, 305,$ES_AUTOVSCROLL + $WS_VSCROLL)
GUICtrlSetData(-1, "hi word")
$Button1 = GUICtrlCreateButton("Button1", 240, 384, 81, 33)
GUICtrlSetState($Edit1,$GUI_FOCUS)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        case $Button1

    EndSwitch
WEnd

saludos

Link to comment
Share on other sites

  • Moderators

mohammadezazi,

I do not know about the "best" way, but I would do it like this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>

#include <GuiEdit.au3>
#include <String.au3>


$sText = ""
For $i = 1 To 20
    $sRandom = _StringRepeat("-", Random(10, 100, 1))
    $sText &= "Line " & $i & " " & $sRandom & @CRLF
Next

$hGUI = GUICreate("Test", 500, 500)

$cEdit = GUICtrlCreateEdit("", 10, 10, 200, 100, BitOr($ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL), $WS_EX_CLIENTEDGE)
GUICtrlSetData($cEdit, $sText)

GUISetState()

_GUICtrlEdit_SetSel($cEdit, -1, -1)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd
All clear? :)

M23

Edited by Melba23
Amended styles

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

AZJIO,

Thanks for that - I had just copied the line from the "style" section of the GUICtrlCreateEdit page in the Help file. :thumbsup:

Will you tell guinness? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...