728x90

Programing Story's 260

[C# WinForm] 배경 화면 지정하기 (WallPaper)

C#에서 배경 화면 지정을 하고 싶다면 외부 dll인 user32.dl를 참조하여 SystemParametersInfo함수를 선언 후 사용 하여야 합니다 기본적인 사용법은 using System.Runtime.InteropServices; using Microsoft.Win32; public class _MainClass { [DllImport("user32.dll", CharSet = CharSet.Auto)] static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni); private const int SPI_SETDESKWALLPAPER = 20; private const int SPIF_U..

[C# WinForm] 엑셀 파일 사용 하기 (Excel)

C#에서 OleDb와 DataTable을 사용해 Excel 파일을 접근하여 사용할 수 있습니다 우선 Excel 클래스로는 using System; using System.Data; using System.Data.OleDb; using System.Windows.Forms; public class CExcel { private OleDbConnection m_Conn = null; private OleDbCommand m_Comm = null; public bool Open(string sFileName) { try { string sConn = string.Empty; if (sFileName.Substring(sFileName.Length - 4, 4).ToLower().Equals("xlsx")) ..

[C# WPF] GIF 파일 재생하기 (MediaElement)

gif 파일을 실행하고 싶다면 기본 컨트롤중 MediaElement를 활용하면 재생이 가능합니다 사용법은 MediaElement me = new MediaElement(); me.Tag = strSite; me.Stretch = Stretch.Fill; me.Width = iWidth; me.Height = iHeight; me.UnloadedBehavior = MediaState.Manual; me.Source = new Uri(strImagePath, UriKind.RelativeOrAbsolute); me.MediaEnded += new RoutedEventHandler(me_MediaEnded); 컨트롤 배치 후 코드를 작성하게 되면 자동으로 gif 파일이 움직이게 됩니다 하지만 gif가 끝나는 ..

[C# WPF] Background 이미지 설정하기

UIElement (Control)의 배경 이미지를 특정 파일로 설정하려면 string strImagePath = AppDomain.CurrentDomain.BaseDirectory + @"\img.jpg"; if (File.Exists(strImagePath)) { System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(strImagePath); BitmapSource bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap() , IntPtr.Zero , Int32Rect.Empty , BitmapSizeOptions.FromEmptyOptions()); ..

[C# WPF] 이미지 화질 개선 (Bitmap 화질 높이기)

C# WPF 를 사용하다 보면 크기 조정 등으로 이미지가 깨지거나 일그러질 경우 자체적으로 보완하는 함수가 존재합니다 해당 함수는 System.Windows.Media.RenderOption.SetBitmapScalingMode 함수로 해당 함수 사용 시 옵션에 따라 개선된 이미지를 제공받을 수 있습니다 사용법은 System.Windows.Media.RenderOption.SetBitmapScalingMode(this, BitmapScalingMode); 위의 방식으로 2번째 인자값에는 public enum BitmapScalingMode { // 요약: // System.Windows.Media.BitmapScalingMode.Linear인 기본 비트맵 배율 조정을 사용합니다. Unspecified =..

[C# WPF] X / Y 좌표로 Margin 위치 구하기

C# WinForm의 경우 X, Y 좌표값으로 컨트롤을 배치하는 반면 WPF의 경우 Margin으로 좌표 위치를 구해야 합니다 그럴 경우 해당 컨트롤의 크기만 있으면 해당 Margin 값을 쉽게 구할 수 있습니다 현재 창의 크기를 가져와서 계산 후 컨트롤의 Margin 값을 대입시키면 됩니다 int iRMargin = (int)this.Width - {X_POS} - {Control_Width}; int iBMartin = (int)this.Height - {Y_POS} - {Control_Height}; {Control}.Margin = new Thickness((double){X_POS}, (double){Y_POS}, (double)iRMargin, (double)iBMartin); 위의 형태로 함..

[C# WPF] 마우스 올렸을때 변화 주기 (IsMouseOver Trigger)

xaml 파일에서 마우스 올렸을 때 TextBlock의 글자 크기나 색상을 변경시키고 싶을 때 아래와 같이 작성하면 쉽게 구현이 가능합니다 위와 같이 작성을 하면 마우스를 올리기 전 기본일 때는 폰트 크기는 12 글자 색상은 #D3D3D3 값을 가지고 있다가 마우스가 올라오면 폰트 크기는 16으로 글자 색상은 흰색으로 변경됩니다 Padding의 경우 마우스 위치를 중앙에 맞춰주기 위해 임의의 값을 넣었습니다 제 글이 도움이 되셨다면 댓글 & 공감 부탁드려요 😀

[C# WPF] 함수에서 다중 인자 값 넘겨 받기

함수를 사용하다 보면 다중 인자 값을 받아야 할 경우가 생깁니다 이럴 때는 아래와 같이 코드를 작성해 주시면 됩니다. public void ListLoad(params string[] strPath) { //사용법 1 foreach (string Values in strPath) { MessageBox.Show(Values); } //사용법 2 int iArgs = strPath.Length; for (int iCnt = 0; iCnt < iArgs; iCnt++) { MessageBox.Show(strPath[iCnt]); } } 사용법 1의 경우 Foreach 사용방법이고 사용법 2의 경우 인자값의 크기를 가져와서 For 문으로 처리하는 방식입니다 제 글이 도움이 되셨다면 댓글 & 공감 부탁드려요 :)

[C# WPF] 파일의 아이콘을 추출해서 BitmapImage 변환하기

특정 파일의 아이콘을 추출하여 BitampImage로 변환을 하기 위해서는 아래와 같은 함수를 사용하면 됩니다 private BitmapImage LoadIcon(string filename) { Icon ico = System.Drawing.Icon.ExtractAssociatedIcon(filename); Bitmap bmp = ico.ToBitmap(); MemoryStream ms = new MemoryStream(); bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.StreamSource = ms; bi.CacheOption = BitmapCacheO..

[C# WPF] StackPanel Control 구분 하기

ListView 컨트롤에서 StackPanel를 쓸 경우 여러 개의 StackPanel을 구분하기가 쉽지 않습니다 그럴 때는 함수의 자식 컨트롤에 따라 구분하시면 됩니다 우선 XAML 파일에서 아래와 같이 ListView의 DataTemplate를 작성하고 아래와 같이 cs 파일에서 특정 데이터를 Binding 합니다 MovieData []mydata = new MyData[m_iCount]; for (int iCnt = 0; iCnt < m_iCount; iCnt++) { mydata[iCnt] = new MyData { Title = "Test" + (iCnt + 1).ToString(), ImageData = LoadImage(@"...") }; } listView1.ItemsSource = myd..

728x90
반응형