GSI

Drag a Panel

하나의 패널 속에 여러개의 패널을 삽입이 가능하다.
이걸 가지고 패널 속에 Visio 와 같은 에디팅 화면을 구현할 수 있을거 같다.
물론 Panel이 아닌 ScrollView 등 다양한 뷰에도 구현이 가능해 진다.

특정 이벤트에 따라서 Panel에 여러개의 Panel 자식 컨트롤을 추가 한 후에
자식 Panel의 이벤트를 사용해서 각각의 패널을 동작시킬 수 있다.

우선 이벤트에 따른 자식 Panel로 등록하는 코드 이다.

private void button2_Click(object sender, EventArgs e)
{
    Panel childPanel = new Panel();
    childPanel.BackColor = System.Drawing.Color.Gainsboro;
    childPanel.Location = new System.Drawing.Point(67, 44);
    childPanel.Name = "panel4";
    childPanel.Size = new System.Drawing.Size(71, 78);
    childPanel.MouseDown += new MouseEventHandler(childPanel_MouseDown);
    childPanel.MouseMove += new MouseEventHandler(childPanel_MouseMove);
    childPanel.MouseUp += new MouseEventHandler(childPanel_MouseUp);
    panel2.Controls.Add(childPanel);
}
- 여러개의 패널이 등록 되지만 이벤트를 처리 하는 함수는 동일하게 가져 가게 되면
  공통적으로 Panel을 처리할 수 있다. (childPanel_MouseDown, Move, Up)

이제 Drag a Panel을 구현하기 위한 코드이다.

private bool dragging = false;
private Point offset;

void childPanel_MouseDown(object sender, MouseEventArgs e)
{
    dragging = true;
    offset = new Point(e.X, e.Y);
}

void childPanel_MouseMove(object sender, MouseEventArgs e)
{
    if (dragging)
    {
        Panel selPanel = (Panel)sender;
        selPanel.Left = e.X + selPanel.Left - offset.X;
        selPanel.Top = e.Y + selPanel.Top - offset.Y;
    }
}

void childPanel_MouseUp(object sender, MouseEventArgs e)
{
    dragging = false;
}

- 전역 변수로 dragging, offset를 선언해 놓는다.
- Down 일때 드래그가 시작되었다고 알리고, 현재 위치를 저장한다.
- Move 일때 드래그라면 현재 선택된 패널 정보를 가져와서 Left, Top를 설정한다.
- Up 일때 드래그가 끝났다고 알린다.

드래그 이벤트는 다양한 컨트롤에서 사용되어 지며, 사용자의 입력을 받아서
처리 되는 다양한 효과를 구현할 수 있다.

관련 MSDN 주소 : http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=689097&SiteID=1

Posted by gsi
:

[C#] - IO 관련 자료

C# 2008. 3. 3. 00:05 |

(펌) - http://blog.naver.com/hahnes2?Redirect=Log&logNo=40023072069

System.IO.BinaryReader

System.IO.BinaryWriter

System.IO.BufferdStream

System.IO.Directory

System.IO.DirectoryInfo

System.IO.DirectoryNotFoundException

System.IO.EndOfStreamException

System.IO.ErrorEventArgs

System.IO.File

System.IO.FileInfo

System.IO.FileLoadException

System.IO.FileNotFoundException

System.IO.FileStream

System.IO.FileSystemEventArgs

System.IO.FileSystemInfo

System.IO.FileSystemWatcher

System.IO.InternalBufferOverflowException

System.IO.IODescriptionAttribute

System.IO.IOException

System.IO.IsolatedStorage.IsolatedStorage

System.IO.IsolatedStorage.IsolatedStorageException

System.IO.IsolatedStorage.IsolatedStorageFile

System.IO.IsolatedStorage.IsolatedStorageFileStream

System.IO.MemoryStream

System.IO.Path

System.IO.PathTooLongException

System.IO.RenamedEventArgs

System.IO.Stream

System.IO.StreamReader

System.IO.StreamWriter

System.IO.StringReader

System.IO.StringWriter

System.IO.TextReader

System.IO.TextWriter

관련 내용을 아주 자세하게 작성해 주셨네요.
감사^^

Posted by gsi
:

Flicker Free Drawing In MFC

이런 주제의 CodeProject 의 내용을 볼 수 있다.
테스트해본 코드 주소는 http://www.codeproject.com/KB/GDI/flickerfree.aspx 이며,
해본 결과 Flicker 를 줄일 수 있었다.

기존의 다른 코드를 사용해서 처리 할때
Release 시 드로잉이 되지 않는 문제점이 발생하였다.
솔직히 이거 때문에 디버깅에 시간이 좀 걸렸다.
나머지 모듈을 다 제거 하고나서야 이 클래스를 사용하지 않고 디버깅을 해봐야 겠다.
생각이 들었고, 빼고 보니 제대로 되었다.
즉, CMemDC 클래스가 이상하다는 것을 알았고,
위의 주소에 있는 내용을 복사해서 처리 하니 되었다.

물론 생성자에 CRect 의 내용도 포함될 수 있는 코드도 있는걸로 봐서
ActiveX 와 같은 곳에서도 사용될 수 있을거 같다.

관련 페이지 >

Sample Image

Posted by gsi
:

MFC 의 Doc, View 부분의 구조를 취하다 보면,
여러개의 다이얼로그를 구성하고 그곳에 데이터의 정보가 연동되는 경우가 있는데,
사실상 이때 new, open, save, saveas 를 고려 해서 작업을 해야 할듯 하다.

어느정도 된 후에 이것을 고려 할려다 보면 많은 부분 수정이 가해진다.

그래서 생각이 든건데, new, save, saveas 가 고려되지 않을 경우에
그 함수를 생성해서 데이터 로직 처리 해보는게 더 좋은 구조를 취할 수 있을거 같다.

더 좋은 방법이 있을까?.
혹.. 더 잘아시는분 있으시면.. 연락주세요 ^^
Posted by gsi
:

파일 저장 다이얼로그

 static char BASED_CODE szFilter[] = "Bitmap Files(*.*)|*.bmp|Jpeg Files(*.*)|*.jpg|Colorplay Files(*.*)|*.colorplay|All Files(*.*)|*.*|";
 CFileDialog dlg(TRUE, _T("*.*"), _T("*.*"), OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter);
 dlg.m_ofn.lpstrInitialDir = "";     //기본 경로를 설정한다.

 if(dlg.DoModal() == IDOK)
 {
 }

Posted by gsi
: