Click here to Skip to main content
11,635,656 members (79,717 online)

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: Thinking Inside the Box Pin
Nagy Vilmos29-Apr-14 11:05
professionalNagy Vilmos29-Apr-14 11:05 
GeneralRe: Thinking Inside the Box Pin
kmoorevs29-Apr-14 11:51
memberkmoorevs29-Apr-14 11:51 
GeneralRe: Thinking Inside the Box Pin
OriginalGriff30-Apr-14 8:13
protectorOriginalGriff30-Apr-14 8:13 
GeneralRe: Thinking Inside the Box Pin
Argonia30-Apr-14 5:00
professionalArgonia30-Apr-14 5:00 
GeneralRe: Thinking Inside the Box Pin
RyanDev29-Apr-14 12:52
mvpRyanDev29-Apr-14 12:52 
Generalconscious perma-coupling Pin
Duncan Edwards Jones20-Apr-14 12:17
professionalDuncan Edwards Jones20-Apr-14 12:17 
GeneralRe: conscious perma-coupling Pin
Shameel21-Apr-14 0:53
memberShameel21-Apr-14 0:53 
GeneralRe: conscious perma-coupling Pin
BobJanova21-Apr-14 23:58
memberBobJanova21-Apr-14 23:58 
GeneralRe: conscious perma-coupling Pin
Duncan Edwards Jones22-Apr-14 0:10
professionalDuncan Edwards Jones22-Apr-14 0:10 
GeneralRe: conscious perma-coupling Pin
Jacek Gajek30-Apr-14 22:18
memberJacek Gajek30-Apr-14 22:18 
GeneralRtf -WTF: why is it different? Pin
Bernhard Hiller15-Apr-14 4:56
professionalBernhard Hiller15-Apr-14 4:56 
GeneralRe: Rtf -WTF: why is it different? Pin
ledtech315-Apr-14 5:11
memberledtech315-Apr-14 5:11 
GeneralRe: Rtf -WTF: why is it different? Pin
Bernhard Hiller15-Apr-14 20:55
professionalBernhard Hiller15-Apr-14 20:55 
GeneralRe: Rtf -WTF: why is it different? Pin
ledtech316-Apr-14 4:28
memberledtech316-Apr-14 4: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? Pin
Rob Grainger16-Apr-14 0:08
memberRob Grainger16-Apr-14 0:08 
GeneralRe: Rtf -WTF: why is it different? Pin
Manikandan1011-Jun-14 3:31
professionalManikandan1011-Jun-14 3:31 
General#region Pin
Bernhard Hiller11-Apr-14 2:51
professionalBernhard Hiller11-Apr-14 2:51 
GeneralRe: #region Pin
tgrt11-Apr-14 3:58
membertgrt11-Apr-14 3:58 
GeneralRe: #region Pin
OriginalGriff11-Apr-14 5:41
protectorOriginalGriff11-Apr-14 5:41 
GeneralRe: #region Pin
Bernhard Hiller13-Apr-14 20:40
professionalBernhard Hiller13-Apr-14 20:40 
GeneralRe: #region Pin
OriginalGriff13-Apr-14 21:00
protectorOriginalGriff13-Apr-14 21:00 
GeneralRe: #region Pin
Brisingr Aerowing11-Apr-14 5:46
professionalBrisingr Aerowing11-Apr-14 5:46 
GeneralRe: #region Pin
Shameel21-Apr-14 0:57
memberShameel21-Apr-14 0:57 
GeneralRe: #region Pin
BobJanova11-Apr-14 6:51
memberBobJanova11-Apr-14 6:51 
GeneralRe: #region Pin
Richard Andrew x6411-Apr-14 8:29
professionalRichard Andrew x6411-Apr-14 8:29 
JokeRe: #region Pin
Sander Rossel24-Apr-14 7:33
memberSander Rossel24-Apr-14 7:33 
GeneralRe: #region Pin
Giuseppe Tollini24-May-14 1:05
memberGiuseppe Tollini24-May-14 1:05 
GeneralRe: #region Pin
Bernhard Hiller29-May-14 20:59
professionalBernhard Hiller29-May-14 20:59 
GeneralHow not to create an instance of a singleton Pin
Dennis_E10-Apr-14 23:59
professionalDennis_E10-Apr-14 23:59 
JokeRe: How not to create an instance of a singleton Pin
Nicholas Marty11-Apr-14 0:25
professionalNicholas Marty11-Apr-14 0:25 
GeneralRe: How not to create an instance of a singleton Pin
Marc Clifton11-Apr-14 1:40
protectorMarc Clifton11-Apr-14 1:40 
GeneralRe: How not to create an instance of a singleton Pin
Nicholas Marty11-Apr-14 3:16
professionalNicholas Marty11-Apr-14 3:16 
GeneralRe: How not to create an instance of a singleton Pin
Marc Clifton11-Apr-14 4:52
protectorMarc Clifton11-Apr-14 4:52 
GeneralRe: How not to create an instance of a singleton Pin
Dennis_E24-Apr-14 1:16
professionalDennis_E24-Apr-14 1:16 
GeneralRe: How not to create an instance of a singleton Pin
Nicholas Marty24-Apr-14 3:20
professionalNicholas Marty24-Apr-14 3:20 
GeneralRe: How not to create an instance of a singleton Pin
BobJanova11-Apr-14 6:50
memberBobJanova11-Apr-14 6:50 
GeneralRe: How not to create an instance of a singleton Pin
Bernhard Hiller11-Apr-14 2:21
professionalBernhard Hiller11-Apr-14 2:21 
GeneralRe: How not to create an instance of a singleton Pin
OriginalGriff11-Apr-14 5:42
protectorOriginalGriff11-Apr-14 5:42 
GeneralRe: How not to create an instance of a singleton Pin
Jacek Gajek29-Apr-14 10:51
memberJacek Gajek29-Apr-14 10:51 
GeneralThere is nothing new under the sun... Pin
Duncan Edwards Jones9-Apr-14 7:22
professionalDuncan Edwards Jones9-Apr-14 7:22 
GeneralRe: There is nothing new under the sun... Pin
I.explore.code9-Apr-14 7:41
memberI.explore.code9-Apr-14 7:41 
GeneralRe: There is nothing new under the sun... Pin
Chris Maunder9-Apr-14 7:55
adminChris Maunder9-Apr-14 7:55 
GeneralRe: There is nothing new under the sun... Pin
Kornfeld Eliyahu Peter9-Apr-14 10:05
professionalKornfeld Eliyahu Peter9-Apr-14 10:05 
GeneralRe: There is nothing new under the sun... Pin
Rob Grainger10-Apr-14 23:30
memberRob Grainger10-Apr-14 23:30 
GeneralRe: There is nothing new under the sun... Pin
Duncan Edwards Jones10-Apr-14 23:49
professionalDuncan Edwards Jones10-Apr-14 23:49 
GeneralRe: There is nothing new under the sun... Pin
Sander Rossel24-Apr-14 7:42
memberSander Rossel24-Apr-14 7:42 
GeneralHow not to do transaction processing Pin
Rob Grainger9-Apr-14 6:12
memberRob Grainger9-Apr-14 6:12 
GeneralRe: How not to do transaction processing Pin
Duncan Edwards Jones9-Apr-14 7:13
professionalDuncan Edwards Jones9-Apr-14 7:13 
GeneralRe: How not to do transaction processing Pin
Rob Grainger10-Apr-14 4:12
memberRob Grainger10-Apr-14 4:12 
GeneralRe: How not to do transaction processing Pin
W Balboos11-Apr-14 1:14
memberW Balboos11-Apr-14 1:14 

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
Web04 | 2.8.150728.1 | Last Updated 30 Jul 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid