namespace winform_ex02;
using System;
using System.Text;
using System.Xml;
using MaterialSkin; //추가
using MaterialSkin.Controls; //추가
// public partial class Form1 : Form
public partial class Form1 : MaterialForm
{
public Form1()
{
InitializeComponent();
// 아래 추가
var materialSkinManager = MaterialSkinManager.Instance;
materialSkinManager.AddFormToManage(this);
materialSkinManager.Theme = MaterialSkinManager.Themes.DARK;
materialSkinManager.ColorScheme=new ColorScheme(Primary.BlueGrey900, Primary.BlueGrey900, Primary.BlueGrey500, Accent.LightBlue200, TextShade.WHITE);
// 여기까지
// 이하는 버튼 클릭 이벤트...
this.button1.Click += new System.EventHandler(this.button1_Click);
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDlg = new OpenFileDialog();
openFileDlg.Filter = "XML Files (*.xml)|*.xml";
openFileDlg.ShowDialog();
// MessageBox.Show("Hello World!");
if (openFileDlg.FileName.Length > 0)
{
foreach (string Filename in openFileDlg.FileNames)
{
this.textBox1.Text = Filename;
XmlDocument xmlDoc = new XmlDocument(); // XmlDocument 객체 생성
xmlDoc.Load(Filename); // XML 파일 로드
XmlNodeList allNodes = xmlDoc.SelectNodes("//bookstore//*");
StringBuilder sb = new StringBuilder();
foreach(XmlNode node in allNodes){
if(node.NodeType == XmlNodeType.Element){
sb.Append(node.InnerText);
}
else if (node.NodeType == XmlNodeType.Text){
sb.Append(node.Value );
}
// sb.Append("\n");
sb.Append(Environment.NewLine);
}
this.result1.Text = sb.ToString();
}
}
}
}
ColorScheme클래스의 생성 인자
materialSkinManager.ColorScheme=new ColorScheme(Primary.BlueGrey900, Primary.BlueGrey900, Primary.BlueGrey500, Accent.LightBlue200, TextShade.WHITE); // 인자1 `Primary.BlueGrey900`: 테마의 기본 색상. 메인 강조 색상. 진한 청회색. // 인자2 `Primary.BlueGrey900`: 보조 색상으로 호버 색상. 초점 색상. // 인자3 `Primary.BlueGrey500`: 3차 색상. 배경색 or 은은한 그림자 색상으로 가끔 사용됨. // 인자4 `Accent.LightBlue200`: 버튼, 링크 등 강조 색상. 연한 파란색 // 인자5 `TextShade.WHITE`: 텍스트 음영
4. Form1.Designer.cs (버튼 클릭 이벤트/폼 예제)
namespace winform_ex02;
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private Button button1;
private TextBox textBox1;
private TextBox result1;
private Panel panel1;
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
// 버튼 컨트롤 생성 및 설정
this.button1 = new System.Windows.Forms.Button();
this.button1.Location = new System.Drawing.Point(10, 10);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(70, 50);
this.button1.Text = "Click Me!";
this.button1.UseVisualStyleBackColor = true;
// this.button1.Click += new System.EventHandler(this.button1_Click); // 클릭 이벤트 핸들러 등록
// 버튼을 폼에 추가
this.Controls.Add(this.button1);
// 텍스트 박스 생성 및 추가
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox1.Location = new System.Drawing.Point(10, 70);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(500, 500);
this.textBox1.Text = "";
// this.textBox1.UseVisualStyleBackColor = true;
this.Controls.Add(this.textBox1);
// 패널 생성 및 추가
this.panel1 = new System.Windows.Forms.Panel();
this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right | System.Windows.Forms.AnchorStyles.Bottom)));
this.panel1.Location = new System.Drawing.Point(10, 100);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(1090,330);
// this.panel1.TabIndex = 0;
// this.panel1.Width = this.ClientSize.Width;
// this.panel1.Height = this.ClientSize.Width;
// this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.AutoScroll = true;
this.panel1.BackColor = Color.DimGray;
this.Controls.Add(this.panel1);
// 텍스트 박스 생성 및 추가
this.result1 = new System.Windows.Forms.TextBox();
this.result1.Name = "resul1";
this.result1.Multiline = true;
this.result1.Location = new System.Drawing.Point(0, 0);
this.result1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.result1.Dock = System.Windows.Forms.DockStyle.Fill; // Dock 속성 설정
this.result1.Text = "";
// 텍스트 박스의 크기와 위치를 조정
// this.result1.Width = this.panel1.ClientRectangle.Width;
// this.result1.Height = this.panel1.ClientRectangle.Height;
this.panel1.Controls.Add(this.result1);
}
#endregion
}
지정된 명령 또는 파일을 찾을 수 없으므로 실행할 수 없습니다.
가능한 원인은 다음과 같습니다.
* 기본 제공 dotnet 명령 철자가 잘못 입력되었습니다.
* .NET 프로그램을 실행하려고 했지만, dotnet-ef이(가) 없습니다.
* 전역 도구를 실행하려고 했지만, 이 이름의 dotnet 접두사가 있는 실행 파일을 PATH에서 찾을 수 없습니다.
찾다보니 아래와 같은 문구를 발견했는데요...
이 도구는 더 이상 기본 제공되지 않으며 명시적인 설치가 필요하다는 ASP.NET Core 3 Preview 4발표를 참조하십시오 .
dotnet ef 도구는 더 이상 .NET Core SDK의 일부가 아닙니다.
이 변경dotnet ef으로 전역 또는 로컬 도구로 설치할 수있는 일반 .NET CLI 도구로 제공 할 수 있습니다. 예를 들어, 마이그레이션 또는 스캐 폴드 a를 관리 하려면 다음 명령을 입력하여 전역 도구로DbContext설치dotnet ef하십시오.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace wpf10_767id
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
// this.PrintSimpleTextButton.Click += printButton_Click;
}
private void printButton_Click(object sender, RoutedEventArgs e)
{
// Create a PrintDialog
PrintDialog printDialog = new PrintDialog();
if(printDialog.ShowDialog().GetValueOrDefault())
{
FontFamily fontFamily =new FontFamily("나눔고딕코딩");
FlowDocument doc = new FlowDocument(new Paragraph(new Run("출력 텍스트")));
doc.Name="FlowDoc";
IDocumentPaginatorSource idpSource = doc;
printDialog.PrintDocument(idpSource.DocumentPaginator, "(description)WPF Printing");
}
}
}
}
2. 글씨체 편집
<MainWindow.xaml.cs 수정>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace wpf10_767id
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
// this.PrintSimpleTextButton.Click += printButton_Click;
}
private void printButton_Click(object sender, RoutedEventArgs e)
{
// Create a PrintDialog
PrintDialog printDialog = new PrintDialog();
if(printDialog.ShowDialog().GetValueOrDefault())
{
FontFamily fontFamily =new FontFamily("나눔고딕코딩");
//// 함수 추가 ////
// FlowDocument doc = new FlowDocument(new Paragraph(new Run("일부 텍스트가 있습니다.")));
FlowDocument doc = CreateFlowDocument();
doc.Name="FlowDoc";
IDocumentPaginatorSource idpSource = doc;
printDialog.PrintDocument(idpSource.DocumentPaginator, "Hello WPF Printing.");
}
}
//// 함수 추가 ////
private FlowDocument CreateFlowDocument()
{
// Create a FlowDocument
FlowDocument doc = new FlowDocument();
// Create a Section
Section sec = new Section();
// Create first Paragraph
Paragraph p1 = new Paragraph();
// Create and add a new Bold, Italic and Underline
Bold bld = new Bold();
bld.Inlines.Add(new Run("First Paragraph"));
Italic italicBld = new Italic();
italicBld.Inlines.Add(bld);
Underline underlineItalicBld = new Underline();
underlineItalicBld.Inlines.Add(italicBld);
// Add Bold, Italic, Underline to Paragraph
p1.Inlines.Add(underlineItalicBld);
// Add Paragraph to Section
sec.Blocks.Add(p1);
// Add Section to FlowDocument
doc.Blocks.Add(sec);
return doc;
}
}
}
3. 프린트 다이얼로그 안띄우고 출력하기
<MainWindow.xaml.cs 수정>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Printing;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace wpf_test06_print
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void printButton_Click(object sender, RoutedEventArgs e)
{
// Create a PrintDialog
PrintDialog printDialog = new PrintDialog();
// 프린트 다이얼로그 안열고 출력하기
var printers = new LocalPrintServer().GetPrintQueues();
var selectedPrinter = printers.FirstOrDefault(p => p.Name == "Samsung SL-J1560 Series"); // 문자열을 실제 프린트 이름으로 변경
if(selectedPrinter == null)
{
MessageBox.Show("not found!");
return;
}
// 다이얼로그에서 값이 입력되면 폰트를 ...으로 설정
// if(printDialog.ShowDialog().GetValueOrDefault())
// {
// FontFamily fontFamily =new FontFamily("나눔고딕코딩");
// }
FlowDocument doc = new FlowDocument(new Paragraph(new Run(ResultBox.Text)));
doc.Name="FlowDoc";
IDocumentPaginatorSource idpSource = doc;
printDialog.PrintDocument(idpSource.DocumentPaginator, "(description)WPF Printing");
// 그리드 출력이 필요할 땐 추가 작업이 필요함
// PrintVisual 활용법 참조
// Grid grid = new Grid();
// grid.SetValue(FontFamilyProperty, fontFamily);
// grid.SetValue(FontSizeProperty , 32d );
// Canvas canvas = new Canvas();
// canvas.Width = printDialog.PrintableAreaWidth;
// canvas.Height = printDialog.PrintableAreaHeight;
// canvas.Background = null;
// canvas.Children.Add(grid);
// printDialog.PrintVisual(canvas, "Sample");
}
private void previewButton_Click(object sender, RoutedEventArgs e)
{
ResultBox.Text = textBox1.Text + textBox2.Text;
}
}
}
using LiveCharts;
using LiveCharts.Wpf;
using System;
using System.IO;
using LiveCharts.Defaults;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
namespace wpf_test04UT2
{
public partial class Dashboard : UserControl
{
public SeriesCollection SeriesCollection { get; set; }
public SeriesCollection LastHourSeries { get; set; }
public SeriesCollection LastHourSeries1 { get; set; }
public string[] Labels { get; set; }
public Func<double,string> Formatter { get; set; }
public Dashboard()
{
InitializeComponent();
SeriesCollection = new SeriesCollection{
new StackedColumnSeries
{
Values = new ChartValues<double> {25, 52, 61, 89},
StackMode = StackMode.Values,
DataLabels = true
},
new StackedColumnSeries
{
Values = new ChartValues<double> {-15, -75, -16, -49},
StackMode = StackMode.Values,
DataLabels = true
}
};
LastHourSeries = new SeriesCollection
{
new LineSeries
{
AreaLimit = -10,
Values = new ChartValues<ObservableValue>
{
new ObservableValue(3),
new ObservableValue(1),
new ObservableValue(9),
new ObservableValue(4),
new ObservableValue(5),
new ObservableValue(3),
new ObservableValue(1),
new ObservableValue(2),
new ObservableValue(3),
new ObservableValue(7),
}
}
};
LastHourSeries1 = new SeriesCollection
{
new LineSeries
{
AreaLimit = -10,
Values = new ChartValues<ObservableValue>
{
new ObservableValue(13),
new ObservableValue(11),
new ObservableValue(9),
new ObservableValue(14),
new ObservableValue(5),
new ObservableValue(3),
new ObservableValue(1),
new ObservableValue(2),
new ObservableValue(3),
new ObservableValue(7),
}
}
};
Labels = new[] { "Feb 7", "Feb8", "Feb 9", "Feb 10" };
Formatter = GetValue => GetValue.ToString();
DataContext = this;
string imgCartoon = Directory.GetCurrentDirectory().ToString()+"\\Images\\aaa.jpg";
string imgavatar = Directory.GetCurrentDirectory().ToString()+"\\Images\\bbb.jpg";
ImgCartoon.Source = new BitmapImage(new Uri(imgCartoon));
avatar1.Source = new BitmapImage(new Uri(imgavatar));
avatar2.Source = new BitmapImage(new Uri(imgavatar));
}
}
}
5. 결과
좀 있어보이나요? 좌측 메뉴가 동영상 강좌랑 달리 스타일이 안들어간 것 같습니다만, 수정하기 귀찮네요..필요할 때 하다보면 되겠죠..??ㅠㅠ