Quantcast
Channel: C#タグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 9551

C# - モーダルなサブウィンドウを開くサンプルコードべた書き(Visual Studio不使用)

$
0
0

Formの画面レイアウトが一杯になってきて設定画面を切り離したいときとかに、子ウィンドウを出したくなると思います。
今回はモーダルウィンドウ(閉じるまで親のFormを操作できない)を表示させます。

モーダルウィンドウ モードレスウィンドウ - Google検索

画面キャプチャ

image.png

サンプルソースコード

usingSystem;usingSystem.Drawing;usingSystem.Windows.Forms;classMainForm:Form{MainForm(){Text="Main window";ClientSize=newSize(400,300);varbtn=newButton(){Size=newSize(200,50),Text="Show sub window.",};Controls.Add(btn);btn.Click+=(s,e)=>{ShowSubFormWithText("this is a sample.");};}staticvoidShowSubFormWithText(stringtext){SubFormf=newSubForm(text);f.ShowDialog();}[STAThread]staticvoidMain(string[]args){Application.Run(newMainForm());}}classSubForm:Form{publicSubForm(stringtext){Text="Sub window";ClientSize=newSize(300,150);StartPosition=FormStartPosition.CenterParent;// StartPosition = FormStartPosition.CenterScreen;vartxt=newTextBox(){Text=text,Multiline=true,ScrollBars=ScrollBars.Both,Dock=DockStyle.Fill};txt.KeyDown+=(sender,e)=>{if(e.Control&&e.KeyCode==Keys.A){txt.SelectAll();}};Controls.Add(txt);}}

・・・

入力データの受け取りとか加筆予定・・

参考サイト


Viewing all articles
Browse latest Browse all 9551

Trending Articles