load text file via menu bar?

Hi everyone - been years since I was an active developer here, but now dipping my toes back in and have a question which hopefully someone can help with.

Im creating a Windows 10 app, consisting of a single window, and have a text area control in the window. I have created a menu bar and have the usual cut, select all, copy, paste etc. all working fine.

However, I have now added an open menu bar item, but when the app is built and run, the File > Open menu option is deactivated (greyed out), so I cannot load a text file into the text area.

Could someone please point me in the right direction?

Thank you all in advance.

From the documentation Getting Started: Everything About Desktop Menus

Add the FileOpen menu handler to your window
in there put something like

Dim dlg As OpenDialog
Dim f As FolderItem
dlg = New OpenDialog
#If Not TargetLinux Then
  dlg.InitialDirectory = SpecialFolder.Documents
#Else //open Home directory on linux
  dlg.InitialDirectory = SpecialFolder.Home

dlg.Title = "Select a Text file"
dlg.Filter = FileTypes1.Text  // "text/plain" file type defined in FileTypes1 set
f = dlg.ShowModal
If f is Nil Then
    return   //User Cancelled
end if

dim tis as textInputStream = TextInputStream.Open(f )

myTextArea.text = tis.readall

tis = nil

Thanks Tim and Norman.
I already had the menu handler created, but was struggling to remember how to load a text file into a text area.

I will try fiddling with Norman’s code.

Thank you both very much!

that code is 99% right out of the 2019r1.1 docs ( and should still function regardless of version )

I posted that version because its not clear what version you’re using so I posted one that works everywhere :slight_smile:

All done - it comes back a lot quicker the second time around - just takes a bit of brain digging to re-learn what you once knew :slight_smile:
Thanks Norman!