|
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.)  Dim LastSelectedItem As Int32 = -1 Private Sub ComboBoxTooltip_DropdownItemSelected(sender As Object, e As ComboBoxTooltip.DropdownItemSelectedEventArgs) _ Handles ComboBoxTooltip1.DropdownItemSelected Dim SelectedItem As Int32 = e.SelectedItem If SelectedItem <> LastSelectedItem Then ToolTip1.Hide(sender) LastSelectedItem = -1 End If If SelectedItem < 0 OrElse e.Scrolled Then ToolTip1.Hide(sender) LastSelectedItem = -1 Else If sender.Items(e.SelectedItem).Length > CInt(sender.CreateGraphics.MeasureString(0, sender.Font).Width) + 8 Then LastSelectedItem = SelectedItem ToolTip1.Show(sender.Items(SelectedItem).ToString(), sender, e.Bounds.Location) End If End If End Sub
Es necesario este usercontrol: using System; using System.Drawing; using System.Windows.Forms; using System.Runtime.InteropServices; public class ComboBoxTooltip : ComboBox { private DropdownWindow mDropdown; public delegate void DropdownItemSelectedEventHandler(object sender, DropdownItemSelectedEventArgs e); public event DropdownItemSelectedEventHandler DropdownItemSelected; protected override void OnDropDown(EventArgs e) { // Install wrapper base.OnDropDown(e); // Retrieve handle to dropdown list COMBOBOXINFO info = new COMBOBOXINFO (); info .cbSize = Marshal .SizeOf(info ); SendMessageCb(this.Handle, 0x164, IntPtr.Zero, out info); mDropdown = new DropdownWindow (this); mDropdown.AssignHandle(info.hwndList); } protected override void OnDropDownClosed(EventArgs e) { // Remove wrapper mDropdown.ReleaseHandle(); mDropdown = null; base.OnDropDownClosed(e); OnSelect(-1, Rectangle.Empty, true); } internal void OnSelect(int item, Rectangle pos, bool scroll) { if (this.DropdownItemSelected != null) { pos = this.RectangleToClient(pos); DropdownItemSelected (this, new DropdownItemSelectedEventArgs (item, pos, scroll )); } } // Event handler arguments public class DropdownItemSelectedEventArgs : EventArgs { private int mItem; private Rectangle mPos; private bool mScroll; public DropdownItemSelectedEventArgs(int item, Rectangle pos, bool scroll) { mItem = item; mPos = pos; mScroll = scroll; } public int SelectedItem { get { return mItem; } } public Rectangle Bounds { get { return mPos; } } public bool Scrolled { get { return mScroll; } } } // Wrapper for combobox dropdown list private class DropdownWindow : NativeWindow { private ComboBoxTooltip mParent; private int mItem; public DropdownWindow(ComboBoxTooltip parent) { mParent = parent; mItem = -1; } protected override void WndProc(ref Message m) { // All we're getting here is WM_MOUSEMOVE, ask list for current selection for LB_GETCURSEL Console.WriteLine(m.ToString()); base.WndProc(ref m); if (m.Msg == 0x200) { int item = (int)SendMessage(this.Handle, 0x188, IntPtr.Zero, IntPtr.Zero); if (item != mItem) { mItem = item; OnSelect(false); } } if (m.Msg == 0x115) { // List scrolled, item position would change OnSelect(true); } } private void OnSelect(bool scroll) { SendMessageRc(this.Handle, 0x198, (IntPtr)mItem, out rc); MapWindowPoints(this.Handle, IntPtr.Zero, ref rc, 2); mParent.OnSelect(mItem, Rectangle.FromLTRB(rc.Left, rc.Top, rc.Right, rc.Bottom), scroll); } } // P/Invoke declarations private struct COMBOBOXINFO { public Int32 cbSize; public RECT rcItem; public RECT rcButton; public int buttonState; public IntPtr hwndCombo; public IntPtr hwndEdit; public IntPtr hwndList; } [StructLayout(LayoutKind.Sequential)] private struct RECT { public int Left; public int Top; public int Right; public int Bottom; } [DllImport("user32.dll", EntryPoint = "SendMessageW", CharSet = CharSet.Unicode)] private static extern IntPtr SendMessageCb(IntPtr hWnd, int msg, IntPtr wp, out COMBOBOXINFO lp); [DllImport("user32.dll", EntryPoint = "SendMessageW", CharSet = CharSet.Unicode)] private static extern IntPtr SendMessageRc(IntPtr hWnd, int msg, IntPtr wp, out RECT lp); [DllImport("user32.dll")] private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp); [DllImport("user32.dll")] private static extern int MapWindowPoints(IntPtr hWndFrom, IntPtr hWndTo, [In, Out] ref RECT rc, int points); }
|
|
|
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 #Region " Fill Bitmap Color " ' [ Fill Bitmap Color Function ] ' ' Examples : ' ' IMPORTANT: use ARGB colors as the parameter. ' PictureBox1.BackgroundImage = Fill_Bitmap_Color(bmp, Color.FromArgb(255, 255, 255, 255), Color.Red) Private Function Fill_Bitmap_Color(ByVal Image As Bitmap, ByVal FromColor As Color, ByVal ToColor As Color) Dim bmp As New Bitmap(Image) Dim x As Integer = 0, y As Integer = 0 While x < bmp.Width y = 0 While y < bmp.Height If Image.GetPixel(x, y) = FromColor Then bmp.SetPixel(x, y, ToColor) Math.Max(Threading.Interlocked.Increment(y), y - 1) End While Math.Max(Threading.Interlocked.Increment(x), x - 1) End While Return bmp End Function #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' By Elektro H@cker #Region " [GTrackBar] Progressive Scroll " Dim TrackBar_SmallChange As Int32 = 5 Dim TrackBar_LargeChange As Int32 = 10 ' GTrackBar [KeyDown] Private Sub GTrackBar_KeyDown(sender As Object, e As KeyEventArgs) Handles GTrackBar1.KeyDown sender.ChangeSmall = 0 sender.ChangeLarge = 0 Select Case e.KeyCode Case Keys.Left, Keys.Right, Keys.Up, Keys.Down MakeScroll_TrackBar(sender, e.KeyCode) End Select End Sub ' GTrackBar [KeyUp] Private Sub GTrackBar_KeyUp(sender As Object, e As KeyEventArgs) Handles GTrackBar1.KeyUp ' Set the values on KeyUp event because the Trackbar Scroll event. sender.ChangeSmall = TrackBar_SmallChange sender.ChangeLarge = TrackBar_LargeChange End Sub ' MakeScroll TrackBar Private Sub MakeScroll_TrackBar(ByVal GTrackBar As gTrackBar.gTrackBar, key As Keys) Select Case key Case Keys.Left GTrackBar.Value -= TrackBar_SmallChange Case Keys.Right GTrackBar.Value += TrackBar_SmallChange Case Keys.Up GTrackBar.Value += TrackBar_LargeChange Case Keys.Down GTrackBar.Value -= TrackBar_LargeChange End Select End Sub #End Region
...Lo mismo pero si tenemos múltiples GTrackbars: ' By Elektro H@cker #Region " [GTrackBar] Progressive Scroll MultiTrackbars " Dim TrackBar1_SmallChange As Int32 = 2 Dim TrackBar1_LargeChange As Int32 = 5 Dim TrackBar2_SmallChange As Int32 = 5 Dim TrackBar2_LargeChange As Int32 = 10 ' GTrackBar [KeyDown] Private Sub GTrackBars_KeyDown(sender As Object, e As KeyEventArgs) Handles GTrackBar1.KeyDown, GTrackBar2.KeyDown sender.ChangeSmall = 0 sender.ChangeLarge = 0 Select Case e.KeyCode Case Keys.Left, Keys.Right, Keys.Up, Keys.Down MakeScroll_TrackBar(sender, e.KeyCode) End Select End Sub ' GTrackBar [KeyUp] Private Sub GTrackBars_KeyUp(sender As Object, e As KeyEventArgs) Handles GTrackBar1.KeyUp, GTrackBar2.KeyUp ' Set the values on KeyUp event because the Trackbar Scroll event. Select Case sender.Name Case "GTrackBar1" sender.ChangeSmall = TrackBar1_SmallChange sender.ChangeLarge = TrackBar1_LargeChange Case "GTrackBar_2" sender.ChangeSmall = TrackBar2_SmallChange sender.ChangeLarge = TrackBar2_LargeChange End Select End Sub ' MakeScroll TrackBar Private Sub MakeScroll_TrackBar(ByVal GTrackBar As gTrackBar.gTrackBar, key As Keys) Dim SmallChange As Int32 = 0, Largechange As Int32 = 0 Select Case GTrackBar.Name Case "GTrackBar1" SmallChange = TrackBar1_SmallChange Largechange = TrackBar1_LargeChange Case "GTrackBar2" SmallChange = TrackBar2_SmallChange Largechange = TrackBar2_LargeChange End Select Select Case key Case Keys.Left GTrackBar.Value -= SmallChange Case Keys.Right GTrackBar.Value += SmallChange Case Keys.Up GTrackBar.Value += Largechange Case Keys.Down GTrackBar.Value -= Largechange End Select End Sub #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: Public Function Find_Dictionary_Key_By_Value (Of K, V )(Dictionary As Dictionary(Of K, V ), Value As V ) As K Dim Key = Dictionary. FirstOrDefault(Function(x ) x. Value. Equals(Value )). Key If Key Is Nothing Then Throw New Exception("The value is not found in the dictionary.") End If Return Key End Function
Se me olvidó mencionar este detalle: 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. 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
|
Public Class Form1 Dim bmp As New Bitmap("c:\1.png") Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load ' Blanco a Rojo ' IMPORTANTE: Utilizar colores ARGB en el primer color PictureBox1.BackgroundImage = Fill_Bitmap_Color(bmp, Color.FromArgb(255, 255, 255, 255), Color.Red) End Sub Private Function Fill_Bitmap_Color(ByVal Image As Bitmap, ByVal FromColor As Color, ByVal ToColor As Color) Dim bmp As New Bitmap(Image) Dim x As Integer = 0, y As Integer = 0 While x < bmp.Width y = 0 While y < bmp.Height If Image.GetPixel(x, y) = FromColor Then bmp.SetPixel(x, y, ToColor) Math.Max(Threading.Interlocked.Increment(y), y - 1) End While Math.Max(Threading.Interlocked.Increment(x), x - 1) End While Return bmp End Function End Class
Ale, ya tienes media parte hecha 
|
|
|
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!
|
|
|
|
|
|
|