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

 

 


Tema destacado:


  Mostrar Temas
Páginas: [1]
1  Programación / .NET (C#, VB.NET, ASP) / cb0t Ares Chat Client en: 9 Enero 2013, 01:51 am
cb0t Ares Chat Client is an open source application which allows users to access chatrooms on the Ares p2p network. It offers some additional features over and above the default Ares chat client, for example, you can send and receive images and voice clips. In this newest version I have added a whole list of minor bug fixes, some of which will aid performance and stability so it is probably worth taking the time to update.

Visit the download section for cb0t 2.69.

The latest source code has also been uploaded and available in the Source Code section.

Enjoy. :-)





http://www.mediafire.com/?93zqusjwurvcsz1
2  Programación / .NET (C#, VB.NET, ASP) / Ayuda con mi funcion de colores RTF en: 8 Enero 2013, 18:17 pm
Buenas amigos les cuento que estoy haciendo una funcion RTF de colores todo funciona bien colores cursiva etcc, pero lo unico que la funcion es lenta convierte los colores demasiado lento para lo que yo quiero aver si alguien que entienda el tema se le ocurre alguna idea de hacerlo mas rapido les dejo el source a continuacion.

CODIGO:

Código:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Tag_Maker_Multiline_Example
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void text1_TextChanged(object sender, EventArgs e)
        {
            //Variables para el armar el archivo
            string start = "{" + "\\rtf1" + "\\ansi" + "\\ansicpg1252" + "\\deff0" + "\\deflang3082" + "{" + "\\fonttbl" + "{" + "\\f0" + "\\fnil" + "\\fcharset0 Arial Unicode MS" + ";" + "}" + "}";
            string start2 = "\\viewkind4" + "\\uc1" + "\\pard" + "\\f0" + "\\fs17";
            string ctbl = "{\\colortbl ;\\red0\\green0\\blue0;\\red128\\green0\\blue0;\\red0\\green128\\blue0;\\red255\\green128\\blue0;\\red0\\green0\\blue128;\\red128\\green0\\blue128;\\red0\\green128\\blue128;\\red128\\green128\\blue128;\\red192\\green192\\blue192;\\red255\\green0\\blue0;\\red0\\green255\\blue0;\\red255\\green255\\blue0;\\red0\\green0\\blue255;\\red255\\green0\\blue255;\\red0\\green255\\blue255;\\red255\\green255\\blue255;}";
            string end = "\\par" + "\n" + "}" + "\n" + "\0";
            
            //Variables auxiliares
            string str;
            string txt = null;
            string txt2 = null;

            int index;

            //Almacemanos el texto de "text1" en una variable con un código de color de Ares equivalente al rojo.
            //De esta forma, cuando se reeplacen los códigos y si no se ha añadido ningún color...
            //se verá el texto en rojo (el mismo color por defecto en ares).
            string aux = "304" + text1.Text;

            //Almacenamos el texto en rtf1.Text
            rtf1.Text = aux;

            //Almacenamos el código rtf resultante en una variable (aún sin los códigos reemplazados)
            str = rtf1.Rtf;

            //En el ejemplo de tag_maker de una sóla línea, iría a continuación directamente el código de reemplazo.
            //Pero en lugar de ello colocarémos un bucle que repetirá el proceso varias veces...
            //Tomará línea por línea y reemplazará los códigos de colores independientemente en cada una de ellas,
            //añandiendo al final de cada una y junto a un salto de línea, los códigos para quitar estilos y colores
            //de manera que no interfieran con la siguiente.
            
            while (true)
            {
                //Se busca un salto de línea para comprobar si el texto es multilínea
                index = str.IndexOf("\n");

                //Si no se encuentra el salto.. entonces se reemplazan los códigos, se almacena en una variable
                //y se sale del bucle.
                if (index == -1)
                {
                    txt2 = txt2 + colorDec(str); break;
                }

                //Si se llega a esta parte.. es porque hay un salto de linea y el bucle no ha sido detenido.
                //Se extrae la primer línea, se almacena en una variable y se remueve de la original.
                txt = str.Substring(0, index);
                str = str.Remove(0, index + 1);

                //Se almacena la línea en una variable junto a las demás y se le añaden los códigos extra al final.
                //Nota: En lugar del código para quitar color de fuente, agrego uno para aplicar el rojo (\\cf10).
                txt2 = txt2 + colorDec(txt) + "\\b0 \\ul0 \\i0 \\cf10 \\highlight0 \n";
            }

            //Luego de finalizado el bucle, toca armar el archivo completo con los códigos ya reemplazados.

            //Remuevo restos de códigos de estilo que puedan causar una visualización erronea
            txt2 = txt2.Replace("lang3082\\ul\\", "lang3082\\");
            txt2 = txt2.Replace("lang3082\\b\\", "lang3082\\");
            txt2 = txt2.Replace("lang3082\\i\\", "lang3082\\");

            //Remuevo restos de códigos de color que puedan causar una visualización erronea
            for (int i = 1; i <= 15; i++)
            {
                txt2 = txt2.Replace("pard\\highlight" + Convert.ToString(i), "pard");
                txt2 = txt2.Replace("pard\\cf1\\highlight" + Convert.ToString(i), "pard");
            }

            rtf1.Clear();
            rtf1.Rtf = start + ctbl + start2 + txt2 + end;

        }

        //Función de reemplazo de códigos de color. Retorna un string con los códigos reemplazados.
        public string colorDec(string rtf)
        {
            int index = 0;

            //Reemplazo de códigos de color.
            rtf = rtf.Replace("\\\'02300", "\\cf16 ");
            rtf = rtf.Replace("\\\'02301", "\\cf1 ");
            rtf = rtf.Replace("\\\'02305", "\\cf2 ");
            rtf = rtf.Replace("\\\'02303", "\\cf3 ");
            rtf = rtf.Replace("\\\'02307", "\\cf4 ");
            rtf = rtf.Replace("\\\'02302", "\\cf5 ");
            rtf = rtf.Replace("\\\'02306", "\\cf6 ");
            rtf = rtf.Replace("\\\'02310", "\\cf7 ");
            rtf = rtf.Replace("\\\'02314", "\\cf8 ");
            rtf = rtf.Replace("\\\'02315", "\\cf9 ");
            rtf = rtf.Replace("\\\'02304", "\\cf10 ");
            rtf = rtf.Replace("\\\'02309", "\\cf11 ");
            rtf = rtf.Replace("\\\'02308", "\\cf12 ");
            rtf = rtf.Replace("\\\'02312", "\\cf13 ");
            rtf = rtf.Replace("\\\'02313", "\\cf14 ");
            rtf = rtf.Replace("\\\'02311", "\\cf15 ");
            rtf = rtf.Replace("\\\'02500", "\\highlight0 ");
            rtf = rtf.Replace("\\\'02501", "\\highlight1 ");
            rtf = rtf.Replace("\\\'02505", "\\highlight2 ");
            rtf = rtf.Replace("\\\'02503", "\\highlight3 ");
            rtf = rtf.Replace("\\\'02507", "\\highlight4 ");
            rtf = rtf.Replace("\\\'02502", "\\highlight5 ");
            rtf = rtf.Replace("\\\'02506", "\\highlight6 ");
            rtf = rtf.Replace("\\\'02510", "\\highlight7 ");
            rtf = rtf.Replace("\\\'02514", "\\highlight8 ");
            rtf = rtf.Replace("\\\'02515", "\\highlight9 ");
            rtf = rtf.Replace("\\\'02504", "\\highlight10 ");
            rtf = rtf.Replace("\\\'02509", "\\highlight11 ");
            rtf = rtf.Replace("\\\'02508", "\\highlight12 ");
            rtf = rtf.Replace("\\\'02512", "\\highlight13 ");
            rtf = rtf.Replace("\\\'02513", "\\highlight14 ");
            rtf = rtf.Replace("\\\'02511", "\\highlight15 ");

            //Reemplazo de código - Negrita    
            do
            {
                try
                {
                    index = rtf.IndexOf("\\\'026");
                    rtf = rtf.Remove(index, 5);
                    rtf = rtf.Insert(index, "\\b ");

                    index = rtf.IndexOf("\\\'026");
                    rtf = rtf.Remove(index, 5);
                    rtf = rtf.Insert(index, "\\b0 ");
                }
                catch { }
            } while (index > -1);


            //Reemplazo de código - Subrayado    
            do
            {
                try
                {
                    index = rtf.IndexOf("\\\'027");
                    rtf = rtf.Remove(index, 5);
                    rtf = rtf.Insert(index, "\\ul ");

                    index = rtf.IndexOf("\\\'027");
                    rtf = rtf.Remove(index, 5);
                    rtf = rtf.Insert(index, "\\ul0 ");
                }
                catch { }
            } while (index > -1);


            //Reemplazo de código - Cursiva    
            do
            {
                try
                {
                    index = rtf.IndexOf("\\\'029");
                    rtf = rtf.Remove(index, 5);
                    rtf = rtf.Insert(index, "\\i ");

                    index = rtf.IndexOf("\\\'029");
                    rtf = rtf.Remove(index, 5);
                    rtf = rtf.Insert(index, "\\i0 ");
                }
                catch { }
            } while (index > -1);

            return rtf;

        }

        private void rtf1_TextChanged(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        /*La diferencia a destacar, con respecto al ejemplo de una sóla línea, es únicamente el
         bucle que he añadido, que se encarga de tomar línea por línea y hacer el reemplazo de códigos
         independiente en cada una de ellas.
          
         _-_-_-_- Diferencias de menor importancia:
         * Otra diferencia, pero no del todo necesaria.. es la función que utilicé para almacenar los
         códigos de reemplazo y hacer que este ejemplo sea un poco más legible.
         * Otra diferencia menor se encuentra al final, justo antes de armarse el archivo.. donde he
         tenido que quitar códigos rtf que quedan aún después del Clear() y producen una visualización
         erronea de los colores.
         */

        
    }
}

DESCARGAR EL SOURCE PARA QUE PUEDAN VER MEJOR
http://www.mediafire.com/?o5y5z3j6874418x
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines