RicherTextBox  편집양식 그대로 저장하기 위한 예제 입니다. 이미지도 같이 저장되게요...

RicherTextBox  의 RTF 구조를 데이터 베이스에 byte 형태로 저장해서 불러온다.

일단 http://www.codeproject.com/Articles/24443/RicherTextBox 가서

 

RicherTextBox   편집기 하나를 받았다.

 

여기에 RTF 저장 및 불러 오기만 구현했음

 

RicherTextBox_demo_jaedoo.zip


*데이터베이스 저장은 MDF (MS -SQL) 와 엔티티6으로 저장하였습니다.

목록조회

 private void button2_Click(object sender, EventArgs e)

{
    Database1Entities entities = new Database1Entities();
    list = entities.TestTable.ToList();
    this.dataGridView1.DataSource = list;
}



등록화면

붙여넣기도 됨

 

저장하기 소스

private void RicherTextBox1_dbSaveClick_click(object sender, string Rtf)
{
    Database1Entities entities = new Database1Entities();
    TestTable tt = new TestTable();
    RichTextBox rt = sender as RichTextBox;
    tt.Contents = rt.Text;
    ASCIIEncoding encoding = new ASCIIEncoding();
 
    byte[] array = encoding.GetBytes(Rtf);
    tt.ObjectContents = array;
    tt.CreateDate = DateTime.Now;
    entities.TestTable.Add(tt);
    entities.SaveChanges();
 
    MessageBox.Show("등록완료");
    this.DialogResult = DialogResult.OK;
    this.Close();
}

불러오기

더블클릭해서 불러온상태

private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
    TestTable tt = list[e.RowIndex] as TestTable;
 
    Form2 mf = new Form2(tt);
    if (mf.ShowDialog() == DialogResult.OK)
    {
        button2.PerformClick();
    }
}
 
private void Form2_Load(object sender, EventArgs e)
{
    richerTextBox1.dbSaveClick_click += RicherTextBox1_dbSaveClick_click;
 
    if (this.tt != null)
    {
     
        byte[] contentBytes = tt.ObjectContents;
        richerTextBox1.SetByteText(contentBytes);
    }
}


+ Recent posts