WPF, XAML

[WPF동영상]1.4 WPF HelloWorld-2(C#코드 기반)

오라클왕 0 754 04.25 09:59

 

1.4 WPF HelloWorld-2(C#코드 기반)

n  Visual Studio File -> New -> Project -> Visual C# -> WPF 응용프로그램

프로젝트명 : HelloWorld2

n  App.xaml, MainWindow.xaml 삭제

n  프로젝트 >> 추가 >> 새항목에서 MyMain.cs 파일 추가

 

 

[MyMain.cs]

using System;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Input;

 

namespace HelloWorld2

{

    class MyMain : Application

    {

        [STAThread]

        public static void Main()

        {

            MyMain app = new MyMain();

            app.ShutdownMode = ShutdownMode.OnMainWindowClose;

            app.Run();

        }

 

        protected override void OnStartup(StartupEventArgs e)

        {

            base.OnStartup(e);

 

            Window mainWindow = new Window();

            mainWindow.Title = "WPF Sample(Main)";

            mainWindow.MouseDown += WinMouseDown;

            mainWindow.Show();

 

            for (int i = 0; i < 2; i++)

            {

                Window win = new Window();

                win.Title = "Extra Window No." + (i + 1);

                win.Show();

            }

        }

 

        void WinMouseDown(Object sender, MouseEventArgs args)

        {

            Window win = new Window();

            win.Title = "Modal DialogBox";

            win.Width = 400;

            win.Height = 200;

 

            Button b = new Button();

            b.Content = "Click Me!";

            b.Click += Button_Click;

 

            win.Content = b;

            win.ShowDialog();

        }

 

        private void Button_Click(object sender, EventArgs e)

        {

            MessageBox.Show("Button Click!", sender.ToString());

        }

    }

}

 

 

n  실행화면(F5)

 


 

Comments