c# - Centering OK button within a MessageBox in winforms -
i learning c#, , part of wrote small app consists of form 2 groups of buttons, 2 buttons each. button closing of app added well. , works ok. there messagebox, showing app going closed. and here little problem bugs me: ok button within messagebox not centered horizontally. guess there method align button, puzzles me why it's not centered default? illustration here screenshots:
here code well:
using system; using system.drawing; using system.windows.forms; public class myform : form { private groupbox gboxgrp1; private groupbox gboxgrp2; private radiobutton butn1a; private radiobutton butn1b; private radiobutton butn2a; private radiobutton butn2b; private button btnclose; public myform() { initializecomponent(); } private void initializecomponent() { this.btnclose = new button(); this.gboxgrp1 = new groupbox(); this.gboxgrp2 = new groupbox(); this.butn1a = new radiobutton(); this.butn1b = new radiobutton(); this.butn2a = new radiobutton(); this.butn2b = new radiobutton(); //myform this.text = "my form"; this.startposition = formstartposition.centerscreen; this.height = 350; this.width = 200; //btnclose this.controls.add(btnclose); this.btnclose.text = "close"; this.btnclose.location = new point(60, 260); this.btnclose.click += new eventhandler(btnclose_click); //gboxgrp1 this.gboxgrp1.location = new point(20, 20); this.gboxgrp1.text = "group box 1"; this.gboxgrp1.width = 150; this.gboxgrp1.height = 100; //gboxgrp2 this.gboxgrp2.text = "group box 2"; this.gboxgrp2.location = new point(20, 130); this.gboxgrp2.width = 150; this.gboxgrp2.height = 100; //radio buttons this.butn1a.text = "radio 1a"; this.butn1a.location = new point(30, 30); this.butn1a.size = new size(90, 15); this.butn1b.text = "radio 1b"; this.butn1b.location = new point(30, 60); this.butn1b.size = new size(90, 15); this.butn2a.text = "radio 2a"; this.butn2a.location = new point(30, 30); this.butn2a.size = new size(90, 15); this.butn2b.text = "radio 2b"; this.butn2b.location = new point(30, 70); this.butn2b.size = new size(90, 15); //controls this.controls.add(gboxgrp1); this.controls.add(gboxgrp2); this.gboxgrp1.controls.add(butn1a); this.gboxgrp1.controls.add(butn1b); this.gboxgrp2.controls.add(butn2a); this.gboxgrp2.controls.add(butn2b); } private void btnclose_click(object sender, eventargs e) { messagebox.show("closing application"); application.exit(); } } public class myapp { public static void main() { application.run(new myform()); } }
you can't restyle default messagebox that's depends on windows os theme. create own message box creating new form , call using newmessagebox.showdialog();
Comments
Post a Comment