C# Form 과 Dialog Box

C# 에서 Form과 Dialog는 동일한 Control이다.
MFC 를 주로 사용하는 개발자에게는 습관적으로 Dialog 를 찾으려는 경향이 있다.
C# 에서는 DialogBox를 별도로 제공하지 않는다. VB에서도 Form과 Dialog를 별도로 구분하지 않았다.
Dialog와 Form을 구분하지 않는 정책이 훨씬 더 편리하고 직관적인 장점이 있다고 생각된다.
C#에서 Form이 Dialog로 처리될 때와 Form으로 처리 될때 어떻게 다르게 동작 하는지 살펴보자.

[그림1]
먼저 MDI Parent로 시작하는 프로젝트에  [그림1]과 같이 Form을 만들고 아래와 같이 코딩한다.
Radio Button에서 MDI 또는 SDI 둘중에 어느것이 선택 되었는지 확인하고 MDI 이면 OK 아니면 No를 반환하도록 코딩한다.

using System;
using System.Windows.Forms;
namespace SampleTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//Radio Button에서 선택상태를 Check한 다음
//Dialog Result로 반환할 값을 선택한다
if (MDIRadio.Checked == true) this.DialogResult = DialogResult.OK;//MDI 가 선택되면 OK
else this.DialogResult = DialogResult.No;//SDI가 선택되면 No
this.Close();//Form을 닫는다
}
}
}
[그림2]
MDIParent Form은 [그림2]와 같이 메뉴를 추가 한다.
그리고 메뉴클릭 이벤트 핸들러에 아래와 같은 코드를 추가한다.

private void testDialogToolStripMenuItem_Click(object sender, EventArgs e)
{
 DialogResult dr = new DialogResult();//Dialog로 부터 결과를 받기위한 변수 생성
 Form fm = new Form1(); //Form 생성
 dr = fm.ShowDialog(); //Form을 Dialog로 띄우기
 fm.Text = "Dailog";
 if (dr == DialogResult.OK)
 {
 //MDI 의 Child로 폼을 보여주기
 fm.MdiParent = this;
 fm.WindowState = FormWindowState.Maximized; //Child Window 최대화 시켜서 MDI Size에 맞춘다
 fm.Show();
 fm.Text = "Form";
 }
 else if (dr == DialogResult.No)
 {
 //SDI 폼을 보여주기
 fm.AutoSize = true;
 fm.MaximumSize = this.MaximumSize;
 fm.AutoSizeMode = AutoSizeMode.GrowAndShrink;
 fm.Show(this);
 fm.Text = "Form";
 }

그럼 어떻게 동작 하는지 살펴보자

[그림3]
메뉴에서 TestDialog를 누르면
Form fm = new Form1(); //Form 생성
fm.ShowDialog(); //Form을 Dialog로 띄우기
에 의해서 [그림3]과 같이 Form이 Dialog참으로 활성화 된다.
Dialog상태에서 MDI를 선택하고 OK를 누르면
if (MDIRadio.Checked == true) this.DialogResult = DialogResult.OK;//MDI 가 선택되면 OK
else this.DialogResult = DialogResult.No;
에서 라디오 버튼의 선택 상태에 따라 결과를 리턴한다.
그리고 아래 코드에서 Dialog의 결과를 리턴 받아서 Form을 MDI의 Child 로 변환시켜서 창을 다시 띄운다
if (dr == DialogResult.OK)
{
//MDI 의 Child로 폼을 보여주기
fm.MdiParent = this;
fm.WindowState = FormWindowState.Maximized; //Child Window 최대화 시켜서 MDI Size에 맞춘다
fm.Show();
}
[그림4]는 MDI Child로 Form이 활성화 되어 있는 것을 보여준다.
[그림4]
 
 
 
 
 
 
 
 
 
 
[그림5]
만일 SDI 로 선택하고 OK를 누르면 [그림5]와 같이 Form이 MDI외부에 그냥활 성화 되어 있는 것이 보일 것이다.
여기서 주목할 사실은 SDI의 경우 Form과 Dialog는 별다른 차이를 보이지 않는다는 것이다.
그런데 윈도우 Text의 변화를보면 Dialog일때 Show()를 실행하면 OK 버튼이 눌러질때 까지 다음 동작을 수행하지 않고 있으므로 Text의 내용이 변경되지 않은 것을 볼수 있다.
그런데 Form의 경우는 윈도우 Title의 text가 변화 되어 있는 것을 볼수 있다.
즉 화면을 보여주고  곧바로 다음 루틴이 실행 된다는 것이다.
 

“C# Form 과 Dialog Box”의 91개의 댓글

  1. I’m not sure where you’re getting your information, but good topic.
    I needs to spend some time learning more or understanding more.
    Thanks for fantastic info I was looking for this info for
    my mission.

  2. Cbd oil that works 2020
    What i don’t understood is in reality how you’re no longer actually a lot more smartly-preferred than you might be right now.
    You’re very intelligent. You already know therefore significantly with regards to this subject, made me for my part believe it from a lot
    of numerous angles. Its like men and women aren’t involved unless
    it’s something to do with Girl gaga! Your personal stuffs
    great. Always handle it up! best rated cbd oil http://t.co/4kPhN7Ek0L cbd oil that works 2020 http://t.co/4kPhN7Ek0L

  3. Terrific article! That is the type of information that are meant to be shared around the net.

    Shame on the search engines for now not positioning this put up
    higher! Come on over and consult with my web site .
    Thank you =)

  4. Leading Online Pharmacy – Contact us at +1 (917) 259-3352 for unbelievable rates, discount and offers on any medicine. Get it delivered free of cost at your door steps, call us today. Phone : +1 (917) 259-3352

  5. I simply want to say I am very new to blogging and absolutely enjoyed your website. Almost certainly I’m going to bookmark your website . You amazingly have exceptional posts. Thanks a lot for sharing your web site.

  6. Next time I read a blog, Hopefully it doesn’t fail me as much as this one. After all, I know it was my choice to read through, nonetheless I genuinely believed you would probably have something interesting to talk about. All I hear is a bunch of complaining about something you could fix if you weren’t too busy searching for attention.

  7. Right here is the right webpage for anyone who wants to understand this topic. You know a whole lot its almost hard to argue with you (not that I personally would want to…HaHa). You certainly put a brand new spin on a topic that has been discussed for years. Excellent stuff, just excellent!

  8. Greetings, I do believe your blog might be having browser compatibility problems. When I take a look at your web site in Safari, it looks fine however when opening in I.E., it’s got some overlapping issues. I merely wanted to give you a quick heads up! Apart from that, wonderful website!

  9. Hi there! This blog post could not be written any better! Reading through this article reminds me of my previous roommate! He constantly kept preaching about this. I most certainly will forward this information to him. Pretty sure he will have a very good read. I appreciate you for sharing!

  10. I’m the business owner of JustCBD label (justcbdstore.com) and I am currently seeking to develop my wholesale side of company. It would be great if someone at targetdomain share some guidance ! I considered that the best way to accomplish this would be to talk to vape companies and cbd stores. I was hoping if anyone could recommend a qualified site where I can purchase Vape Shop Business Marketing Data I am currently examining creativebeartech.com, theeliquidboutique.co.uk and wowitloveithaveit.com. Not exactly sure which one would be the best selection and would appreciate any support on this. Or would it be simpler for me to scrape my own leads? Suggestions?

  11. I truly love your blog.. Very nice colors & theme. Did you develop this website yourself? Please reply back as I’m trying to create my very own blog and would love to learn where you got this from or what the theme is called. Many thanks!

  12. I must thank you for the efforts you’ve put in penning this blog. I really hope to view the same high-grade blog posts from you in the future as well. In truth, your creative writing abilities has encouraged me to get my own, personal website now 😉

  13. I’m the proprietor of JustCBD Store company (justcbdstore.com) and I’m presently looking to develop my wholesale side of business. It would be great if anybody at targetdomain is able to provide some guidance . I thought that the most effective way to accomplish this would be to connect to vape stores and cbd retail stores. I was really hoping if anybody could suggest a dependable web site where I can buy Vape Shop Business Data I am presently looking at creativebeartech.com, theeliquidboutique.co.uk and wowitloveithaveit.com. On the fence which one would be the very best choice and would appreciate any support on this. Or would it be simpler for me to scrape my own leads? Ideas?

  14. A fascinating discussion is definitely worth comment. I do think that you need to publish more on this subject matter, it might not be a taboo subject but generally folks don’t discuss such topics. To the next! Many thanks!!

  15. Hi there! This blog post couldn’t be written much better! Reading through this post reminds me of my previous roommate! He continually kept preaching about this. I will forward this article to him. Fairly certain he will have a great read. Thank you for sharing!

  16. The very next time I read a blog, I hope that it does not fail me just as much as this one. I mean, Yes, it was my choice to read, however I really believed you’d have something helpful to say. All I hear is a bunch of moaning about something that you can fix if you were not too busy looking for attention.

  17. Hey there, I think your site might be having browser
    compatibility issues. When I look at your website in Firefox, it looks fine
    but when opening in Internet Explorer, it has some overlapping.

    I just wanted to give you a quick heads up! Other then that,
    superb blog!

  18. I’m impressed, I have to admit. Seldom do I come across a blog that’s equally educative and engaging, and let me tell you, you’ve hit the nail on the head. The issue is something that not enough men and women are speaking intelligently about. I’m very happy I found this during my hunt for something concerning this.

  19. Can I simply say what a comfort to discover somebody that genuinely knows what they are discussing over the internet. You actually realize how to bring an issue to light and make it important. More and more people really need to check this out and understand this side of your story. I can’t believe you’re not more popular given that you surely have the gift.

  20. Nice post. I was checking constantly this blog and I’m inspired!
    Very helpful information specifically the remaining phase 🙂 I maintain such info much.
    I used to be seeking this certain information for
    a long time. Thanks and good luck.

  21. Next time I read a blog, Hopefully it doesn’t fail me just as much as this particular one. After all, I know it was my choice to read, but I truly believed you would probably have something useful to talk about. All I hear is a bunch of moaning about something you can fix if you weren’t too busy seeking attention.

  22. An outstanding share! I have just forwarded this onto a coworker who had been doing a little homework on this. And he in fact bought me breakfast simply because I stumbled upon it for him… lol. So let me reword this…. Thank YOU for the meal!! But yeah, thanks for spending time to discuss this topic here on your site.

  23. 핑백: golf course community

  24. 핑백: mơ mình chết đánh con gì

  25. [url=https://jenniferalexander20.hatenablog.com/entry/2020/09/13/141702]https://jenniferalexander20.hatenablog.com/entry/2020/09/13/141702[/url]

  26. [url=https://camponotusforeli.pixnet.net/blog/post/21780500-aldara-cream-guide]https://camponotusforeli.pixnet.net/blog/post/21780500-aldara-cream-guide[/url]

  27. I like what you guys are up also. Such smart work and reporting! Carry on the superb works guys I have incorporated you guys to my blogroll. I think it’ll improve the value of my site :).

  28. [url=http://best-huiles-essentielles.online/post/huiles-essentielles-pour-le-nez-qui-coule.php]http://best-huiles-essentielles.online/post/huiles-essentielles-pour-le-nez-qui-coule.php[/url]

  29. 핑백: Panzer Arms BP-12 Bullpup Shotgun 12ga

  30. This is the right webpage for everyone who really wants to find out about this topic. You know a whole lot its almost tough to argue with you (not that I really will need to…HaHa). You certainly put a new spin on a subject that has been discussed for years. Great stuff, just great!

  31. hello there and thank you for your information I have certainly picked up anything new from right here. I did however expertise some technical issues using this web site, as I experienced to reload the website many times previous to I could get it to load correctly. I had been wondering if your web hosting is OK? Not that I am complaining, but slow loading instances times will very frequently affect your placement in google and could damage your high-quality score if advertising and marketing with Adwords. Well I am adding this RSS to my e-mail and could look out for a lot more of your respective exciting content. Make sure you update this again soon..

댓글 남기기