Imports System
Imports Gtk
Imports GtkSharp
Public Module ToggleButtons
Dim tb As Gtk.TextView
Dim buffer As Gtk.TextBuffer
Sub OnDeleteEvent(ByVal obj As Object, ByVal args As DeleteEventArgs)
Application.Quit()
End Sub
Sub OnExitButtonEvent(ByVal obj As Object, ByVal args As EventArgs)
Application.Quit()
End Sub
Sub OnClick(ByVal obj As Object, ByVal args As EventArgs)
' Create a new buffer object
buffer = New Gtk.TextBuffer(System.IntPtr.Zero)
' Set the buffer to point to the textviews buffer
buffer = tb.Buffer
' Set text to display
buffer.SetText("hey there")
End Sub
Public Sub Main()
Application.Init() ' pre initialization
Dim window As Window = New Window("Testing Widgets") ' Declaring a new window
AddHandler window.DeleteEvent, AddressOf OnDeleteEvent
window.BorderWidth = Convert.ToUInt32(0)
Dim box1 As VBox = New VBox(False, 10) ' Creatinga child container for window to hold
' Note that the window object can only hold 1 child. So we use the Boxes to hold our main widegts
window.Add(box1)
box1.Show()
' Create a button with a Clicked event wired up
Dim btnClick As Button = New Button("Click to add text to textview!")
AddHandler btnClick.Clicked, AddressOf OnClick
box1.PackStart(btnClick, True, True, Convert.ToUInt32(0)) ' Add it to the Box container we creates
btnClick.Show() ' make it visible
Dim separator As HSeparator = New HSeparator() ' horizontal seperator
box1.PackStart(separator, False, True, Convert.ToUInt32(0))
separator.Show()
' Create a quit button
Dim btnQuit As Button = New Button("Quit")
AddHandler btnQuit.Clicked, AddressOf OnExitButtonEvent
box1.PackStart(btnQuit, True, True, Convert.ToUInt32(0))
tb = New Gtk.TextView()
tb.SetSizeRequest(100, 100)
box1.PackStart(tb, True, True, Convert.ToUInt32(0))
btnQuit.CanDefault = True ' Make quit button default
btnQuit.GrabDefault()
btnQuit.Show()
window.ShowAll() ' Display the child to window object
Application.Run() ' Run the application
End Sub
End Module