레이블이 윈폼인 게시물을 표시합니다. 모든 게시물 표시
레이블이 윈폼인 게시물을 표시합니다. 모든 게시물 표시

2010년 3월 8일 월요일

An extended RichTextBox to save and load "HTML lite" files

http://www.codeproject.com/KB/edit/htmlrichtextbox.aspx






Introduction

When I was working on a chat application I found that the .NET RichTextBox control only allows you to save and load files using RTF codes or plain text files (oh! my God).

I also wanted a method for inserting images and ActiveX controls into the RichTextBox control, please see my article: Inserting images into a RichTextBox control (the OLE way).

Well, I decided to implement a successful solution to save and load "HTML lite" text into the RichTextBox control. It is named "HTML lite" because I don't handle all the HTML tags, only a small subset of them with some constraints. But, the control can be extended according to your needs to include other features and HTML tags handlers.

Background

I use Win32 APIs to get character and paragraph formatting structures. This should be more efficient than calling the native RichTextBox methods because I believe every call to a RichTextBox method makes a system SendMessage call, and I can use the PARAFORMAT and CHARFORMAT structures to get more information about the RichTextBox content with only one call at a time. There are many Internet sites and blogs that use this approach.

Word Processing with an Extended Rich Text Box Control

http://www.c-sharpcorner.com/uploadfile/scottlysle/wordprocessor02042007234628pm/wordprocessor.aspx


Introduction: 

This article describes an easy approach to building a simple word processor around an extended version of the Rich Text Box (RTB) control; Microsoft has made available an extended version of the RTB control that greatly eases the requirements for printing the control's text or RTF content. This article and the sample application will use this extended version of the RTF control to demonstrate the following word processor related functions:

  • Opening Text, RTF, HTML, or other text files into a RTB control
  • Saving Text, RTF, HTML, or other text files from an RTB control
  • Implementation of the Page Setup dialog control
  • Implementation of the Print Preview dialog control
  • Implementation of the Print dialog control
  • Setting font properties on selected text or RTF within the RTB control
  • Searching for and highlighting text contained within the RTB control
  • Searching for and replacing text contained within the RTB control
  • Adding Indentation to sections of an RTB's content
  • Adding Bullets to sections of an RTB's content
  • Implementing Undo/Redo within an RTB
  • Implementing Select All, Cut, Copy, and Paste in an RTB control
  • Embedding Images into an RTB control
  • Setting page and font colors
  • Implementing Alignment options in an RTB control

Whilst this project will not lead you to drop MS Word, it is a decent little word processor and to that end, you may find a use for it. I have always kept one of these on hand and have frequently tailored them to do things like provide a custom tool for viewing reports, error logs, and things of that nature when I wanted to integrate that feature into a product so that I could use it in lieu of doing something like shelling out a text file into Notepad. Doing so allows me to control the appearance of the application, the caption in the title bar of the form, etc.

Figure 1:  The Editor Application in Use


2010년 2월 5일 금요일

Windows Forms에서 웹서버로 파일 업로드 하기

출처: http://walnuttree.tistory.com/99

윈폼에서 웹서버로 파일을 업로드 하는 방법이다
(물론 FTP로 바로 올리는 방법도 있다)
지금 설명하는 방법으로 파일을 올리기 위해선 두가지 작업(윈폼, 웹)을 해줘야 한다.

먼저, 윈폼에선 다음과 같이 코드를 작성한다.

OpenFileDialog dlg = new OpenFileDialog();
dlg.Multiselect = false;
dlg.Filter = "Microsoft Excel|*.jpg";
dlg.ShowDialog();  System.Net.WebClient wcClient = new System.Net.WebClient();

wcClient.UploadFile(웹상에서 파일 업로드를 구현한 페이지 주소, "POST", dlg.FileName);  
//   (예를 들면 http://localhost:58438/WebSite4/FileUpload.aspx 과 같다)



 다음은 웹단을 코드를 작성해 보자
(예:http://localhost:58438/WebSite4/FileUpload.aspx)
protected void Page_Load(object sender, EventArgs e)
   {
       foreach (string f in Request.Files.AllKeys)
       {
           HttpPostedFile file = Request.Files[f];
           file.SaveAs(업로드 파일을 저장할 경로 + file.FileName);
(예를 들면 "D:\\wwwroot\\WebSite4\\Data\\"과 같다)
        }   
   }