using System; using System.Windows.Forms; using System.Drawing; /* 質問のためのプログラムを書きました。(手抜きですみません。 上を押すとフォームが 下押す警告するやつ?がでます。 警告するやつはフォーカスを失いません。 それって普通のフォームでもできるのでしょうか? */ class Program{ public static void Main(string[] asrgs){ MainForm mainForm = new MainForm(); Application.Run(mainForm); } } class MainForm:Form{ MainMenu mainMenu = new MainMenu(); //メインメニュー MenuItem M = new MenuItem("項目1"); //倍率メニュー MenuItem[] m = new MenuItem[2]; MyPanel myPanel1; public MainForm(){ //メインメニュー作成 this.Size = new Size(260,315); m[0] = new MenuItem("サブ項目1"); m[1] = new MenuItem("サブ項目2"); m[1].Checked = true; M.MenuItems.AddRange(m); mainMenu.MenuItems.AddRange(new MenuItem[] {M}); this.Menu = mainMenu; //パネル配置 myPanel1 = new MyPanel( 5,20,220,100 ); // myPanel2 = new MyPanel( 5,145,220,100 ); this.Controls.Add(myPanel1); // this.Controls.Add(myPanel2); } } class MyPanel:Panel{ MyButton myButton1; MyButton myButton2; public MyPanel( int sX, int sY ,int sW, int sH ){ this.Location = new Point( sX, sY ); this.Size = new Size( sW, sH ); this.BackColor = Color.Red; myButton1 = new MyButton("上",10,10,200,30); myButton2 = new MyButton("下",10,60,200,30); this.Controls.Add(myButton1); this.Controls.Add(myButton2); } } class MyButton:RadioButton{ MyForm form; public MyButton( string sSt, int sX, int sY ,int sW, int sH ){ this.Appearance = Appearance.Button; this.AutoCheck = false; this.Location = new Point( sX, sY ); this.Size = new Size( sW, sH ); this.BackColor = SystemColors.Control; this.Text = sSt; form = new MyForm(); this.Click += ButtonClick; } void ButtonClick( object sender, EventArgs e){ this.Checked = !this.Checked; var ob = sender as MyButton; if(ob.Text == "上"){ form.Show(); }else{ string message = "フォーカスを失わない"; string caption = "これどうやって作る?"; MessageBoxButtons buttons = MessageBoxButtons.YesNo; DialogResult result = MessageBox.Show(this, message, caption, buttons, MessageBoxIcon.Question); if(result == DialogResult.Yes) { } } } } class MyForm:Form{ public MyForm(){ Closing += onClosing; } void onClosing(object sender, System.ComponentModel.CancelEventArgs e){ bool a = true; e.Cancel = a; ((MyForm)sender).Hide(); } }