.Net] 버튼 Pressed Event!!
버튼 -> 누르고 있으면 이벤트 발생 ~
클릭과는 다른 동작을 함.
# 차이는 다음과 같음.
void jsfW_Button1_MouseUp(object sender, MouseEventArgs e)
{
jsfW_Button1.ForeColor = Color.Black;
}
// 버튼을 누른체 1초후 발생 -> Click Event 는 건너뜀.
void jsfW_Button1_MousePressing(object sender, EventArgs e)
{
jsfW_Button1.ForeColor = Color.Red;
label1.Text += "Press" + Environment.NewLine;
}
void jsfW_Button1_MouseDown(object sender, MouseEventArgs e)
{
jsfW_Button1.ForeColor = Color.Black;
}
void jsfW_Button1_Click(object sender, EventArgs e)
{
label1.Text += "클릭"+ Environment.NewLine;
}
# 소스
public class JSFW_Button : Button
{
bool isMDown = false;
TimeSpan PressingTimeSpan = TimeSpan.MinValue;
bool IsPressed = false;
protected override void OnMouseDown(MouseEventArgs mevent)
{
base.OnMouseDown(mevent);
if (mevent.Button == System.Windows.Forms.MouseButtons.Left)
{
isMDown = true;
PressingTimeSpan = new TimeSpan(DateTime.Now.Ticks);
Action pressingAction = PressChecking;
pressingAction.BeginInvoke(ir => pressingAction.EndInvoke(ir), pressingAction);
}
}
void PressChecking()
{
IsPressed = false;
while (isMDown)
{
Debug.Write(DateTime.Now.Subtract(PressingTimeSpan).Millisecond + Environment.NewLine);
if( TimeSpan.FromTicks( DateTime.Now.Ticks ).Subtract(PressingTimeSpan).TotalMilliseconds > 1000 )
{
Invoke( new Action<EventArgs>( OnMousePressing), EventArgs.Empty);
break; // Thread 종료!
}
System.Threading.Thread.Sleep(200);
}
}
protected override void OnClick(EventArgs e)
{
if (IsPressed == false)
{
base.OnClick(e);
}
IsPressed = false;
}
protected override void OnMouseUp(MouseEventArgs mevent)
{
isMDown = false;
base.OnMouseUp(mevent);
}
public event EventHandler MousePressing = null;
protected void OnMousePressing(EventArgs e)
{
if (MousePressing != null)
{
IsPressed = true;
MousePressing(this, e);
}
}
}
'# 4) .Net ( Vs 2010 ) > C#' 카테고리의 다른 글
GDI+] 이미지 회전! (0) | 2012.08.13 |
---|---|
2010 WinForm ] 컨트롤 리사이징 예제... (0) | 2012.07.20 |
.NET ] 멀티 랭귀지 지원 ... (0) | 2012.03.06 |
ArrayList.Sort 하기... (4) | 2011.07.29 |
[IPC] Event 추가 ~~ (0) | 2011.05.14 |
.NET] 트리 뷰_ 체크박스 - 더블클릭
더블 클릭하니 체크박스가 이상한 동작을 함...
이에 대한 버그대처는 아래.. 출처에 있음.
출처 :
http://anandopaul.wordpress.com/2010/01/01/c-treeview-checkbox-double-click-bug-for-vista-and-win7/
using System;
using System.Windows.Forms;
public class NewTreeView : TreeView {
protected override void WndProc(ref Message m) {
if (m.Msg == 0x203) { m.Result = IntPtr.Zero; }
else base.WndProc(ref m);
}
}
'# 1) 프로그래밍' 카테고리의 다른 글
C#] 문자열 정렬처리... (0) | 2013.11.10 |
---|---|
.net] 모니터링 프로그램... (0) | 2012.05.13 |
.net ] 한글 유니코드 변환 (0) | 2012.04.07 |
.Net] 배율 맞추기 II (0) | 2012.03.25 |
.Net] 가운데 이동 (0) | 2012.03.25 |
.net ] 한글 유니코드 변환
훈스 닷넷에 올라온 글 중
유니코드 관련된 글이 올라왔는데 Neo님 댓글 보고 대략 짐작해보고 댓글 달고
지켜보니 잘 안된다고 해서 주말에 시간을 좀 내서 확인해보니 그만큼 쉽지 않았다.
약간의 검색을 통해 아래 링크에 자세히 적혀있는것을 보고 훑어보고 만들었다.
저런걸 생각하는 사람은 정말 대단한것 같다.
// 유니코드 -> 조합형
string[] Chosungs = new string[19] { "ㄱ", "ㄲ", "ㄴ", "ㄷ", "ㄸ", "ㄹ", "ㅁ", "ㅂ", "ㅃ", "ㅅ", "ㅆ", "ㅇ", "ㅈ", "ㅉ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ" };
string[] jungsungs = new string[21] { "ㅏ", "ㅐ", "ㅑ", "ㅒ", "ㅓ", "ㅔ", "ㅕ", "ㅖ", "ㅗ", "ㅘ", "ㅙ", "ㅚ", "ㅛ", "ㅜ", "ㅝ", "ㅞ", "ㅟ", "ㅠ", "ㅡ", "ㅢ", "ㅣ"};
string[] jongsungs = new string[28] { "", "ㄱ", "ㄲ", "ㄳ", "ㄴ", "ㄵ", "ㄶ", "ㄷ", "ㄹ", "ㄺ", "ㄻ", "ㄼ", "ㄽ", "ㄾ", "ㄿ", "ㅀ", "ㅁ", "ㅂ", "ㅄ", "ㅅ", "ㅆ", "ㅇ", "ㅈ", "ㅊ", "ㅋ" , "ㅌ", "ㅍ", "ㅎ" };
private void button3_Click(object sender, EventArgs e)
{
string 초 = "ㅂ";
string 중 = "ㅞ";
string 종 = "ㄺ";
int chidx = (Array.IndexOf(Chosungs, 초) *588 )+
( Array.IndexOf(jungsungs, 중) * 28 )+
( Array.IndexOf(jongsungs, 종) );
this.textBox2.Text = Convert.ToChar(chidx + 44032)+ "";
}
'# 1) 프로그래밍' 카테고리의 다른 글
.net] 모니터링 프로그램... (0) | 2012.05.13 |
---|---|
.NET] 트리 뷰_ 체크박스 - 더블클릭 (0) | 2012.04.09 |
.Net] 배율 맞추기 II (0) | 2012.03.25 |
.Net] 가운데 이동 (0) | 2012.03.25 |
.Net] 양쪽 맞춤. (0) | 2012.03.25 |
.Net] 배율 맞추기 II
음... 사이즈 배율 조절하기인데...
음... 조금 고민거리가 있긴하다
배율조정하면 이게 좌표가 자꾸 바뀌므로 가운데 이동을 시켜주는데...
그냥 해당 위치만큼 off 조절하는 로직을 고민해봐야겠음.
void ZoomIn()
{
int idx = toolStripComboBox1.ComboBox.SelectedIndex;
if (Factors.Length > toolStripComboBox1.ComboBox.SelectedIndex + 1)
toolStripComboBox1.ComboBox.SelectedIndex++;
}
void ZoomOut()
{
int idx = toolStripComboBox1.ComboBox.SelectedIndex;
if (0 <= toolStripComboBox1.ComboBox.SelectedIndex - 1)
toolStripComboBox1.ComboBox.SelectedIndex--;
}
void ZoomSet(int Idx)
{
if (0 <= Idx && Idx < Factors.Length)
{
float SelectFactor = Factors[Idx];
float FactorF = SelectFactor / OldFactor;
ControlScale(toolStripContainer1.ContentPanel.Controls, FactorF);
OldFactor = SelectFactor;
CenterMove();
}
}
private void ControlScale( Control.ControlCollection ctrls, float FactorF)
{
if( ctrls == null ) return;
foreach (Control ctrl in ctrls)
{
if (ctrl.Tag != null) continue;
ctrl.Scale(new SizeF(FactorF, FactorF));
ctrl.Font = new Font(ctrl.Font.FontFamily, ctrl.Font.Size * FactorF);
// 최상위 컨트롤의 AutoScaleMode = None!!설정
if (ctrl.Controls != null && ctrl.Controls.Count > 0)
{
ctrl.Width = ctrl.Controls[0].Width + GS_Class_UI_Config.Margin;
ctrl.Height = ctrl.Controls[0].Height + GS_Class_UI_Config.Margin;
ctrl.Controls[0].Left = GS_Class_UI_Config.OffSet_XY;
ctrl.Controls[0].Top = GS_Class_UI_Config.OffSet_XY;
}
}
}
'# 1) 프로그래밍' 카테고리의 다른 글
.NET] 트리 뷰_ 체크박스 - 더블클릭 (0) | 2012.04.09 |
---|---|
.net ] 한글 유니코드 변환 (0) | 2012.04.07 |
.Net] 가운데 이동 (0) | 2012.03.25 |
.Net] 양쪽 맞춤. (0) | 2012.03.25 |
.Net] C# 객체 숨기기.... (0) | 2012.03.22 |
.Net] 가운데 이동
한 판넬에 컨트롤들을 중심점으로 이동시키기 위해...
바로 중심점으로 이동시... 한번에 안되기도 한다? 왜일까? 오차?.. 오차 치고는 좀 컸는뎅...
원점으로 이동했다가 다시 중심점으로 이동시켜주니 잘 되던데....
private void CenterMove2()
{
Rectangle rct = toolStripContainer1.ContentPanel.ClientRectangle;
float cx = rct.Width / 2f + rct.Left;
float cy = rct.Height / 2f + rct.Top;
area = ContentRegion2(); // 중심점으로 이동시키고 모든 컨텐츠의 영역을 가져옴.
float ccx = area.Width / 2f + area.Left;
float ccy = area.Height / 2f + area.Top;
foreach (Control ctrl in toolStripContainer1.ContentPanel.Controls)
{
ctrl.Left = ctrl.Left + (int)( (cx - ccx));
ctrl.Top = ctrl.Top + (int)((cy - ccy));
}
area.X = area.X + (int)(cx - ccx);
area.Y = area.Y + (int)(cy - ccy);
ContentInvalidate();
}
'# 1) 프로그래밍' 카테고리의 다른 글
.net ] 한글 유니코드 변환 (0) | 2012.04.07 |
---|---|
.Net] 배율 맞추기 II (0) | 2012.03.25 |
.Net] 양쪽 맞춤. (0) | 2012.03.25 |
.Net] C# 객체 숨기기.... (0) | 2012.03.22 |
C# 포인터... (0) | 2012.03.16 |
.Net] 양쪽 맞춤.
컨트롤들을 하나의 판넬에 몰아 넣었을때... 특정 배율에 화면에 꽉 채우기 위해 계산한 방법임.
그러나. 아래 대각선 비율로만 하면 한쪽이 너무 클 경우 꽉찬 배율로 맞출수 없으므로,
가로, 세로를 각각 아래 같은 방법으로 계산 후 가장 좋은 조건으로 선택해서 Zoom 처리 해주어야 했다.
void AutoSizeFit2()
{
try
{
Rectangle rct = toolStripContainer1.ContentPanel.ClientRectangle;
float cx = rct.Width / 2f + rct.Left;
float cy = rct.Height / 2f + rct.Top;
toolStripComboBox1.SelectedIndex = 0; //Zoom 0번째 부터...
area = ContentRegion();
// 대각선
//double d1 = rct.Width > rct.Height ? rct.Width : rct.Height;
//double d2 = area.Width > area.Height ? area.Width : area.Height;
//double a0 = Math.Sqrt(Math.Pow(d1, 2d) + Math.Pow(d1, 2d));
//double a1 = Math.Sqrt(Math.Pow(d2, 2d) + Math.Pow(d2, 2d));
//// a : b = c : d 계산!! ad = bc
//double ze = a0 * Factors[0] / a1;
//int loop = Factors.Length;
//while (ze <= Factors[--loop] && loop >= 0) ;
//가로
//double d1 = rct.Width > rct.Height ? rct.Width : rct.Height;
//double d2 = area.Width > area.Height ? area.Width : area.Height;
//double a0 = d1;//Math.Sqrt(Math.Pow(d1, 2d) + Math.Pow(d1, 2d));
//double a1 = d2;// Math.Sqrt(Math.Pow(d2, 2d) + Math.Pow(d2, 2d));
//// a : b = c : d 계산!! ad = bc
//double ze = a0 * Factors[0] / a1;
//int loop = Factors.Length;
//while (ze <= Factors[--loop] && loop >= 0) ;
//세로
//double d1 = rct.Height;
//double d2 = area.Height;
//double a0 = d1;//Math.Sqrt(Math.Pow(d1, 2d) + Math.Pow(d1, 2d));
//double a1 = d2;// Math.Sqrt(Math.Pow(d2, 2d) + Math.Pow(d2, 2d));
//// a : b = c : d 계산!! ad = bc
//double ze = a0 * Factors[0] / a1;
//int loop = Factors.Length;
//while (ze <= Factors[--loop] && loop >= 0) ;
#region 가로 / 세로 병행 ( 이게 제일 빠르네!! )
// 세로
double d1 = rct.Height;
double d2 = area.Height;
double ze1 = d1 * Factors[0] / d2;
int loop1 = Factors.Length;
while (ze1 <= Factors[--loop1] && loop1 > 0) ;
// 가로
double a0 = rct.Width;
double a1 = area.Width;
// a : b = c : d 계산!! ad = bc
double ze2 = a0 * Factors[0] / a1;
int loop2 = Factors.Length;
while (ze2 <= Factors[--loop2] && loop2 > 0) ;
toolStripComboBox1.SelectedIndex = loop1 < loop2 ? loop1 : loop2 ;
#endregion
}
finally
{
CenterMove2();
}
}
'# 1) 프로그래밍' 카테고리의 다른 글
.Net] 배율 맞추기 II (0) | 2012.03.25 |
---|---|
.Net] 가운데 이동 (0) | 2012.03.25 |
.Net] C# 객체 숨기기.... (0) | 2012.03.22 |
C# 포인터... (0) | 2012.03.16 |
컨트롤 마우스 이동 처리 (0) | 2012.03.14 |
.Net] C# 객체 숨기기....
특정 객체를 숨겨야 할때...? 엥??? 설명이 쉽지 않군...
이번 시스템 모니터링에 중심이 되는 조그만한 객체 하나가 있다.
이 객체의 내용은 모두 암복호화 시킬 예정이기에 dll을 참조한다고 해서 툭 튀어나오면 안된다.
또한 관련된 객체( 참조...)들에서도 점 찍어서 텨나오면 안된다.
물론 리플렉터로는 답없다 ㅡ.,ㅡ;
## 조건 ############################################################
1. 프로젝트 A영역에 [숨겨야 할 객체] 가 존재
2. 프로젝트 B영역에선 숨겨야 할 객체가 보여선 안됨.
프로젝트 = dll ( 어셈블리 ) 단위
namespace 프로젝트 A영역
{
public interface 통신인터페이스
{
string 이름 { get; }
}
public class 옮겨줄객체 : 통신인터페이스
{
public 옮겨줄객체( string name )
{
nm = name;
}
string nm = "";
string 통신인터페이스.이름
{
get { return nm; }
}
}
internal class 숨겨야할객체
{
public string 이름
{ get; set; }
}
public class 공개된객체
{
internal List<숨겨야할객체> 비밀 = new List<숨겨야할객체>();
public void 데이타전달(통신인터페이스 m)
{
비밀.Add(new 숨겨야할객체(){ 이름 = m.이름 });
}
}
}
공개된객체 에서 숨겨야야할 객체를 internal로 가지고 있다.
이러면 물론 프로젝트A영역에선 인텔리센스를 이용하면 보인다.
그러나, 타 프로젝트에서는 볼 수 없다.
이러면 끝이 아니다... 이유인즉. 공개된 객체어서 숨겨야 할 비밀 객체에 데이타를 전달!
그럼 Property를 이용해서 넣어주면 되지 않는가? 이지만!!
지금 설계하고 있는 것이 컬렉션 데이타 이므로... Get 시켜줄수도 없공... 일일이 파라미터로 받자니..
또 hash...등등.. 컬렉션으로 받기도 애매하다... 객체 자체가 internal이기에 ...
이때, 통신 인터페이스 + 옮겨줄 데이타 객체를 통해서 구성해준다.
namespace 프로젝트영역B
{
....
공개된객체 ad = new 공개된객체();
옮겨줄객체 mp = new 옮겨줄객체("Map");
ad.데이타전달(mp);
....
}
옮겨줄 객체에 먼저 담고 - 전달해준다.
음.. 쓰다보니... 괜한짓인가???
'# 1) 프로그래밍' 카테고리의 다른 글
.Net] 가운데 이동 (0) | 2012.03.25 |
---|---|
.Net] 양쪽 맞춤. (0) | 2012.03.25 |
C# 포인터... (0) | 2012.03.16 |
컨트롤 마우스 이동 처리 (0) | 2012.03.14 |
.Net 2008 ] XML 직렬화 (0) | 2012.03.13 |
C# 포인터...
훈스에 글올리신 분이 있어서 답변달다가
깊은 복사. 얉은 복사..
값타입을 파라미터로 넘겨주면 메모리 주소를 넘겨주는게 깊은복사
값들을 복사해서 새 메모리에 적재해서 넘겨주는게 얉은복사...
음!! 아닌가? 어느 블로그는 반대로 설명이 되있어서... 아리 까리 하네...
기록해둔것 같은데 없네...
int n = 10;
int k = 112;
string t = "";
string s = "";
string h = "";
unsafe
{
t = string.Format("{0}", (int)&n);
s = string.Format("{0}", (int)&k);
}
t +="/"+ Ptr( n); // 바뀐 주소값이 넘어오는것을 볼 수 있다.
t += "/" + Ptr(ref n); // 처음 n값과 같은 주소값.
s += "/" + Ptr(ref k);
public unsafe string Ptr( int n)
{
string addr = "";
addr = string.Format("{0}", (int)&n);
return addr;
}
public unsafe string Ptr(ref int n)
{
string addr = "";
unsafe
{
fixed( int* l = &n )
{
addr = string.Format("{0}", (int)l);
}
}
return addr;
}
'# 1) 프로그래밍' 카테고리의 다른 글
.Net] 양쪽 맞춤. (0) | 2012.03.25 |
---|---|
.Net] C# 객체 숨기기.... (0) | 2012.03.22 |
컨트롤 마우스 이동 처리 (0) | 2012.03.14 |
.Net 2008 ] XML 직렬화 (0) | 2012.03.13 |
Conditional 속성 사용!!! (0) | 2011.10.26 |
컨트롤 마우스 이동 처리
기억력 감퇴인가.. 기록해둔것 같은디..
protected override void OnControlAdded(ControlEventArgs e)
{
base.OnControlAdded(e);
e.Control.MouseDown += new MouseEventHandler(Control_MouseDown);
e.Control.MouseMove += new MouseEventHandler(Control_MouseMove);
e.Control.MouseUp += new MouseEventHandler(Control_MouseUp);
}
bool IsDown = false;
Point mStart;
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
IsDown = false;
}
void Control_MouseUp(object sender, MouseEventArgs e)
{
OnMouseUp(e);
}
void Control_MouseMove(object sender, MouseEventArgs e)
{
if (IsDown)
{
Control ctrl = (Control)sender;
ctrl.Left = ctrl.Left+ e.Location.X - mStart.X;
ctrl.Top = ctrl.Top +e.Location.Y - mStart.Y;
Invalidate();
}
}
void Control_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
IsDown = true;
mStart = e.Location;
}
}
'# 1) 프로그래밍' 카테고리의 다른 글
.Net] C# 객체 숨기기.... (0) | 2012.03.22 |
---|---|
C# 포인터... (0) | 2012.03.16 |
.Net 2008 ] XML 직렬화 (0) | 2012.03.13 |
Conditional 속성 사용!!! (0) | 2011.10.26 |
서버 모니터링 프로그램~~ (0) | 2011.06.26 |
.Net 2008 ] XML 직렬화
개발중에 샘플로 작성해본 코드인데
클래스별로 xml 형식을 제어하기 까다로워서 다른 방법으로 해결보았음.
기존에 XML Helper 로 만든 소스가 있지만... 아래보다 좋은데...
프로젝트에 쓸순 없공...
아래 샘플코드는 객체 -> XML , XML -> 객체 .
참 짧고 쉽다. 필요한경우 쓰면 좋을 듯 ...
/// <summary>
/// Xml 직렬화!!! 역직렬화
/// </summary>
public class XmlSerialize
{
public static string Serialize<T>(T svr)
{
StringBuilder XmlString = new StringBuilder();
TextWriter writer = new StringWriter(XmlString);
XmlSerializer serializer = new XmlSerializer(typeof(T), "Dokebi");
serializer.Serialize(writer, svr);
return XmlString.ToString();
}
public static T DeSerialize<T>( string xml ) where T : class
{
T DataObject = null;
TextReader reader = new StringReader(xml);
XmlSerializer serializer = new XmlSerializer(typeof(T), "Dokebi");
DataObject = (T)serializer.Deserialize(reader);
reader.Close();
return DataObject;
}
}
ArrayList 가 추가된 객체로 해봤는데 뭔가 에러가 발생한는뎅..
msdn 보다 보니 IList<T> 구현된건 안된다고 봤는뎅... 링크를 못찾겠공..
오늘 본 msdn은 또 ICollection 인가 하는 인터페이스를 구현한 객체는 또 된다고 나오공...
나중에 다시 직렬화 할 일이 있을때나....
예제1 )
[System.Xml.Serialization.XmlRoot("DemoXmlObject")]
public class DemoXmlObject
{
public string ID { get; set; }
public string Name { get; set; }
public bool Enable { get; set; }
[XmlIgnore]
public string Alias { get; set; }
}
-- 결과 -------------------------------------
<?xml version="1.0" encoding="utf-16"?>
<DemoXmlObject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="Dokebi">
<ID>ID</ID>
<Name>테스트</Name>
<Enable>true</Enable>
</DemoXmlObject>
예제2 )
[System.Xml.Serialization.XmlRoot("DemoXmlObject")]
public class DemoXmlObject
{
[XmlAttribute("ID")]
public string ID { get; set; }
[XmlAttribute("Name")]
public string Name { get; set; }
[XmlAttribute("Enable")]
public bool Enable { get; set; }
[XmlIgnore]
public string Alias { get; set; }
}
-- 결과 -------------------------------------
<?xml version="1.0" encoding="utf-16"?>
<DemoXmlObject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ID="ID" Name="테스트" Enable="true" xmlns="Dokebi" />
예제 3) 더미 추가
[System.Xml.Serialization.XmlRoot("Items")]
public class XmlDummy<T>
{
public T Item { get; set; }
}
DemoXmlObject obj = new DemoXmlObject();
obj.ID = "ID";
obj.Alias = "Melong";
obj.Name = "테스트";
obj.Enable = true;
string XmlString = XmlSerialize.Serialize<DemoXmlObject>(obj);
DemoXmlObject obj2 = XmlSerialize.DeSerialize<DemoXmlObject>(XmlString);
XmlDummy<DemoXmlObject> dummy = new XmlDummy<DemoXmlObject>();
dummy.Item = obj2;
string xml3 = XmlSerialize.Serialize < XmlDummy<DemoXmlObject> >(dummy);
-- 결과 -------------------------------------
<?xml version="1.0" encoding="utf-16"?>
<Items xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="Dokebi">
<Item>
<ID>ID</ID>
<Name>테스트</Name>
<Enable>true</Enable>
</Item>
</Items>
'# 1) 프로그래밍' 카테고리의 다른 글
C# 포인터... (0) | 2012.03.16 |
---|---|
컨트롤 마우스 이동 처리 (0) | 2012.03.14 |
Conditional 속성 사용!!! (0) | 2011.10.26 |
서버 모니터링 프로그램~~ (0) | 2011.06.26 |
로그 시스템... (0) | 2011.06.09 |