C#筆記

來源:互聯網
上載者:User

C#筆記
讀取網頁:

using System.Net;
using System.Text;
using System.Web;
using System.IO ;
public void getPageContent(String url)
  
  {
   WebRequest request = WebRequest.Create(url);
   try
      {
    //請求服務
    WebResponse response = request.GetResponse();
    //返回資訊
    Stream resStream = response.GetResponseStream(); 
    StreamReader sr = new StreamReader(resStream, System.Text.Encoding.Default);
    string tempCode= sr.ReadToEnd();
    resStream.Close(); 
    sr.Close();

    textBox1.Text=(tempCode);
      }
   catch
   {
    MessageBox.Show("出錯了,請檢查網路是否連通;");
   }
  }

http://www.xgdown.com/article/32/ArticleList32_1.htm

##託管C++ 環境設定
 
建立託管C++應用程式
 
可以使用3種方法建立託管的C++的應用程式和組件:
 
從草稿建立一個託管的C++應用程式.
可將一個現存的C++應用程式轉化為一個託管的C++應用程式.
要建立一個託管的C++應用程式或組件,可以將現存的組件封裝在託管的C++外殼中.
 
執行個體:
 
建立一MFC應用程式, 然後將他傳給CLR.需要改變一些項目的編譯選項;
開啟MFC項目.
Solutious Explorer ->Properties.
可在項目屬性對話方塊上端的配置組合框中選擇All Configurations.
在左側選擇C/C++ General.
Complie As Managed ->Assembly Support(/clr)
Debug Information Format->Program Database(/Zi)
在左側選擇C/C++ Code Generation
Enable Minimal Rebuild->No
Basic Runtime Checks->Default
點擊OK.
 
注:有時需要處理先行編譯指令,取消先行編譯指令.
C/C++ Precomplied Headers->Create/Use Precompiled Header->Not Using Precompiled Headers
 
這樣可以有效將該項目轉化為CLR進行編譯.
 
將.Net基礎類庫添加到MFC應用程式中時,還要注意一個細節
 
MFC的調試版本重新定義了new操作符,以便能跟蹤已經被分配的記憶體,並能識別應用程式中的記憶體流失.但這與.NET對象不相容.因此每當建立.NET對象的執行個體或任何其他託管對象(包括自訂的任何垃圾收集類和結構)時,都需要使用#pragma push_macro, pop_macro 以及#undef指令來重新定義new操作符,以便使用託管對象.
 
#ifdef _DEBUG
#pragma push_macro("new")
#undef new
#endif
 
String *S;
S = new String("This is a managed string for test.");
 
#ifdef _DEBUG
#pragma pop_macro("new")
#endif

#在C#中如何調用自己寫的dll檔案?
 懸賞分:10 - 解決時間:2007-1-11 15:51
自己寫了一個dll檔案,如何在程式中調用

建立一項目,在項目“引用”上右擊,“添加引用”,瀏覽到你的dll檔案上,然後就可以用了~

###怎麼調用c++寫的dll
我知道在c#中掉用c++寫的函數很方便  
using   System.Runtime.InteropServices;

  [DllImport("user32.dll")]  
  public   static   extern   int   ActivateKeyboardLayout   (  
  int   HKL,  
  int   flags  
  );  
##c#調用COM組件
直接添加引用就行吧。

##如果是在表單上畫的話,如下  
  Image   imgPic   =   Image.FromFile(   yourImageFile   );  
  Graphics   g   =   this.CreateGraphics();  
  g.DrawImage(imgPic,   yourStartX,   yourStartY,   ImageWidth,   ImageHeight   );  
  g.Dispose();

/////////////////
先將byte[]轉為System.IO.Stream   stream;  
  然後:  
  Bitmap   bmp   =   new   Bitmap(stream);  
  g.DrawImage(bmp,   0,   0);  
   
  比如:  
        byte[]   imgByteArray   =   GetImage("2");   //這是你的byte數組  
        MemoryStream   stream   =   new   MemoryStream();  
        stream.Write(imgByteArray,   0,   imgByteArray.Length);  
  //顯示圖片  
        Image   m_Bitmap   =   Image.FromStream(stream);  
        this.CreateGraphics().DrawImage(m_Bitmap,   0,   0);  
        stream.Close();  

##

rtsp://219.223.252.38:554/movie2/zoujinkexue15/01.rmvb

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.