Invoke((Action)(() => {
Close();
}));
Blog de todo lo referente a .Net Framework. Visitanos y descubre con nosotros los secretos de este framework de programación.
Invoke((Action)(() => {
Close();
}));
using System;
using Gdk;
using GLib;
using Gtk;
namespace Somedave {
public class ContextMenuEventArgs: EventArgs {
private Widget widget;
public Widget Widget { get { return widget; } }
private bool rightClick;
public bool RightClick { get { return rightClick; } }
public ContextMenuEventArgs(Widget widget, bool rightClick) {
this.widget = widget;
this.rightClick = rightClick;
}
}
public class ContextMenuHelper {
public event EventHandler<ContextMenuEventArgs> ContextMenu;
public ContextMenuHelper() { }
public ContextMenuHelper(Widget widget) {
AttachToWidget(widget);
}
public ContextMenuHelper(Widget widget, EventHandler<ContextMenuEventArgs> handler) {
AttachToWidget(widget);
ContextMenu += handler;
}
public void AttachToWidget(Widget widget) {
widget.PopupMenu += Widget_PopupMenu;
widget.ButtonPressEvent += Widget_ButtonPressEvent;
}
public void DetachFromWidget(Widget widget) {
widget.PopupMenu -= Widget_PopupMenu;
widget.ButtonPressEvent -= Widget_ButtonPressEvent;
}
[GLib.ConnectBefore]
private void Widget_PopupMenu(object o, PopupMenuArgs args) {
RaiseContextMenuEvent(args, (Widget)o, false);
}
[GLib.ConnectBefore]
private void Widget_ButtonPressEvent(object o, ButtonPressEventArgs args) {
if(args.Event.Button == 3 && args.Event.Type == EventType.ButtonPress) {
RaiseContextMenuEvent(args, (Widget)o, true);
}
}
private bool propagating = false; //Prevent reentry
private void RaiseContextMenuEvent(SignalArgs signalArgs, Widget widget, bool rightClick) {
if(!propagating) {
//Propagate the event
Event evnt = Gtk.Global.CurrentEvent;
propagating = true;
Gtk.Global.PropagateEvent(widget, evnt);
propagating = false;
signalArgs.RetVal = true; //The widget already processed the event in the propagation
//Raise the context menu event
ContextMenuEventArgs args = new ContextMenuEventArgs(widget, rightClick);
if(ContextMenu != null) {
ContextMenu.Invoke(this, args);
}
}
}
}
}
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
logger.Info("Hola");
logger.FatalException("Error:", exception);
[StructLayout(LayoutKind.Sequential)]
private struct LASTINPUTINFO {
public static readonly int SizeOf = Marshal.SizeOf(typeof(LASTINPUTINFO));
[MarshalAs(UnmanagedType.U4)]
public UInt32 cbSize;
[MarshalAs(UnmanagedType.U4)]
public UInt32 dwTime;
}
[DllImport("user32.dll")]
private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
private double GetLastInputTime() {
uint idleTime = 0;
LASTINPUTINFO lastInputInfo = new LASTINPUTINFO();
lastInputInfo.cbSize = (uint)Marshal.SizeOf(lastInputInfo);
lastInputInfo.dwTime = 0;
uint envTicks = (uint)Environment.TickCount;
if(GetLastInputInfo(ref lastInputInfo)) {
uint lastInputTick = lastInputInfo.dwTime;
idleTime = envTicks - lastInputTick;
}
TimeSpan span = new TimeSpan(0, 0, 0, 0, (int)idleTime);
return span.TotalMinutes;
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Gtk;
using Gdk;
namespace Test {
internal class ImageResize {
private Gtk.Image _Wrapped = null;
private Pixbuf original = null;
private string _File = null;
public ImageResize(Gtk.Image wrapped) {
_Wrapped = wrapped;
_Wrapped.ExposeEvent += new ExposeEventHandler(ImageResize_ExposeEvent);
}
void ImageResize_ExposeEvent(object o, ExposeEventArgs args) {
Pixbuf newPix = new Pixbuf(original.Colorspace, original.HasAlpha, original.BitsPerSample, _Wrapped.Allocation.Width, _Wrapped.Allocation.Height);
double zoom = (double)((double)_Wrapped.Allocation.Width / (double)((double)original.Width));
original.Scale(newPix, 0, 0, _Wrapped.Allocation.Width, _Wrapped.Allocation.Height, 0, 0, zoom, zoom, InterpType.Nearest);
_Wrapped.Pixbuf = newPix;
}
public string File {
get {
return _File;
}
set {
_File = value;
original = new Pixbuf(_File);
ImageResize_ExposeEvent(this, null);
}
}
}
}
public event MyEventHandler PropertyChanged;
public delegate void MyEventHandler(Object sender
, MyEventArgs e);
public class MyEventArgs
: System.ComponentModel.PropertyChangedEventArgs {
public object Value { get; private set; }
public MyEventArgs(string propertyName, object value)
: base(propertyName) {
Value = value;
}
}
using System;
using System.Diagnostics;
public class Class1
{
public void StarP() {
ProcessStartInfo stInfo = new ProcessStartInfo("prog.exe");
stInfo.UseShellExecute = false;
Process proc = Process.Start(stInfo);
proc.WaitForExit();
}
}
using org.pdfbox.pdmodel;
using org.pdfbox.util;
using System;
public class GetText() {
public string Retrieve(string fileName) {
PDDocument doc = PDDocument.load(fileName);
PDFTextStripper stripper = new PDFTextStripper();
return stripper.getText(doc);
}
}
<?xml version="1.0"?>
<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy toplevel-contextual -->
<object class="GtkWindow" id="window1">
<child>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">label</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button1">
<property name="label" translatable="yes">button</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="yalign">0</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
using System;
using Gtk;
namespace GTKBuilder {
class MainClass {
Window thisWnd = null;
Builder thisObject = null;
Button button1 = null;
Label label1 = null;
public static void Main (string[] args) {
Application.Init ();
MainClass tester = new MainClass();
tester.Show();
Application.Run ();
}
MainClass() {
InitializeComponent();
}
private void InitializeComponent(){
thisObject = new Gtk.Builder();
thisObject.AddFromFile("tester.glade");
thisWnd = (Window)thisObject.GetObject("window1");
label1 = (Label)thisObject.GetObject("label1");
button1 = (Button)thisObject.GetObject("button1");
button1.Clicked += (object sender, EventArgs e) => {
label1.Text = "Hello";
};
thisWnd.DeleteEvent += (o, args) => {
Application.Quit();
};
}
public void Show() {
thisWnd.ShowAll();
}
}
}