最新の更新情報

2012年5月
« 4月    
 12345
6789101112
13141516171819
20212223242526
2728293031  

本ブログのURL

qrcode.png

お天気

 
このブログ「吟遊詩人の戯言」 の記事検索...

【C#】フォームを最背面(最後面)にしたいとき


キーワード(クリックで関連記事が読めます) → ,

関連記事



 
 

怪しい常駐ソフト
DELPHIで書いていたんだけど,どうも調子悪い...

ってことで,C#で書き直してみたり...

いや,ものの10分で,コア部分が出来たり(爆
便利な世の中やなぁ~

ただ,フォームを最背面(最後面)にする方法が全くわからず...

Form.SendToBack()メソッドを飛ばせば
なんとなく,背面に行きそうだったけど,なんか,イマイチオーラが出てて

あれこれ調べていったら
何のことは無い
フォームをディスクトップの子として,ぶら下げればいいらしい
ソースは,こんな感じ?





C#:
  1. [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
  2. static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
  3.  
  4. [System.Runtime.InteropServices.DllImport("user32.dll")]
  5. static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
  6.  
  7.  
  8. private void Form1_Load(object sender, EventArgs e)
  9. {
  10.  
  11.   IntPtr tmpdesktop = FindWindow(null, "Program Manager");
  12.   if(tmpdesktop != null) {
  13.     SetParent(this.Handle, tmpdesktop);
  14.   }
  15. }


手元の技術試験アプリ,期待通り,最背面に移動してくれています

 
 
 
 

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <img localsrc="" alt="">