Click here to Skip to main content

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrasing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: conscious perma-coupling PinmemberShameel21-Apr-14 1:53 
GeneralRe: conscious perma-coupling PinmemberBobJanova22-Apr-14 0:58 
GeneralRe: conscious perma-coupling PinprofessionalDuncan Edwards Jones22-Apr-14 1:10 
GeneralRe: conscious perma-coupling PinmemberJacek Gajek30-Apr-14 23:18 
GeneralRtf -WTF: why is it different? PinprofessionalBernhard Hiller15-Apr-14 5:56 
GeneralRe: Rtf -WTF: why is it different? Pinmemberledtech315-Apr-14 6:11 
GeneralRe: Rtf -WTF: why is it different? PinprofessionalBernhard Hiller15-Apr-14 21:55 
GeneralRe: Rtf -WTF: why is it different? Pinmemberledtech316-Apr-14 5:28 
Try this test to get a better Idea.
Create a test project with a richtextbox and a normal text box.
 
two buttons and a label to show the length
 
In VB.net it would look like.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim selLen As Integer
 
    Dim selectedRtf As String = RichTextBox1.SelectedRtf
    selLen = selectedRtf.Length
    Label1.Text = selLen.ToString
    TextBox1.Text = selectedRtf
End Sub
 
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Dim selLen As Integer
 
    Dim selectedRtf As String = RichTextBox1.Rtf
    selLen = selectedRtf.Length
    Label1.Text = selLen.ToString
    TextBox1.Text = selectedRtf
End Sub
 
Using a converter to convert to C# it would look like this.
private void Button1_Click(System.Object sender, System.EventArgs e)
{
    int selLen = 0;
 
    string selectedRtf = RichTextBox1.SelectedRtf;
    selLen = selectedRtf.Length;
    Label1.Text = selLen.ToString;
    TextBox1.Text = selectedRtf;
}
 
private void Button2_Click(System.Object sender, System.EventArgs e)
{
    int selLen = 0;
 
    string selectedRtf = RichTextBox1.Rtf;
    selLen = selectedRtf.Length;
    Label1.Text = selLen.ToString;
    TextBox1.Text = selectedRtf;
}
 
Next create some text in wordpad with different formating. Copy paste to the richtextbox (ctl+V)
what this code does is gets the length of the string, the entire string with the hidden formating and copies it to the plain textbox to view all of it.
You can add the line to select all or just select it on the RTF box.
 
After going back and forth between the buttons you may notice that the second one shows more formatting and thus it is longer.
GeneralRe: Rtf -WTF: why is it different? PinmemberRob Grainger16-Apr-14 1:08 
GeneralRe: Rtf -WTF: why is it different? PinprofessionalManikandan1011-Jun-14 4:31 
General#region PinprofessionalBernhard Hiller11-Apr-14 3:51 
GeneralRe: #region Pinmembertgrt11-Apr-14 4:58 
GeneralRe: #region PinprotectorOriginalGriff11-Apr-14 6:41 
GeneralRe: #region PinprofessionalBernhard Hiller13-Apr-14 21:40 
GeneralRe: #region PinprotectorOriginalGriff13-Apr-14 22:00 
GeneralRe: #region PinprofessionalBrisingr Aerowing11-Apr-14 6:46 
GeneralRe: #region PinmemberShameel21-Apr-14 1:57 
GeneralRe: #region PinmemberBobJanova11-Apr-14 7:51 
GeneralRe: #region PinprofessionalRichard Andrew x6411-Apr-14 9:29 
JokeRe: #region PinmemberSander Rossel24-Apr-14 8:33 
GeneralRe: #region PinmemberGiuseppe Tollini24-May-14 2:05 
GeneralRe: #region PinprofessionalBernhard Hiller29-May-14 21:59 
GeneralHow not to create an instance of a singleton PinprofessionalDennis_E11-Apr-14 0:59 
JokeRe: How not to create an instance of a singleton PinprofessionalNicholas Marty11-Apr-14 1:25 
GeneralRe: How not to create an instance of a singleton PinprotectorMarc Clifton11-Apr-14 2:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 26 Dec 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid