[Mono-docs-list] MyTextEntry, code source
Andrés Sáyago
asath@yahoo.com
Mon, 21 Apr 2003 04:49:03 -0500
This is a multi-part message in MIME format.
--------------060607080305040301020705
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
Miguel and people!
I'm new here and I'm new in the Mono world. I want to colaborate for
this excelente project. My first colaboration is this code attachment, a
conversion of the Entry in Gtk to Gtk#. The original code was taken from
the official manual:
http://go-mono.com/tutorial/html/en/gnome/bindings/gtk-sharp/misctextentries.html
Please, my Eglish isn't perfect. But I receive suggests!
Andrés Sáyago
-------
Hola Miguel. Este es mi primer aporte a Mono, una conversión del
programa que usa el widget Entry en Gtk para ser usado en Gtk#. Usé el
códido original del manual que se encuentra en:
http://go-mono.com/tutorial/html/en/gnome/bindings/gtk-sharp/misctextentries.html
Mi Inglés no es perfecto pero recibo sugerencias y agradezco correciones
al texto. Me sentiría muy orgulloso y animado si incluyen mi aporte y
los créditos en la página que Johannes Roith y Alejandro Sánchez Acosta
tienen publicada.
Espero comentarios!
Portal GNU ColombiaLinux
http://www.ColombiaLinux.org
asath@ColombiaLinux.org
Universidad Autónoma de Bucaramanga
Bucaramanga, Colombia
Tel: (57-7)6454994 Móvil: 3157632295
--------------060607080305040301020705
Content-Type: text/plain;
name="MyTextEntry.cs"
Content-Transfer-Encoding: 8bit
Content-Disposition: inline;
filename="MyTextEntry.cs"
// MyTextEntry.cs - GTK# Tutorial example
//
// Authors: Andrés Sáyago
// asath@ColombiaLinux.org
//
// (C) 2003 Andrés Sáyago
// Colombia
//
namespace GtkSharpTutorial
{
using Gtk;
using GtkSharp;
using System;
public class textEntrySample
{
// The entry_toggle_* functions use it
static Entry entry;
static void enter_callback(object obj, EventArgs args)
{
string entry_text = ((Entry) obj).Text;
Console.WriteLine("Entry contents: " + entry_text);
}
static void entry_toggle_editable(object obj, EventArgs args)
{
entry.Editable = ((CheckButton) obj).Active;
}
static void entry_toggle_visibility(object obj, EventArgs args)
{
entry.Visible = ((CheckButton) obj).Active;
}
static void window_destroy(object obj, DeleteEventArgs args)
{
Application.Quit();
}
static void button_close(object obj, EventArgs args)
{
Application.Quit();
}
// Function for the Widgets building
static void create_text_entry()
{
Window window;
VBox vbox;
HBox hbox;
Button button;
CheckButton check;
int tmp_pos;
// Create a new window
window = new Window (WindowType.Toplevel);
window.SetDefaultSize(200, 100);
window.Title = "GTK Entry";
window.DeleteEvent += new DeleteEventHandler(window_destroy);
vbox = new VBox(false, 0);
window.Add(vbox);
vbox.Show();
// Box to enter text
entry = new Entry();
entry.MaxLength = 50;
// When the Enter key is pressed, print a message to the console
entry.Activated += new EventHandler(enter_callback);
entry.Text = "hello";
tmp_pos = entry.Text.Length;
// Demostration of the 'InsertText' function (-1 is at end)
entry.InsertText(" world", -1, out tmp_pos);
// Text selected
entry.SelectRegion(0, entry.Text.Length);
vbox.PackStart(entry, true, true, 0);
entry.Show();
hbox = new HBox(false, 0);
vbox.Add(hbox);
hbox.Show();
check = new CheckButton("Editable");
hbox.PackStart(check, true, true, 0);
check.Toggled += new EventHandler(entry_toggle_editable);
check.Active = true;
check.Show();
check = new CheckButton("Visible");
hbox.PackStart(check, true, true, 0);
check.Toggled += new EventHandler(entry_toggle_visibility);
check.Active = true;
check.Show();
button = Button.NewFromStock(Gtk.Stock.Close);
button.Clicked += new EventHandler(button_close);
vbox.PackStart(button, true, true, 0);
button.CanDefault = true;
button.GrabDefault();
button.Show();
window.Show();
}
// Main function
public static void Main(string[] args)
{
Application.Init ();
create_text_entry();
Application.Run ();
}
}
}
--------------060607080305040301020705--