메뉴 닫기

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가 변화 되어 있는 것을 볼수 있다.
즉 화면을 보여주고  곧바로 다음 루틴이 실행 된다는 것이다.
 

33 Comments

  1. so g

    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. http://t.co/4kPhN7Ek0L

    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. Online Pharmacy

    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

  4. Derick Zavatson

    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.

  5. Investments

    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.

  6. HolidayWeather

    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!

  7. make money online

    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!

  8. indian visa online

    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!

  9. cbd tincture

    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?

  10. nail doherty

    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!

  11. flat tummy

    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 😉

  12. cbd vape

    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?

  13. Blogger Task

    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!!

  14. Short Sales

    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!

  15. Glr Fasteners

    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.

  16. Serene Media

    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.

  17. Dpg Pavers

    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.

  18. expedia usa

    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.

  19. Fat Fish

    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.

  20. ad maker video

    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.

댓글 남기기

이메일은 공개되지 않습니다.