topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday December 12, 2024, 9:32 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: NANY 2012 Request  (Read 19778 times)

kyrathaba

  • N.A.N.Y. Organizer
  • Moderator
  • Joined in 2006
  • *****
  • Posts: 3,200
    • View Profile
    • Donate to Member
NANY 2012 Request
« on: December 12, 2011, 07:20 AM »
Not really an app request, but rather a component request, and perhaps there's a free version of this out there in cyberspace somewhere, but if so I haven't come across it:

I would like a custom control that I can add to my Visual C# Express toolbox. It should inherit from RichTextBox, but should be able to LoadFile() just like a RichTextBox (plain or RTB format), and should have a Print() method that prints the entire contents of the custom Rich TextBox.

Printing is abominably arcane in .NET!  Grrr...

lotusrootstarch

  • Member
  • Joined in 2009
  • **
  • Posts: 160
  • People reckon I'll smash into Cody someday.
    • View Profile
    • Donate to Member
Re: NANY 2012 Request
« Reply #1 on: December 12, 2011, 07:23 AM »
Get my apps in Android Market! Go droids go! :)


kyrathaba

  • N.A.N.Y. Organizer
  • Moderator
  • Joined in 2006
  • *****
  • Posts: 3,200
    • View Profile
    • Donate to Member
Re: NANY 2012 Request
« Reply #2 on: December 12, 2011, 08:15 AM »
Thanks, lotus.  There are lots of useful articles such as that one. But all are quite involved. I just can't believe that someone hasn't made a simple drop-in custom control such that, if the Rich Text Box contains text, you can just invoke Print() to print all the text it contains.

I've figured out a way to print simple text files in their entirety, but I'm not finding a pre-made free control for doing the same with RichTextBox. There's plenty of code samples for rolling-your-own.

hollowlife1987

  • Honorary Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 92
    • View Profile
    • Donate to Member
Re: NANY 2012 Request
« Reply #3 on: December 12, 2011, 08:20 AM »
How about an Extension Method?

http://msdn.microsof...ibrary/bb383977.aspx

kyrathaba

  • N.A.N.Y. Organizer
  • Moderator
  • Joined in 2006
  • *****
  • Posts: 3,200
    • View Profile
    • Donate to Member
Re: NANY 2012 Request
« Reply #4 on: December 12, 2011, 07:14 PM »
Hmm, thank you for that link, hollowlife; it appears worthy of study...

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 11,190
    • View Profile
    • Donate to Member
Re: NANY 2012 Request
« Reply #5 on: December 12, 2011, 07:57 PM »
So basically, all you need is the print functionality added to the current richtextbox?

kyrathaba

  • N.A.N.Y. Organizer
  • Moderator
  • Joined in 2006
  • *****
  • Posts: 3,200
    • View Profile
    • Donate to Member
Re: NANY 2012 Request
« Reply #6 on: December 12, 2011, 08:57 PM »
So basically, all you need is the print functionality added to the current richtextbox?

Yeah. I'd like either a user-defined control that can sit in my Toolbox and be dragged onto a Form for use, or (b) a custom class inheriting from RichTextBox that extends it, such that I can do the following:

clsExtendedRtbCtrl obj = new clsExtendedRtbCtrl();
obj.LoadFile(filepath, RichTextBoxStreamType.RichText);
obj.Print();

and, with those three lines, you get the print preview, and the ability to click OK on the print preview pane and send the RichText document to the printer. It should print any rich-text properly (italics, bold, underline, etc.), do word-wrap correctly, and print the entire contents of the rich textbox, even if it takes multiple pages.

kyrathaba

  • N.A.N.Y. Organizer
  • Moderator
  • Joined in 2006
  • *****
  • Posts: 3,200
    • View Profile
    • Donate to Member
Re: NANY 2012 Request
« Reply #7 on: December 12, 2011, 08:59 PM »
Heh, perhaps this thread needs to be moved to Developer's Corner...

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 11,190
    • View Profile
    • Donate to Member
Re: NANY 2012 Request
« Reply #8 on: December 12, 2011, 11:00 PM »
This isn't really a NANY, but, I posted a solution on my tech blog.  A direct link is here.

In the zip file, this is the structure

+--Libraries\External\ThinkShui.Libraries.External.csproj - the actual implementation of the extension method
|
+--PrintingTest\PrintingTest\PrintingTest.csproj - a simple example of how to use it
|
+--Bin - the assembly and the example compiled

The core of this is not original work, I just wrapped it up into two extension methods: one for when you already have the printqueue and one for when you want it to prompt, and adjusted the main code accordingly.  The URL for the source of the code is in the primary method.

Sorry for all the levels of folders; I had to extract it from something else I'm working on.  I haven't extensively tested it, so let me know if you have any questions.
« Last Edit: December 13, 2011, 07:17 AM by wraith808 »

kyrathaba

  • N.A.N.Y. Organizer
  • Moderator
  • Joined in 2006
  • *****
  • Posts: 3,200
    • View Profile
    • Donate to Member
Re: NANY 2012 Request
« Reply #9 on: December 13, 2011, 06:38 AM »
Awesome, wraith! Thank you :D

kyrathaba

  • N.A.N.Y. Organizer
  • Moderator
  • Joined in 2006
  • *****
  • Posts: 3,200
    • View Profile
    • Donate to Member
Re: NANY 2012 Request
« Reply #10 on: December 13, 2011, 06:40 AM »
Hmm...

http://thinkshui.net...ng-from-richtextbox/...

Firefox can't find the server at thinkshui.net.

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,629
    • View Profile
    • Donate to Member
Re: NANY 2012 Request
« Reply #11 on: December 13, 2011, 07:00 AM »
Just opened that page using FF 8 :D

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,629
    • View Profile
    • Donate to Member
Re: NANY 2012 Request
« Reply #12 on: December 13, 2011, 07:03 AM »
But the downloaded file can't be read by 7-zip :(

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 11,190
    • View Profile
    • Donate to Member
Re: NANY 2012 Request
« Reply #13 on: December 13, 2011, 07:12 AM »
But the downloaded file can't be read by 7-zip :(

Eh?  It should be able to be read, considering that I made it with 7-zip.  Let me try again.  And try again on the page (or the download).  I'm just getting everything together on the site, so there may be a few quirks.  (Trying to separate my gaming from my development stuff)

...that's strange.  I downloaded it and opened it with 7-zip and it opened fine and I was able to browse it.  I re-compressed it and uploaded it again.  Let me know if you still have problems.

hollowlife1987

  • Honorary Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 92
    • View Profile
    • Donate to Member
Re: NANY 2012 Request
« Reply #14 on: December 13, 2011, 07:14 AM »
I was able to extract with 7zip and WinRAR, as for download URL, i noticed you posted the URL using all lowercase letters. I was able to download by changing the file name to RTFPrinting.zip in the URL

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 11,190
    • View Profile
    • Donate to Member
Re: NANY 2012 Request
« Reply #15 on: December 13, 2011, 07:16 AM »
I was able to extract with 7zip and WinRAR, as for download URL, i noticed you posted the URL using all lowercase letters. I was able to download by changing the file name to RTFPrinting.zip in the URL
-hollowlife1987 (December 13, 2011, 07:14 AM)

Whoops!  I'll update.

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,629
    • View Profile
    • Donate to Member
Re: NANY 2012 Request
« Reply #16 on: December 13, 2011, 07:25 AM »
Using the instructions of Hollow I've successfully downloaded and opened the file :up:

kyrathaba

  • N.A.N.Y. Organizer
  • Moderator
  • Joined in 2006
  • *****
  • Posts: 3,200
    • View Profile
    • Donate to Member
Re: NANY 2012 Request
« Reply #17 on: December 14, 2011, 07:13 AM »
Hmm, I tried hollowlife's renaming, downloaded the file, but wasn't able to open it:

troubleDownloading.png

kyrathaba

  • N.A.N.Y. Organizer
  • Moderator
  • Joined in 2006
  • *****
  • Posts: 3,200
    • View Profile
    • Donate to Member
Re: NANY 2012 Request
« Reply #18 on: December 14, 2011, 07:18 AM »
Also unable to open it with 7-zip.  :huh:

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,287
    • View Profile
    • Donate to Member
Re: NANY 2012 Request
« Reply #19 on: December 14, 2011, 07:45 AM »
For what it's worth, I'm able to download it and extract it with both WinRAR (v3.91) and 7-zip (v4.65), no problem.

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,629
    • View Profile
    • Donate to Member
Re: NANY 2012 Request
« Reply #20 on: December 14, 2011, 08:14 AM »
Hmm, I tried hollowlife's renaming,
in the URL
-hollowlife1987 (December 13, 2011, 07:14 AM)
These last 3 words are crucial in the description of getting it to work...

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 11,190
    • View Profile
    • Donate to Member
Re: NANY 2012 Request
« Reply #21 on: December 14, 2011, 08:56 AM »
I fixed the URL problem in the direct download, and it works on the site, so that shouldn't be a problem.  As far as the not being able to open it in 7-zip, that's still strange, as I compressed it with 7-zip.  Also attaching it in this post (didn't do that before for the sake of changes to the code... but maybe that will work for you?)

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,629
    • View Profile
    • Donate to Member
Re: NANY 2012 Request
« Reply #22 on: December 14, 2011, 09:40 AM »
Wraith, the link on your Blog is dodgy, it points to the zipfile with all lowercase letters, as hollowlife pointed out. Clicking the link gives me a 404 error-page.
If I right-click and select download, I (slowly) get a file of about 20 kB, but I can't open it. When copying the link text and changing the name into the correct case (using a new tab in my browser), it downloads fine and can be opened as expected.

The direct link in your #8 reply here works fine now, as does the attached download.

wraith808

  • Supporting Member
  • Joined in 2006
  • **
  • default avatar
  • Posts: 11,190
    • View Profile
    • Donate to Member
Re: NANY 2012 Request
« Reply #23 on: December 14, 2011, 10:16 AM »
Ah... thanks!  I didn't know I'd messed up on the one on the blog post itself also!  That one is corrected, also.  Now I know why I usually make my file names all lower case!  ;D

Thanks again for pointing that out!

kyrathaba

  • N.A.N.Y. Organizer
  • Moderator
  • Joined in 2006
  • *****
  • Posts: 3,200
    • View Profile
    • Donate to Member
Re: NANY 2012 Request
« Reply #24 on: December 30, 2011, 07:59 PM »
wraith, thanks again for your work on this: with your help, I figured out how to make printing work in my Prayer Minder app. Much obliged!