[C#] 프린트 C# 2009. 2. 3. 21:56

흠.. 일단 간단한 프린트를 하기 위한 코드이다.

각 출력 결과에 따른 포멧 형식은 자신들이 정해야겠지만..

필자는 단지 출력 테스트를 한 것 뿐..

별 다른게 없다^_^

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;

namespace Print
{
    public partial class Form1 : Form
    {
        private PageSettings m_PageSetting = null;
        private Font m_subFont = new Font("굴림체",13);
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                PageSetupDialog Psetup = new PageSetupDialog();
                if (this.m_PageSetting == null)
                    this.m_PageSetting = new PageSettings();
                Psetup.PageSettings = this.m_PageSetting;
                Psetup.ShowDialog();
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                PrintDocument pd = new PrintDocument();
                pd.PrintPage += new PrintPageEventHandler(this.PrintPageEvent);

                if (this.m_PageSetting != null)
                    pd.DefaultPageSettings = this.m_PageSetting;

                PrintPreviewDialog pdlg = new PrintPreviewDialog();
                pdlg.Document = pd;
                pdlg.ShowDialog();
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }

        protected void PrintPageEvent(Object obj,PrintPageEventArgs pea)
        {
            Graphics g = pea.Graphics;
            PrintDocument(g);
            pea.HasMorePages=false;
        }

        private void PrintDocument(Graphics g)
        {
            g.FillRectangle(Brushes.White, 100, 50, 800, 600);
            StringFormat sf = new StringFormat();
            sf.Alignment = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;
            Rectangle rect = new Rectangle(110, 130, 400, this.m_subFont.Height * 10);
            g.DrawString(this.txt_Content.Text, this.m_subFont, Brushes.Black, rect);
        }

        private void button3_Click(object sender, System.EventArgs e)
        {
            try
            {
                PrintDocument pd = new PrintDocument();
                pd.PrintPage += new PrintPageEventHandler(this.PrintPageEvent);
                if (this.m_PageSetting != null)
                    pd.DefaultPageSettings = this.m_PageSetting;
                PrintDialog pdlg = new PrintDialog();
                pdlg.Document = pd;
                if (pdlg.ShowDialog() == DialogResult.OK)
                {
                    pd.Print();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}

-_- 그냥... 무지 간단하다..

다른거 필요없다;;

혹여나 모르시는 분들을 위해;;

필자도 오랜만에 해본 것이라서 잊을까봐;;

일단 허브에 해당 랜선을 다 꽂는다 -_- 물론 컴퓨터에도 꽂아야겠죠?

그 다음.. -_- DNS를 제외한 IP와 Subnetmask, Gateway를 입력하면.. 끝이다..

아 참고로 -_- 오라클이나 SQL같은 Datadase도 연결 가능하겠죠?^_^

네!! 가능합니다!!
SandCastle 이란 놈을 이용하면 XML을 이용해서 문서를 작성 할 수가 있다.

SandCastle 설치 폴더에 Examples\generic아래에 Gui에 해당하는 실행 프로그램을 실행한 후

각 해당하는 항목에 Add 해 주면 된다.

-. Assembly And Comment Files


Assemblies :
작성할 대상의 DLL 설정한다. 개의 DLL 또는 다수의 DLL, 폴더를 통째로 지정할 있다.

 

Comments : DLL 생성시 같이 생성되는 XML 코멘트 파일을 설정한다.

Comments파일을 지정하지 않더라도 Help File 생성할 있지만 경우 Syntax 외에 중요한 정보들은 Help File 나타나지 않는다.

                   

Dependent Assemblies : 해당 DLL에서 참조하는 DLL들을 지정한다. 참조하는 DLL 지정하지 않을 경우 Help File 생성되지 않는다.

 

-. Options

Name : Sandcastle 프로젝트 명이자, 출력될 폴더 명이 된다.

 

Presentation Style : Help File 출력 타입을 설정한다.

 

Language ID : 생성될 Help File 언어를 설정, 한국어는 1042

 

Default Targets : 출력할  대상 설정

-. Log : Build버튼을 눌러 실행하면 모든 로그가 항목에 나타난다.

          Build 실패할 경우 로그를 통해 원인을 있다.


Build
완료되면 지정된 폴더에 Name항목에 설정한 폴더가 생성된다.

기본적으로 생성물은 C:\Program Files\Sandcastle\Examples 폴더아래에 Name 설정한 폴더명으로 생성이 되며, generic.targets파일의 BuildDir 항목을 수정하여 변경할 있다.

 

기본적으로 Sandcastle 사용되는 모든 파일을 복사하여 사용하고, 원본 파일은 사용하지 않는다.

comments : 화면에서 지정한 코멘트파일(XML) 폴더에 자동 복사되어 진다.

 

dll : Assemblies 에서 지정한 DLL Dependent Assemblies 지정한 참조 파일들이

폴더에 자동으로 복사되어진다.

 

hana, vs2005, prototype : Presentation Style에서 지정한 Style 폴더가 생성되고

최종 결과물(.chm파일) 폴더 하위의 chm 폴더에 생성된다.

SandCastle 파일은 아래 주소에 가면 받을 수 있다.

http://www.codeplex.com/Sandcastle/Release/ProjectReleases.aspx?ReleaseId=13873

[C#] 윈도우 좌표~ C# 2009. 1. 19. 17:44
            Rectangle screenRect = Screen.PrimaryScreen.WorkingArea;
            Rectangle tempRect = new Rectangle(screenRect.Right - 890, -8, 500, 0);
            this.DesktopBounds = tempRect;

-_-ㅋ 말 그대로 좌표를 가지고 온답;;;
[C#]Tray Icon C# 2009. 1. 16. 15:43

Tray Icon..

-_-a 뭐 기본적으로 그런 내용이다;;

언젠가 쉽게 쓸 일이 있겠지 ㅋㅋ

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;//이벤트 취소
            this.WindowState = FormWindowState.Minimized;//폼 최소화
            this.ShowInTaskbar = false;//작업표시줄 표시 금지
        }

        private void Tray_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            this.Visible = true;
            this.ShowInTaskbar = true;    // 현재 프로그램을 테스크 바에 표시하게 한다.   
            this.WindowState = FormWindowState.Normal; // 폼을 윈도 상태를 normal
            Tray.Visible = false; // 트레이의 아이콘을 보이지 않게 한다. 
        }

아 -_- contextmenu 넣어줄라면?
this.tray.contextmenu=this.contextmenu(생성한것) 해주기!

[C#]volatile C# 2009. 1. 15. 10:38

volatile 키워드는 동시에 실행 중인 여러 스레드에 의해 필드가 수정될 수 있음을 나타냅니다. volatile로 선언된 필드에는 단일 스레드를 통한 액세스를 전제로 하는 컴파일러 최적화가 적용되지 않습니다. 이렇게 하면 필드의 값을 항상 최신 상태로 유지할 수 있습니다.

일반적으로 volatile 한정자는 액세스를 serialize할 때 lock 문을 사용하지 않고 여러 스레드에서 액세스하는 필드에 사용됩니다. 

volatile 키워드는 다음과 같은 형식의 필드에 적용할 수 있습니다.

  • 참조 형식

  • 안전하지 않은 컨텍스트의 포인터 형식. 포인터 자체는 volatile일 수 있지만 포인터가 가리키는 개체는 volatile일 수 없습니다. 즉, "volatile 개체에 대한 포인터"를 선언할 수 없습니다.

  • sbyte, byte, short, ushort, int, uint, char, float 및 bool 같은 정수 계열 형식

  • 정수 계열 형식을 기반으로 한 열거형

  • 참조 형식으로 알려진 제네릭 형식 매개 변수

  • IntPtrUIntPtr

volatile 키워드는 클래스 또는 구조체의 필드에만 적용할 수 있습니다. 지역 변수는 volatile로 선언할 수 없습니다. 

[예제]

// csharp_volatile.cs

// Compile with: /target:library

class Test

{

   public volatile int i;


   Test(int _i)

   {

      i = _i;

   }

}


출처 : MSDN

싱글턴 패턴을 보다가 신기한 것을 알았다 -_-

Syncronized를 할 경우 멀티 스레딩의 경우 효율적이지 못한 결과가 일어난다.

성능 저하를 말하는 것이다.

하지만 -_- DCL..

요놈을 이용하면 된답 -_-

이것은 인스턴스가 생성 되었는지 확인하고 난 다음 생성되지 않을때만 동기화를 한다

하지만 요놈은.. 1.4버전 이전은.. 되지 않는답 ㅠㅡㅠ

다음은 그 간단한 코드 예이다

public class Test{

         private volatile static Test t;

         private Test(){}

         public static Test getInstance(){
                if(t==null){
                     syncronized(Test.class){
                             if(t==null){
                                     t = new Test();
                             }
                     }
                 }
         }
}
[C#]스레드 C# 2009. 1. 14. 10:47
스레드 생성에는 Thread,ThreadPool,Timer Class를 이용한 세가지 방법이 존재한다.

여기서 Thread Class를 이용한 스레드는 과도한 문맥전환의 문제가 있을 수 있다.

이에 ThreadPool Class는 Pool을 구성하고 적정량의 스레드를 수용함으로

Thread Class를 이용한 것보다 좀 더 안정적이다.

Timer Class의 경우는 일정 시간마다 스레드를 자동으로 활성화 해 준다.

1.Thread Class

Thread th = new Thread(new ThreadStart(대상));

2. ThreadPool Class

ThreadPool.QueueUserWorkItem(new WaitCallBack(대상,null);

3. Timer Class

Timer timer = new Timer(new TimerCallBack(대상),null,시간,100);
[C#]BackgroundWorker. C# 2009. 1. 12. 14:20
private BackgroundWorker myWorker = new BackgroundWorker();

myWorker.DoWork += new DoWorkEventHandler(myWorker_DoWork);
myWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(myWorker_RunWorkerCompleted);
myWorker.RunWorkerAsync() ;

먼저 BackgroundWorker는 다른 영역의 쓰레드를 실행 시키게 해 준다.

즉 메인 영역의 쓰레드가 아닌 별개의 영역을 말한다.

여기서 생성된 쓰레드는 DoWork 이벤트 핸들러에 의해서 작업이 수행된다.

만약 DoWork의 작업이 완료되거나 취소될 경우는 그 다음 RunWorkerCompletedEventHandler가 실행되어 쓰레드의 종료 또는 취소 후의 처리를 해 준다.

myWorker.RunWorkerAsync() 는 다른 영역에서 쓰레드가 실행되게 해 준다는 뜻이다.

http://www.synch3d.com/wiki/moin/moin.cgi/Effective_20C_23


찬찬~ 히 보면 많은 도움이 된다지요~

-_-/ 꼭 인터넷이 되는데만 보세요 ㅎㅎ