cscの作法 その59
1721 ワード
概要
cscの作法、調べてみた。
モーダルウィンドウやってみた。
参考にしたページ
写真
サンプルコード
using System;
using System.Drawing;
using System.Windows.Forms;
class MainForm : Form
{
Button btn;
MainForm() {
Text = "Main window";
ClientSize = new Size(400, 300);
btn = new Button();
btn.Size = new Size(200, 50);
btn.Text = "Show sub window.";
Controls.Add(btn);
btn.Click += btn_Click;
}
void btn_Click(object sender, System.EventArgs e) {
ShowSubFormWithText("this is a sample.");
}
static void ShowSubFormWithText(string text) {
SubForm f = new SubForm(text);
f.ShowDialog();
}
[STAThread]
static void Main(string[] args) {
Application.Run(new MainForm());
}
}
class SubForm : Form
{
TextBox txt;
public SubForm(string text) {
Text = "Sub window";
ClientSize = new Size(300, 150);
StartPosition = FormStartPosition.CenterParent;
txt = new TextBox();
txt.Text = text;
txt.Multiline = true;
txt.ScrollBars = ScrollBars.Both;
txt.Dock = DockStyle.Fill;
txt.KeyDown += txt_KeyDown;
Controls.Add(txt);
}
void txt_KeyDown(object sender, KeyEventArgs e) {
if (e.Control && e.KeyCode == Keys.A)
{
txt.SelectAll();
}
}
}
using System;
using System.Drawing;
using System.Windows.Forms;
class MainForm : Form
{
Button btn;
MainForm() {
Text = "Main window";
ClientSize = new Size(400, 300);
btn = new Button();
btn.Size = new Size(200, 50);
btn.Text = "Show sub window.";
Controls.Add(btn);
btn.Click += btn_Click;
}
void btn_Click(object sender, System.EventArgs e) {
ShowSubFormWithText("this is a sample.");
}
static void ShowSubFormWithText(string text) {
SubForm f = new SubForm(text);
f.ShowDialog();
}
[STAThread]
static void Main(string[] args) {
Application.Run(new MainForm());
}
}
class SubForm : Form
{
TextBox txt;
public SubForm(string text) {
Text = "Sub window";
ClientSize = new Size(300, 150);
StartPosition = FormStartPosition.CenterParent;
txt = new TextBox();
txt.Text = text;
txt.Multiline = true;
txt.ScrollBars = ScrollBars.Both;
txt.Dock = DockStyle.Fill;
txt.KeyDown += txt_KeyDown;
Controls.Add(txt);
}
void txt_KeyDown(object sender, KeyEventArgs e) {
if (e.Control && e.KeyCode == Keys.A)
{
txt.SelectAll();
}
}
}
以上。
Author And Source
この問題について(cscの作法 その59), 我々は、より多くの情報をここで見つけました https://qiita.com/ohisama@github/items/c50009e4ee4a42f77291著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .