윈도우즈 서비스에서


System.Environment.CurrentDirectory 을 호출하면 "C:\Windows\System32"를 카리킨다.


그럴때 두가지 방법이 있다.


1. System.Windows.Forms 을 참조하고 System.Windows.Forms.Application.StartupPath을 호출


2. System.Reflection.Assembly.GetEntryAssembly().Location



'.Net > .Net' 카테고리의 다른 글

[.Net] 닷넷프레임워크 버전 확인  (0) 2013.05.10
[.Net] TransactedInstaller  (0) 2013.04.22
[.Net] Changing Start Mode of a Windows Service  (0) 2013.04.20
[.Net] Mutex 클래스  (0) 2013.04.19
[.Net] ServiceController  (0) 2013.04.18
posted by 뚱2

[WinForm] OpenFileDialog

.Net/WinForm 2013. 3. 13. 15:46
OpenFileDialog open_file_dialog = new OpenFileDialog();
open_file_dialog.Filter = "dat Files|*.dat|All Files|*.*";
open_file_dialog.FilterIndex = 1;
open_file_dialog.RestoreDirectory = true;

try
{
    if (open_file_dialog.ShowDialog() == DialogResult.OK)
    {
        import_path = open_file_dialog.FileName;
    }
}
catch (System.Exception)
{
}

'.Net > WinForm' 카테고리의 다른 글

[.Net] FolderbrowserDialog Custom Action  (0) 2014.02.08
[WinForm] 서브클래스에서 OnPaint가 안될때...  (0) 2013.02.22
posted by 뚱2

TextBox에 PlaceHolder 기능을 추가해야 해서 이것 저것 해보다가

 

OnPaint로 그릴 생각까지 했는데 분면 OnPaint를 오버라이드 했는데도 이벤트가 발생하지 않았습니다.

그럴때는 서브클래싱한 컨트롤에서 SetStyle을 설정('SetStyle(ControlStyles.userPaint, true)')해줘야 합니다.

 

SetStyle : http://msdn.microsoft.com/ko-kr/library/system.windows.forms.control.setstyle.aspx

 

그런데 구글링으로 찾은 소스중 보다 Win32 API를 이용해서 텍스트박스에 PlaceHolder 기능을 구현한게 있네요.

 

public class CueTextBox : TextBox

{  

    private static class NativeMethods

    {

        private  const uint ECM_FIRST       = 0x1500;

        internal const uint EM_SETCUEBANNER = ECM_FIRST + 1;

        [DllImport("user32.dll", EntryPoint = "SendMessageW")]

        public static extern IntPtr SendMessageW(IntPtr hWnd, UInt32 Msg, IntPtr wParam, [MarshalAs(UnmanagedType.LPWStr)] string lParam);

    }

    private string _cue;

    [

        Description("PlaceHolder로 사용될 텍스트"),

        Category("Appearance"),

        Browsable(true),

    ]        

    public string Cue

    {

        get

        {

            return _cue;

        }

        set

        {

            _cue = value;

            UpdateCue();

        }

    }

    public CueTextBox()

    {

        this.SetStyle(ControlStyles.UserPaint, false);

        this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);

    }

    protected override void OnPaint(PaintEventArgs e)

    {

        base.OnPaint(e);

    }

    private void UpdateCue()

    {

        if (IsHandleCreated && _cue != null)

        {

            NativeMethods.SendMessageW(Handle, NativeMethods.EM_SETCUEBANNER, (IntPtr)1, _cue);

        }

    }

    protected override void OnHandleCreated(EventArgs e)

    {

        base.OnHandleCreated(e);

        UpdateCue();

    }

}


'.Net > WinForm' 카테고리의 다른 글

[.Net] FolderbrowserDialog Custom Action  (0) 2014.02.08
[WinForm] OpenFileDialog  (0) 2013.03.13
posted by 뚱2

[C#] Form close와 Dispose

.Net/C# 2013. 1. 28. 20:19

링크 (Form.Dispose) : http://msdn.microsoft.com/ko-kr/library/aw58wzka(v=vs.90).aspx

링크 (Form.Close) : http://msdn.microsoft.com/ko-kr/library/system.windows.forms.form.close(v=vs.90).aspx 


모달리스로 닫을시에는 Form.Close()를 호출

모달로 닫을시에는 Form.DialogResult 프로퍼티에 값을 대입

posted by 뚱2

[.Net] pinvoke.net

.Net/.Net 2013. 1. 7. 16:46

링크 : http://www.pinvoke.net/index.aspx 

 

win32 API 를 .Net에서 사용할때 .Net에 맞게 DllImport를 해야 하는데 그 변환 문법이 만만치 않다.

각 함수별로 잘 정리되어 있는 사이트

 

* 사이트 메인 화면을 보면 Visual Studio 2010, 2012 Add-In 프로그램도 존재한다. Winform으로 개발시 유용할듯

'.Net > .Net' 카테고리의 다른 글

[.Net] Aspect Oriented Programming With .Net  (0) 2013.01.14
[.Net] 웹 자동화 구현 클래스  (0) 2013.01.09
[.Net] Windows 서비스 응용 프로그램  (0) 2012.12.07
[.Net] Zlib Wrapper  (0) 2012.05.22
[.Net] Inter-Process Communication  (0) 2012.04.17
posted by 뚱2