Ver Mensaje Individual
  #1 (permalink)  
Antiguo 04/08/2010, 11:19
Avatar de Nekeniehl
Nekeniehl
 
Fecha de Ingreso: julio-2009
Ubicación: Berlin, Alemania / Granada, España
Mensajes: 132
Antigüedad: 15 años, 7 meses
Puntos: 6
Aplicar diferentes fuentes a una cadena - C#

Pues básicamente la duda es esa, estoy haciendo una tonteria para hacer los primeros pinitos en c#, es un generador de nick con un "live view", la cosa es que necesito aplicar diferentes estilos a una misma cadena de texto, por ejemplo:

"Esto es un ejemplo de lo que necesito"
Y la cosa está chunga, por que no tengo ni idea de aplicar fonts, a un textfield si, pero no a una cadena, para que entendais un poquito el código si encuentro "$i" es italic por ejemplo.

Os pego lo que tengo..

Código c#:
Ver original
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace NickCreator
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         String nick = "";
  15.         String live = "";
  16.         String formato = "";
  17.         public Form1()
  18.         {
  19.             InitializeComponent();
  20.         }
  21.  
  22.         private void Copiar_Click(object sender, EventArgs e)
  23.         {
  24.             tNick.SelectAll();
  25.             tNick.Copy();
  26.         }
  27.  
  28.         private void Limpiar_Click(object sender, EventArgs e)
  29.         {
  30.             tNick.Text = "";
  31.             tLive.Text = "";
  32.         }
  33.  
  34.         private void tNick_TextChanged(object sender, EventArgs e)
  35.         {
  36.             MostrarLive(nick, formato);
  37.         }
  38.  
  39.         private void MostrarLive(String nick, String formato)
  40.         {
  41.             tLive.Text = tNick.Text;
  42.         }
  43.         private void cBFormato_KeyPress(object sender, KeyPressEventArgs e)
  44.         {
  45.             e.Handled = true;
  46.         }
  47.  
  48.         private void Form1_Shown(object sender, EventArgs e)
  49.         {
  50.             tNick.Focus();
  51.         }
  52.  
  53.         private void cBFormato_SelectedIndexChanged(object sender, EventArgs e)
  54.         {
  55.             DevolverFormato();
  56.             TransformarNick();
  57.         }
  58.         private void TransformarNick()
  59.         {
  60.             formato = DevolverFormato();
  61.             int tamaño = nick.Length;
  62.             int posCursor = tNick.SelectionStart;
  63.             nick = tNick.Text;
  64.             String prin = nick.Substring(0, posCursor);
  65.             prin = prin + formato;
  66.             String fin = nick.Substring(posCursor);
  67.             prin = prin + fin;
  68.             nick = prin;
  69.             tNick.Text = nick;
  70.             TransformarLive();
  71.         }
  72.         private void TransformarLive()
  73.         {
  74.             live = tNick.Text;
  75.             int pos = live.IndexOf("$i");
  76.             int tam = live.Length;
  77.             String cad = live.Substring(0, pos);
  78.         }
  79.         private String DevolverFormato()
  80.         {
  81.             int a = cBFormato.SelectedIndex;
  82.             formato = "";
  83.             switch (a)
  84.             {
  85.                 case 0: formato = "$t";
  86.                     break;
  87.                 case 1: formato = "$i";
  88.                     break;
  89.                 case 2: formato = "$w";
  90.                     break;
  91.                 case 3: formato = "$n";
  92.                     break;
  93.                 case 4: formato = "$g";
  94.                     break;
  95.                 case 5: formato = "$m";
  96.                     break;
  97.                 case 6: formato = "$z";
  98.                     break;
  99.             }
  100.             return formato;
  101.         }
  102.  
  103.         private void tNick_KeyPress(object sender, KeyPressEventArgs e)
  104.         {
  105.         }
  106.     }

Alguna idea de por donde tengo que encaminarme?, gracias y un saludo.
__________________
Antes de cambiar el mundo...dá tres vueltas por tu casa

Usa Google es tu amigo ;)