using System.Drawing;
using System.Drawing.Drawing2D;

void drawforeground(int xx,int yy,int width,int height,int ____hatchstyle)
{
HatchStyle hs = (HatchStyle)____hatchstyle;//0-52까지 가능
Brush myBrush = new HatchBrush(hs, System.Drawing.Color.SteelBlue);
Pen myPen = new Pen(System.Drawing.Color.LightGray, 1);

System.Drawing.Graphics formGraphics;
formGraphics = this.CreateGraphics();
formGraphics.FillRectangle(myBrush, new Rectangle(xx, yy, width, height));
formGraphics.DrawRectangle(myPen , xx, yy, width, height);
}
void drawforeground(int xx,int yy,int width,int height,int ____hatchstyle)
{
HatchStyle hs = (HatchStyle)____hatchstyle;//0-52까지 가능
Brush myBrush = new HatchBrush(hs, System.Drawing.Color.LightYellow);
Pen myPen = new Pen(System.Drawing.Color.LightGray, 1);

System.Drawing.Graphics formGraphics;
formGraphics = this.CreateGraphics();
formGraphics.FillRectangle(myBrush, new Rectangle(xx, yy, width, height));
formGraphics.DrawRectangle(myPen , xx, yy, width, height);
}

ex31.cs
0.00MB
ex11.cs
0.02MB

 

1. Hexa,ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ

1. Horizon Direction
2. Vertical Direction
3. LeftToRight Direction
4. LightToLeft Direction

2. Tettris,ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ

1. Horizon Direction

파일첨부

frm_common.cs
0.02MB




LINQ 쿼리 소개(C#)

쿼리 는 데이터 소스에서 데이터를 검색하는 식입니다. 
쿼리는 일반적으로 특수화된 쿼리 언어로 표현됩니다. 
관계형 데이터베이스에는 SQL이 사용되고 XML에는 XQuery가 사용되는 것처럼 시간에 따라 다양한 형식의 데이터 소스에 대해 서로 다른 언어가 개발되었습니다. 
따라서 개발자는 지원해야 하는 데이터 소스의 형식이나 데이터 형식에 따라 새로운 쿼리 언어를 배워야 했습니다. 
LINQ는 다양한 데이터 소스 및 형식에 사용할 수 있는 일관된 모델을 제공함으로써 이러한 상황을 단순화합니다. 
LINQ 쿼리에서는 항상 개체를 사용합니다. 
XML 문서, SQL 데이터베이스, ADO.NET 데이터 세트, .NET 컬렉션 및 LINQ 공급자를 사용할 수 있는 다른 모든 형식에서 데이터를 쿼리하고 변환하는 데 동일한 기본 코딩 패턴을 사용합니다.

쿼리 작업의 세 부분
모든 LINQ 쿼리 작업은 다음과 같은 세 가지 고유한 작업으로 구성됩니다.

1. 데이터 소스 가져오기.(Data Source)
2. 쿼리 만들기.(Query)
3. 쿼리 실행.(Query Execution)


ex)

using System.Linq;
using System;

class IntroToLINQ
{
    static void Main()
    {
        // The Three Parts of a LINQ Query:
        // 1. Data source.
        int[] numbers = new int[7] { 0, 1, 2, 3, 4, 5, 6 };

        // 2. Query creation.
        // numQuery is an IEnumerable<int>
        var numQuery =
            from num in numbers
            where (num % 2) == 0
            select num;

        // 3. Query execution.
        foreach (int num in numQuery)
        {
            Console.Write("{0,1} ", num);
        }
    }
}

 

/*execution display
D:\tmp\console>ex200
0 2 4 6
D:\tmp\console>
D:\tmp\console>
D:\tmp\console>
*/

WinForms와 WPF의 한가지 가장 큰 차이점은 WinForms는 단순히 Standard Windows Control(e.g a TextBox)의 최상단 레이어인 반면에 WPF는 맨처음부터 거의 모든 경우에 Standard Windows Control에 의존하지 않도록 만들어졌다.

# winform이 먼저 발표되었습니다.

마소(마이크로소프트)에서 개발한 윈도우 환경에서 개발자들이 프로그램을 개발하기 위해서는 기계어를 알아야 했지만, 개발 생산성을 올리기 위해서 다양한 프레임워크가 탄생하게 되었는데요. 그중에서 .Net Framework가 있고, 그 중에서 C#으로 개발하는데 사용되는 UI 개발도구로 Winform과 Wpf가 있습니다.

Winform의 경우 .Net 1.0 부터 지원되었고, 이는 드레그 앤 드롭 방식으로 자신이 생성하고 싶은 컨트롤을 UI 개발창에 올리면 자동으로 코드가 생성되고, 결과는 개발자가 볼 수 있는 방식이였습니다. 이는 매우 직관적이고 초보자도 쉽게 개발 할 수 있다는 장점이 있었습니다. 

이런식으로 버튼 하나를 선택해서 원하는 위치에 올리면 Control이 생성되는 방식입니다. 이때 해당 Form에는 디자인코드와 소스코드가 생성되는데요. 디자인코드는 코드보기를 선택하여 해당 Form의 디자인코드를 볼 수 있습니다. 

하지만 이 디자인 코드는 자동으로 생성이 되기 때문에 별도로 수정을 하지 않아도 어느정도 자신이 원하는 컨트롤을 만들 수 있습니다. 

Wpf의 경우 .Net 3.0 부터 지원이 되었고, Winform이 갖고 있던 다양한 한계를 해결하고 만들어졌습니다. 그래서 Winform에 비해서 더 다양한 기능과 확장성을 갖고 있습니다. 

Winform에서는 Form이라면 Wpf에서는 Control이 있습니다. Control을 상속 받아서 다양한 Control이 생성되는데요. Window, UserControl, Button 처럼 다양한 Control을 만들 수 있습니다. 

처음 Wpf 프로젝트를 생성하면 MainWindow.xaml 이라는 것을 볼 수 있는데요. 이는 C# 코드와 xaml 코드가 합쳐진 형태입니다. 그래서 xaml 코드를 이용해서 디자인 작업을 하고 C# 코드를 이용해서 필요한 기능을 구현하기도 합니다. 

위쪽이 C# 코드이고 아래쪽이 xaml 코드입니다. 실제로 xaml 코드는 다양한 곳에서 사용되는데요. 여기서 xaml은 Extensible Application Markup Language 의 약자로 흔히 마크업 언어라고 불리는 언어들 중에 하나인데요. 인터넷 브라우저에서 F12를 누르면 나오는 코드들과 비슷한 형태의 코드라고 보시면 됩니다. 

WPF는 Winform의 한계를 극복하기 위해서 그리고 더 다양한 확장성을 갖기 위해서 만들어진 UI 개발 프레임워크인데요. 처음 WPF와 Winform을 접하는 분들에게는 Winform 더 직관적이고 쉬울 수 있으나, 실제 실무에서는 Winform 보다는 Wpf를 더 많이 사용하고 있고, 다양한 클라이언트의 요구를 만족시키기 위해서라도 Wpf가 더 좋은 선택이라고 생각하는데요. 한번 배우는데, 오래 걸리고 MVVM이나 Binding, DependencyProperty 와 같은 생소한 개념들이 있기 때문에 거부감이 들 수 있지만, 이러한 기능들은 개발자의 편의를 위해서 개발된 기능이기 때문에 충분히 익힌다면, 오히려 도움이 될 것이라고 생각합니다. 


In C#,,,,,,,,

When Owner draw Control ,,,,,,,,,,,,

ex105.cs
0.00MB

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

...

/// <summary>
/// 메시지 보내기
/// </summary>
/// <param name="windowHandle">윈도우 핸들</param>
/// <param name="message">메시지</param>
/// <param name="wParam">WORD 파리미터</param>
/// <param name="lParam">LONG 파라미터</param>
/// <returns>처리 결과</returns>
[DllImport("User32.dll")]
public static extern Int64 SendMessage(IntPtr windowHandle, uint message, IntPtr wParam, IntPtr lParam);

...

/// <summary>
/// WM_PAINT
/// </summary>
private const int WM_PAINT = 0x000f;

...

#region ForcePaint(form)

/// <summary>
/// 강제로 칠하기
/// </summary>
/// <param name="form">폼</param>
public void ForcePaint(Form form)
{
    SendMessage(form.Handle, WM_PAINT, IntPtr.Zero, IntPtr.Zero);
}

#endregion


설명) Form에 테트리스게임이 수행되고 인는중이라도, 백그라운드로 쓰레드 2개가 현재 동작하는 모습을 나타냅니다.
여러모로 실전활용가능한 모델입니다.

1. Form Activate & Other Statistic Possible(Threading Background)
2. BackgroundWorker
3. Form Drawing
4. Data set,get
5. Tris
6. Form - WM_PAINT Logic

basic !!

ex11.cs
0.01MB

Background class
Tris class divide!!!

ex12.cs
0.01MB

static class ----> #define instead!!

ex13.cs
0.01MB

design pattern various!!

ex14.cs
0.01MB

/*
 * BackgroundWorker 사용법 : Form 혹은 Console이 사라지면 함께 작동을 멈춘다.
 * BackgroundWorker 클래스
   네임스페이스: System.ComponentModel
 */


using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Threading;

public class Program : Form
{
int toggle=0;

public Program()
{
this.Text="BackgroungWorker Thread Process!!";
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN))
{
         switch (keyData)
         {
         case Keys.S:
             break; 
         case Keys.F5:
             break; 
         case Keys.Enter:
             Application.Exit();
             break;
         case Keys.Tab:
             break;
         default:
             break;
         }
     }
return base.ProcessCmdKey(ref msg, keyData);
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);

try
{
switch(m.Msg)
{
default:
if(toggle==0)
{
BackgroundMakeCls nm = new BackgroundMakeCls();
nm.running();

toggle=100; //Form이 실행시에 오직 한번만 수행하도록 한다.
}
break;
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
public static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Program());
}
}

public class BackgroundMakeCls
{
BackgroundWorker recvWorker = new BackgroundWorker();
BackgroundWorker sendWorker = new BackgroundWorker();

public void running()
{
recvWorker.DoWork += new DoWorkEventHandler(recvWorker_DoWork);
recvWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(recvWorker_RunWorkerCompleted);

sendWorker.DoWork += new DoWorkEventHandler(sendWorker_DoWork);
sendWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(sendWorker_RunWorkerCompleted);

recvWorker.RunWorkerAsync();
}
void recvWorker_DoWork(object sender, DoWorkEventArgs e)
{
Console.WriteLine(">>>>recvWorker_DoWork");
}
void recvWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
Console.WriteLine(">>>>recvWorker_RunWorkerCompleted");

try
{
if(! sendWorker.IsBusy) sendWorker.RunWorkerAsync();
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
void sendWorker_DoWork(object sender, DoWorkEventArgs e)
{
Console.WriteLine(">>>>recvWorker_DoWork");
}
void sendWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
Console.WriteLine(">>>>recvWorker_RunWorkerCompleted");

try
{
if(! recvWorker.IsBusy) recvWorker.RunWorkerAsync();
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}

+ Recent posts