elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.


Tema destacado: Curso de javascript por TickTack


  Mostrar Mensajes
Páginas: 1 ... 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 [883] 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 ... 1254
8821  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets) en: 5 Julio 2013, 07:10 am
[ComboBoxTooltip] Show tooltip when text exceeds ComboBox width

(Muestra un tooltip cuando el tamaño del Item supera el tamaño del ComboBox.)



Código
  1.    Dim LastSelectedItem As Int32 = -1
  2.  
  3.    Private Sub ComboBoxTooltip_DropdownItemSelected(sender As Object, e As ComboBoxTooltip.DropdownItemSelectedEventArgs) _
  4.    Handles ComboBoxTooltip1.DropdownItemSelected
  5.  
  6.        Dim SelectedItem As Int32 = e.SelectedItem
  7.  
  8.        If SelectedItem <> LastSelectedItem Then
  9.            ToolTip1.Hide(sender)
  10.            LastSelectedItem = -1
  11.        End If
  12.  
  13.        If SelectedItem < 0 OrElse e.Scrolled Then
  14.            ToolTip1.Hide(sender)
  15.            LastSelectedItem = -1
  16.        Else
  17.            If sender.Items(e.SelectedItem).Length > CInt(sender.CreateGraphics.MeasureString(0, sender.Font).Width) + 8 Then
  18.                LastSelectedItem = SelectedItem
  19.                ToolTip1.Show(sender.Items(SelectedItem).ToString(), sender, e.Bounds.Location)
  20.            End If
  21.        End If
  22.  
  23.    End Sub

Es necesario este usercontrol:

Código
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. using System.Runtime.InteropServices;
  5.  
  6. public class ComboBoxTooltip : ComboBox
  7. {
  8.    private DropdownWindow mDropdown;
  9.    public delegate void DropdownItemSelectedEventHandler(object sender, DropdownItemSelectedEventArgs e);
  10.    public event DropdownItemSelectedEventHandler DropdownItemSelected;
  11.  
  12.    protected override void OnDropDown(EventArgs e)
  13.    {
  14.        // Install wrapper
  15.        base.OnDropDown(e);
  16.        // Retrieve handle to dropdown list
  17.        COMBOBOXINFO info = new COMBOBOXINFO();
  18.        info.cbSize = Marshal.SizeOf(info);
  19.        SendMessageCb(this.Handle, 0x164, IntPtr.Zero, out info);
  20.        mDropdown = new DropdownWindow(this);
  21.        mDropdown.AssignHandle(info.hwndList);
  22.    }
  23.    protected override void OnDropDownClosed(EventArgs e)
  24.    {
  25.        // Remove wrapper
  26.        mDropdown.ReleaseHandle();
  27.        mDropdown = null;
  28.        base.OnDropDownClosed(e);
  29.        OnSelect(-1, Rectangle.Empty, true);
  30.    }
  31.    internal void OnSelect(int item, Rectangle pos, bool scroll)
  32.    {
  33.        if (this.DropdownItemSelected != null)
  34.        {
  35.            pos = this.RectangleToClient(pos);
  36.            DropdownItemSelected(this, new DropdownItemSelectedEventArgs(item, pos, scroll));
  37.        }
  38.    }
  39.    // Event handler arguments
  40.    public class DropdownItemSelectedEventArgs : EventArgs
  41.    {
  42.        private int mItem;
  43.        private Rectangle mPos;
  44.        private bool mScroll;
  45.        public DropdownItemSelectedEventArgs(int item, Rectangle pos, bool scroll) { mItem = item; mPos = pos; mScroll = scroll; }
  46.        public int SelectedItem { get { return mItem; } }
  47.        public Rectangle Bounds { get { return mPos; } }
  48.        public bool Scrolled { get { return mScroll; } }
  49.    }
  50.  
  51.    // Wrapper for combobox dropdown list
  52.    private class DropdownWindow : NativeWindow
  53.    {
  54.        private ComboBoxTooltip mParent;
  55.        private int mItem;
  56.        public DropdownWindow(ComboBoxTooltip parent)
  57.        {
  58.            mParent = parent;
  59.            mItem = -1;
  60.        }
  61.        protected override void WndProc(ref Message m)
  62.        {
  63.            // All we're getting here is WM_MOUSEMOVE, ask list for current selection for LB_GETCURSEL
  64.            Console.WriteLine(m.ToString());
  65.            base.WndProc(ref m);
  66.            if (m.Msg == 0x200)
  67.            {
  68.                int item = (int)SendMessage(this.Handle, 0x188, IntPtr.Zero, IntPtr.Zero);
  69.                if (item != mItem)
  70.                {
  71.                    mItem = item;
  72.                    OnSelect(false);
  73.                }
  74.            }
  75.            if (m.Msg == 0x115)
  76.            {
  77.                // List scrolled, item position would change
  78.                OnSelect(true);
  79.            }
  80.        }
  81.        private void OnSelect(bool scroll)
  82.        {
  83.            RECT rc = new RECT();
  84.            SendMessageRc(this.Handle, 0x198, (IntPtr)mItem, out rc);
  85.            MapWindowPoints(this.Handle, IntPtr.Zero, ref rc, 2);
  86.            mParent.OnSelect(mItem, Rectangle.FromLTRB(rc.Left, rc.Top, rc.Right, rc.Bottom), scroll);
  87.        }
  88.    }
  89.    // P/Invoke declarations
  90.    private struct COMBOBOXINFO
  91.    {
  92.        public Int32 cbSize;
  93.        public RECT rcItem;
  94.        public RECT rcButton;
  95.        public int buttonState;
  96.        public IntPtr hwndCombo;
  97.        public IntPtr hwndEdit;
  98.        public IntPtr hwndList;
  99.    }
  100.    [StructLayout(LayoutKind.Sequential)]
  101.    private struct RECT
  102.    {
  103.        public int Left;
  104.        public int Top;
  105.        public int Right;
  106.        public int Bottom;
  107.    }
  108.    [DllImport("user32.dll", EntryPoint = "SendMessageW", CharSet = CharSet.Unicode)]
  109.    private static extern IntPtr SendMessageCb(IntPtr hWnd, int msg, IntPtr wp, out COMBOBOXINFO lp);
  110.    [DllImport("user32.dll", EntryPoint = "SendMessageW", CharSet = CharSet.Unicode)]
  111.    private static extern IntPtr SendMessageRc(IntPtr hWnd, int msg, IntPtr wp, out RECT lp);
  112.    [DllImport("user32.dll")]
  113.    private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);
  114.    [DllImport("user32.dll")]
  115.    private static extern int MapWindowPoints(IntPtr hWndFrom, IntPtr hWndTo, [In, Out] ref RECT rc, int points);
  116. }
  117.  
8822  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets) en: 5 Julio 2013, 05:31 am
Modifica el color de un Bitmap

Código
  1. #Region " Fill Bitmap Color "
  2.  
  3.    ' [ Fill Bitmap Color Function ]
  4.    '
  5.    ' Examples :
  6.    '
  7.    ' IMPORTANT: use ARGB colors as the parameter.
  8.    ' PictureBox1.BackgroundImage = Fill_Bitmap_Color(bmp, Color.FromArgb(255, 255, 255, 255), Color.Red)
  9.  
  10.    Private Function Fill_Bitmap_Color(ByVal Image As Bitmap, ByVal FromColor As Color, ByVal ToColor As Color)
  11.  
  12.        Dim bmp As New Bitmap(Image)
  13.  
  14.        Dim x As Integer = 0, y As Integer = 0
  15.  
  16.        While x < bmp.Width
  17.            y = 0
  18.            While y < bmp.Height
  19.                If Image.GetPixel(x, y) = FromColor Then bmp.SetPixel(x, y, ToColor)
  20.                Math.Max(Threading.Interlocked.Increment(y), y - 1)
  21.            End While
  22.            Math.Max(Threading.Interlocked.Increment(x), x - 1)
  23.        End While
  24.  
  25.        Return bmp
  26.  
  27.    End Function
  28.  
  29. #End Region





Mueve el slider de un "GTrackBar" de forma progresiva al mantener presionada una tecla de dirección.

Se necesita el control extendido GTrackBar: http://www.codeproject.com/Articles/35104/gTrackBar-A-Custom-TrackBar-UserControl-VB-NET

Código
  1. ' By Elektro H@cker
  2. #Region " [GTrackBar] Progressive Scroll "
  3.  
  4.    Dim TrackBar_SmallChange As Int32 = 5
  5.    Dim TrackBar_LargeChange As Int32 = 10
  6.  
  7.    ' GTrackBar [KeyDown]
  8.    Private Sub GTrackBar_KeyDown(sender As Object, e As KeyEventArgs) Handles GTrackBar1.KeyDown
  9.  
  10.        sender.ChangeSmall = 0
  11.        sender.ChangeLarge = 0
  12.  
  13.        Select Case e.KeyCode
  14.            Case Keys.Left, Keys.Right, Keys.Up, Keys.Down
  15.                MakeScroll_TrackBar(sender, e.KeyCode)
  16.        End Select
  17.  
  18.    End Sub
  19.  
  20.    ' GTrackBar [KeyUp]
  21.    Private Sub GTrackBar_KeyUp(sender As Object, e As KeyEventArgs) Handles GTrackBar1.KeyUp
  22.        ' Set the values on KeyUp event because the Trackbar Scroll event.
  23.        sender.ChangeSmall = TrackBar_SmallChange
  24.        sender.ChangeLarge = TrackBar_LargeChange
  25.    End Sub
  26.  
  27.    ' MakeScroll TrackBar
  28.    Private Sub MakeScroll_TrackBar(ByVal GTrackBar As gTrackBar.gTrackBar, key As Keys)
  29.  
  30.        Select Case key
  31.            Case Keys.Left
  32.                GTrackBar.Value -= TrackBar_SmallChange
  33.            Case Keys.Right
  34.                GTrackBar.Value += TrackBar_SmallChange
  35.            Case Keys.Up
  36.                GTrackBar.Value += TrackBar_LargeChange
  37.            Case Keys.Down
  38.                GTrackBar.Value -= TrackBar_LargeChange
  39.        End Select
  40.  
  41.    End Sub
  42.  
  43. #End Region

...Lo mismo pero si tenemos múltiples GTrackbars:

Código
  1. ' By Elektro H@cker
  2. #Region " [GTrackBar] Progressive Scroll MultiTrackbars "
  3.  
  4.    Dim TrackBar1_SmallChange As Int32 = 2
  5.    Dim TrackBar1_LargeChange As Int32 = 5
  6.  
  7.    Dim TrackBar2_SmallChange As Int32 = 5
  8.    Dim TrackBar2_LargeChange As Int32 = 10
  9.  
  10.    ' GTrackBar [KeyDown]
  11.    Private Sub GTrackBars_KeyDown(sender As Object, e As KeyEventArgs) Handles GTrackBar1.KeyDown, GTrackBar2.KeyDown
  12.  
  13.        sender.ChangeSmall = 0
  14.        sender.ChangeLarge = 0
  15.  
  16.        Select Case e.KeyCode
  17.            Case Keys.Left, Keys.Right, Keys.Up, Keys.Down
  18.                MakeScroll_TrackBar(sender, e.KeyCode)
  19.        End Select
  20.  
  21.    End Sub
  22.  
  23.    ' GTrackBar [KeyUp]
  24.    Private Sub GTrackBars_KeyUp(sender As Object, e As KeyEventArgs) Handles GTrackBar1.KeyUp, GTrackBar2.KeyUp
  25.  
  26.        ' Set the values on KeyUp event because the Trackbar Scroll event.
  27.  
  28.        Select Case sender.Name
  29.            Case "GTrackBar1"
  30.                sender.ChangeSmall = TrackBar1_SmallChange
  31.                sender.ChangeLarge = TrackBar1_LargeChange
  32.            Case "GTrackBar_2"
  33.                sender.ChangeSmall = TrackBar2_SmallChange
  34.                sender.ChangeLarge = TrackBar2_LargeChange
  35.        End Select
  36.  
  37.    End Sub
  38.  
  39.    ' MakeScroll TrackBar
  40.    Private Sub MakeScroll_TrackBar(ByVal GTrackBar As gTrackBar.gTrackBar, key As Keys)
  41.  
  42.        Dim SmallChange As Int32 = 0, Largechange As Int32 = 0
  43.  
  44.        Select Case GTrackBar.Name
  45.            Case "GTrackBar1"
  46.                SmallChange = TrackBar1_SmallChange
  47.                Largechange = TrackBar1_LargeChange
  48.            Case "GTrackBar2"
  49.                SmallChange = TrackBar2_SmallChange
  50.                Largechange = TrackBar2_LargeChange
  51.        End Select
  52.  
  53.        Select Case key
  54.            Case Keys.Left
  55.                GTrackBar.Value -= SmallChange
  56.            Case Keys.Right
  57.                GTrackBar.Value += SmallChange
  58.            Case Keys.Up
  59.                GTrackBar.Value += Largechange
  60.            Case Keys.Down
  61.                GTrackBar.Value -= Largechange
  62.        End Select
  63.  
  64.    End Sub
  65.  
  66. #End Region
8823  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets) en: 5 Julio 2013, 05:06 am
Algo como esto en C#

Muy bueno Nov!, gracias, la verdad es que necesitaba simplificar esa función y eres el único de todo stackoverflow que ha llegado a conseguirlo xD.

Lo mismo pero en VB:

Código
  1.    Public Function Find_Dictionary_Key_By_Value(Of K, V)(Dictionary As Dictionary(Of K, V), Value As V) As K
  2.  
  3.        Dim Key = Dictionary.FirstOrDefault(Function(x) x.Value.Equals(Value)).Key
  4.  
  5.        If Key Is Nothing Then
  6.            Throw New Exception("The value is not found in the dictionary.")
  7.        End If
  8.  
  9.        Return Key
  10.  
  11.    End Function





http://foro.elhacker.net/net/libreria_de_snippets_posteen_aqui_sus_snippets-t378770.0.html;msg1857514#msg1857514

Siempre me salta la Excepción de Could not set keyboard hook

Que puedo hacer? :S

Se me olvidó mencionar este detalle:

Citar
Project -> Properties -> Debug -> Uncheck “Enable the Visual Studio hosting process”

Saludos!
8824  Sistemas Operativos / Windows / Re: ¿Alguien que tenga algún Windows que no sea el 7 podría hacerme un favor? en: 5 Julio 2013, 04:47 am
¿Os parece muy divertido meterse con un colaborador del foro y que ha sido moderador desde la época de los dinosaurios?

Yo os daría un baneo temporal a los 3 si pudiera, así de claro, ikillnukes incluido por seguir el juego.

Rando a veces puede ser el poli malo o el poli bueno, pero con los polis uno no se mete, se les respeta, porque te pueden sacar la porra.

Citar
No sabes aceptar comentarios de personas que no piensen de la misma forma que tú y llegas incluso a atacarlos.
Esto demuestra el poco aprecio que le tienes a tu tiempo, al de los demás y a ti mismo.

Lo único que demuestra eso es que algunos tienen poco sentido del humor, y lo pronto que nos gusta juzgar a las personas sin conocerlas, porque estás equivocado.

Saludos!
8825  Programación / Programación General / Re: crear un script necesito algún editor de texto en: 5 Julio 2013, 04:35 am
entonces en conclusión C ++ esto que es programar en pyton en perla o que ?? por que me estoy liando un poco

C++ es programar en C++.

No vas a poder hacer un generador de nada en un día, ni en 7, primero has de aprender el lenguaje lo suficiente (lo básico).

Como "Editor de C++" puedes usar "VISUAL C++ STUDIO", "NetBeans", y muchos más.
8826  Programación / .NET (C#, VB.NET, ASP) / Re: Customizar texto 2 o 3 veces dentro del mismo label? en: 5 Julio 2013, 04:20 am
Código
  1. Public Class Form1
  2.  
  3.    Dim bmp As New Bitmap("c:\1.png")
  4.  
  5.    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  6.        ' Blanco a Rojo
  7.        ' IMPORTANTE: Utilizar colores ARGB en el primer color
  8.        PictureBox1.BackgroundImage = Fill_Bitmap_Color(bmp, Color.FromArgb(255, 255, 255, 255), Color.Red)
  9.    End Sub
  10.  
  11.    Private Function Fill_Bitmap_Color(ByVal Image As Bitmap, ByVal FromColor As Color, ByVal ToColor As Color)
  12.  
  13.        Dim bmp As New Bitmap(Image)
  14.  
  15.        Dim x As Integer = 0, y As Integer = 0
  16.  
  17.        While x < bmp.Width
  18.            y = 0
  19.            While y < bmp.Height
  20.                If Image.GetPixel(x, y) = FromColor Then bmp.SetPixel(x, y, ToColor)
  21.                Math.Max(Threading.Interlocked.Increment(y), y - 1)
  22.            End While
  23.            Math.Max(Threading.Interlocked.Increment(x), x - 1)
  24.        End While
  25.  
  26.        Return bmp
  27.  
  28.    End Function
  29.  
  30. End Class

Ale, ya tienes media parte hecha ;)
8827  Programación / .NET (C#, VB.NET, ASP) / Re: Customizar texto 2 o 3 veces dentro del mismo label? en: 5 Julio 2013, 04:06 am
EDITO: No es posible con un Windows Form >:( ya me lo han confirmado por StackOverFlow :silbar:

Si que es posible, pero no pinta nada fácil.

Puedes tranformar parte del label a un bitmap, luego modificas el color del bitmap, y luego dibujas ese bitmap en las coordenadas equivalentes.

No se me ocurre otra manera.

Hay muchas cosas parecidas en google... -> http://www.codeproject.com/Articles/5133/Flood-Fill-Algorithms-in-C-and-GDI

Como ya digo... esto fácil no es.

Saludos
8828  Programación / .NET (C#, VB.NET, ASP) / Re: Librería de Snippets !! (Posteen aquí sus snippets) en: 4 Julio 2013, 11:24 am
Devolvuelve la Key equivalente de un Value de un dictionary:

Código
  1.    Public Function FindKeyByValue(Of TKey, TValue)(dictionary As Dictionary(Of TKey, TValue), value As TValue) As TKey
  2.  
  3.        For Each pair As KeyValuePair(Of TKey, TValue) In dictionary
  4.            If value.Equals(pair.Value) Then Return pair.Key
  5.        Next
  6.  
  7.        ' Throw New Exception("The value is not found in the dictionary.")
  8.        Return Nothing
  9.    End Function
8829  Programación / Programación General / Re: crear un script necesito algún editor de texto en: 4 Julio 2013, 00:53 am
Es que no entiendes el concepto.

Un editor de texto sirve para escribir, puedes exribir un script o una poesia, pero si luego quieres ejecutar ese script, necesitas el intérprete de ese lenguaje.

Yo para lo relacionado con las permutaciones y operaciones de archivos a mansalva (porque necesitarás escribir horas y horas datos en archivos, y además cortar cientos de archivos de texto de largas combnaciones si quieres abrir el archivo sin que se coma toda la RAM...) te recomiendo C# o VBNET, nada de scripting, pero si prefieres el scripting pues Python, Perl, o Ruby, como ya te dije, aunque deberías mirar primero algunas comparaciones de velocidad entre esos trés lenguajes de scripting.

Te digo lo mismo que antes, elige un lenguaje, y luego descargatelo y descárgate el IDE, una IDE es una especie de "editor" especial para ese lenguaje, suele haber varias IDEs NO oficiales para cada lenguaje, así que hay donde elegir, pero no me uses nada de editores de texto como notepad++ ni cosas así, eso es para cuando ya sabes escribir código de forma avanzada sin cometer errores de sintaxis entonces con un editor de texto lo escribes sin preocupaciones y en poco tiempo, como en Batch por ejemplo, que los scripts de Batch se escriben en el notepad porque es muy sencillo. Un buen IDE te suele facilitar las cosas, auto-indentación, debug, auto-correción, intellisense, etc. un buen editor de texto como mucho tiene resaltado de sintaxis y "sugerencias" de keywords, no me puedes comparar un IDE con un editor de texto.

De todas formas si no me quieres hacer mucho caso y te empeñas con lo dle editor de texto, el que yo uso es "Sublime Text" (craqueado): http://www.sublimetext.com/

bueno,
saludos!
8830  Sistemas Operativos / Windows / Re: ¿Alguien que tenga algún Windows que no sea el 7 podría hacerme un favor? en: 3 Julio 2013, 21:25 pm
Lo probaré en XP y Vista a ver si va :rolleyes:

no creo que sea necesario hacer pruebas en el windows Bestia ese xD
Páginas: 1 ... 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 [883] 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 ... 1254
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines