2014-05-10 21 views
0

我如何在我的c#窗口應用程序中使用html div和css風格?我想在HTML表格中顯示這些數據。 在此先感謝如何在C#窗口應用程序中使用html div和css樣式?

while (reader.Read()) 
{ 
      string fname = (string)reader["std_name"]; 
      string lname = (string)reader["f_name"]; 
      string age = (string)reader["age"].ToString(); 

      MessageBox.Show(fname+", "+lname+", "+age); 
} 
+0

如果這是一個WinForms應用程序,則不能將HTML或CSS直接嵌入界面中。您可以使用Web瀏覽器控件來渲染標記。 –

+0

哪種語言最適合C#窗口應用程序中的樣式,因爲在Web中使用了css? – user3553577

+0

恐怕我不明白這個問題。如果你問什麼.NET框架最適合使用HTML和相關標記進行演示,我會說MVC或Web表單。 –

回答

1

我認爲是沒有方法在wonfor添加CSS,你可以在HTML中添加。但是你可以在wpf應用程序中添加css like標籤。

0

您必須通過您的應用程序 創建一個HTML文件,該代碼創建一個HTML文件,並讀取訪問文件信息 然後注入informayino到HTML文件:

using System; 
 
using System.Collections.Generic; 
 
using System.Linq; 
 
using System.Text; 
 
using System.IO; 
 
using System.Data; 
 
using System.Data.OleDb; 
 
using System.Windows.Forms; 
 

 
namespace pomp_benzin 
 
{ 
 
    class class_print 
 
    { 
 
     public void print_to_html_file(string str_sql,int count_field,string[] headers) 
 
     { 
 
      //خط زير تنها كانكشن استرينگ را ميخواند كه ميتوان ان را نيز به صورت دستي نوشت 
 
      OleDbConnection con=new OleDbConnection(vars.con_str); 
 
      OleDbCommand cmd=new OleDbCommand(str_sql,con); 
 
      con.Open(); 
 
      OleDbDataReader rd=cmd.ExecuteReader(); 
 
      TextWriter tw = new StreamWriter(Application.StartupPath + "\\a.html", false, Encoding.UTF8); 
 
      tw.WriteLine("<table dir='rtl' border='1' style='width:100%;border-style:solid'>"); 
 
      //ساخت هدر هر ستون در جدول با توجه به هدر هاي ارسال شده از طرثق آرايه 
 
      tw.WriteLine("<tr>"); 
 
      for (int i = 0; i < headers.Length; i++) 
 
      { 
 
       tw.WriteLine("<td style='background-color: #CCCCCC;border-style:solid'>"); 
 
       tw.WriteLine(headers[i]); 
 
       tw.WriteLine("</td>"); 
 
      } 
 

 
      while(rd.Read()) 
 
      { 
 
       tw.WriteLine("<tr>"); 
 
       for (int cel = 0; cel < count_field; cel++) 
 
       { 
 
        tw.WriteLine("<td style='border-style:solid'>"); 
 
        //محتويات يك فيلد از جدول مربوطه 
 
        tw.WriteLine(rd.GetValue(cel).ToString()); 
 
        //محتويات يك فيلد از جدول مربوطه 
 
        tw.WriteLine("</td>"); 
 
       } 
 
       tw.WriteLine("</tr>"); 
 
      } 
 

 

 
      tw.WriteLine(" </table>"); 
 
      con.Close(); 
 
      tw.Close(); 
 
      System.Diagnostics.Process.Start(Application.StartupPath + "\\a.html"); 
 
     } 
 
    } 
 
}

那麼你必須運行a.html: system.diagnostic.process.start(「a.html」);

相關問題