728x90
728x170

1

2

 

3. 컨텐트

* SizeToContent = SizeToContent.WidthAndHeight; : 컨텐트에 맞춰서 창을 조정한다.

 

* 이미지 삽입

            Uri uri = new Uri(http://www.charlespetzold.com/PetzoldTattoo.jpg);

            // Uri uri = new Uri("pack://application:,,,/1439813578408.jpg"); - 솔루션내의 이미지 가져오기
            BitmapImage bitmap = new BitmapImage(uri);
            Image img = new Image();
            img.Source = bitmap;
            Content = img;

 

- Uri uri = new Uri(System.IO.Path.Combine(Environment.GetEnvironmentVariable("windir"), "Gone Fishing.bmp"));

 

* TextBlock

            TextBlock txt = new TextBlock();
            txt.FontSize = 32; // 24 포인트
            txt.Inlines.Add("This is some ");
            txt.Inlines.Add(new Italic(new Run("italic")));
            txt.Inlines.Add(" text, and this is some ");
            txt.Inlines.Add(new Bold(new Run("bold")));
            txt.Inlines.Add(" text, and let's cap it off with some ");
            txt.Inlines.Add(new Bold(new Italic(new Run("bold italic"))));
            txt.Inlines.Add(" text.");
            txt.TextWrapping = TextWrapping.Wrap;
            Content = txt;

 

4. 버튼

Button btn = new Button();
btn.Content = "_Click me, please!";

이상태에서 alt+c 를 누르면 단축키로 활용이 가능하다  _ 를 넣으면 된다.

- Command

            Button btn = new Button();

            btn.HorizontalAlignment = HorizontalAlignment.Center;
            btn.VerticalAlignment = VerticalAlignment.Center;
            btn.Command = ApplicationCommands.Paste;
            btn.Content = ApplicationCommands.Paste.Text;

            Content = btn;

            // Command와 이벤트 핸들러의 바인딩
            CommandBindings.Add
            (
                new CommandBinding
                (
                    ApplicationCommands.Paste,
                    PasteOnExecute,
                    PasteCanExecute
                )
            );
        void PasteOnExecute(object sender, ExecutedRoutedEventArgs args)
        {
            Title = Clipboard.GetText();
        }

        void PasteCanExecute(object sender, CanExecuteRoutedEventArgs args)
        {

            // 클립보드에 있는 내용이 문자인지 확인하여 문자면 버튼을 활성화 한다.
            args.CanExecute = Clipboard.ContainsText();
        }

 

- CheckBox, ToggleButton

ToggleButton btn = new ToggleButton();
btn.SetBinding(ToggleButton.IsCheckedProperty, "Topmost"); // 체크발생시 Topmost 값을 변경한다.

//  어떤 Window의 Topmost 프로퍼티를 참조하는지 따로 알 수 없기 때문에 버튼의 DataContext 프로퍼티에 Window 객체를 지정해야 한다.
btn.DataContext = this;

Content = btn;
ToolTip tip = new ToolTip();
tip.Content = "Toggle the button on to make the window topmost on the desktop";
btn.ToolTip = tip; 

 

 

728x90
그리드형

'C# > Winform' 카테고리의 다른 글

(Linq) linq T Type Join result T Type  (0) 2017.04.14
(WPF) wpf 관련 리소스 정리  (0) 2017.04.13
(.NET) async, await 비동기 샘플 코드  (0) 2017.04.13
(.NET) 이펙티브 C# - 요점 정리  (0) 2017.04.13
(WCF) .net CORE WCF  (0) 2017.04.13
Posted by kjun
,