counter = 0
mpos = 1
GraphicsWindow.Width = 500
GraphicsWindow.Height = 600
GraphicsWindow.FontSize = 11
GraphicsWindow.Title = "Простейший текстовый редактор"
GraphicsWindow.BrushColor = "Blue"
Button_1 = Controls.AddButton("Открыть файл", 0,0)
Controls.SetSize(Button_1, 300,50)
Button_2 = Controls.AddButton("сохранить файл",0,0)
Controls.SetSize(Button_2, 300,50)
Controls.HideControl(Button_2)
Button_3 = Controls.AddButton(">>>",250,0)
Controls.SetSize(Button_3, 300,50)
Button_4 = Controls.AddButton("найти строку",0,400)
Controls.SetSize(Button_4, 300,50)
Controls.ButtonClicked = OnButtonClick
Controls.TextTyped = OnTextTyped
NewEdit_1 = Controls.AddMultiLineTextBox(0,50)
Controls.SetSize(NewEdit_1, 500,200)
NewEdit_2 = Controls.AddTextBox(0,250)
Controls.SetSize(NewEdit_2, 450,25)
Controls.SetTextBoxText(NewEdit_2,"filename.txt")
NewEdit_3 = Controls.AddTextBox(0,350)
Controls.SetSize(NewEdit_3, 450,25)
resulttext = ""
filename = "filename.txt"
Sub OnButtonClick
if Controls.LastClickedButton = Button_1 Then
result = File.ReadContents(filename)
Controls.SetTextBoxText(NewEdit_1,result)
EndIf
if Controls.LastClickedButton = Button_2 Then
File.WriteContents(filename,resulttext)
EndIf
if Controls.LastClickedButton = Button_3 And counter = 1 Then
counter = counter + 1
Controls.HideControl(Button_2)
Controls.ShowControl(Button_1)
endif
if Controls.LastClickedButton = Button_3 And counter = 0 Then
counter = counter + 1
Controls.HideControl(Button_1)
Controls.ShowControl(Button_2)
endif
If counter = 2 Then
counter = 0
endif
if Controls.LastClickedButton = Button_4 Then
edit = Controls.LastTypedTextBox
mytext = Controls.GetTextBoxText(edit)
For i = 1 To Text.GetLength(resulttext)
newtext = Text.GetSubText(resulttext,i,Text.GetLength(mytext))
pos = Text.GetIndexOf(newtext,mytext)
If pos <> 0 then
GraphicsWindow.ShowMessage("Совпадение найдено на символе " +i,"Сообщение")
endif
EndFor
endif
EndSub
Sub OnTextTyped
edit = Controls.LastTypedTextBox
If edit = NewEdit_1 then
resulttext = Controls.GetTextBoxText(edit)
EndIf
If edit = NewEdit_2 then
filename = Controls.GetTextBoxText(edit)
EndIf
EndSub
|