퇴근5분전

 

회전!! 뱅글 뱅글..

 

 Resource.R 은 회전 될 이미지

 

 

 public partial class Form1 : Form
    {
        float angle = 0f;
        Timer tm = new Timer();
        public Form1()
        {
            InitializeComponent();
            tm.Interval = 500;
            tm.Tick += new EventHandler(tm_Tick);
            tm.Start();
        }
        void tm_Tick(object sender, EventArgs e)
        {
            angle += 10;
            Invalidate();
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            e.Graphics.DrawImage( rotateImage( Resources.r , angle ), 100f, 100f);
        }
        /// <summary>
        /// 튜토리얼 :  http://www.switchonthecode.com/tutorials/csharp-tutorial-image-editing-rotate
        /// </summary>
        /// <param name="b"></param>
        /// <param name="angle"></param>
        /// <returns></returns>
        private Bitmap rotateImage(Bitmap b, float angle)
        {
            //create a new empty bitmap to hold rotated image
            Bitmap returnBitmap = new Bitmap(b.Width, b.Height);
            //make a graphics object from the empty bitmap
            Graphics g = Graphics.FromImage(returnBitmap);
            //move rotation point to center of image
            g.TranslateTransform((float)b.Width / 2, (float)b.Height / 2);
            //rotate
            g.RotateTransform(angle);
            //move image back
            g.TranslateTransform(-(float)b.Width / 2, -(float)b.Height / 2);
            //draw passed in image onto graphics object
            g.DrawImage(b, new Point(0, 0));
            return returnBitmap;
        }
    }

 

 

훈스 질답게시판에 이미지 리사이징 관련 글이 올라와서

 

30분 정도 짜보았음.  

 

 

 

 

 

콤보1, 버튼2, 체크박스1

 

판넬1,

 

픽쳐박스1 ( 이미지 리사이징 레이어 )

 

 

 

 

소스

 

public partial class Form1 : Form
    {
        float oldSizing = 100f;
        float[] factors = new float[] { 20, 50, 100, 120, 240 };

        public Form1()
        {
            InitializeComponent();
            comboBox1.DataSource = factors;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            comboBox1.SelectedIndex = 2;
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Resizing(comboBox1.SelectedIndex);
        }

        private void Resizing(int idx)
        {
            float CurrentSizing = factors[idx];
            pictureBox1.Scale(new SizeF(CurrentSizing / oldSizing, CurrentSizing / oldSizing));
            oldSizing = CurrentSizing;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //+
            ZoomIn();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //-
            ZoomOut();
        }

        void ZoomIn()
        {
            if (checkBox1.Checked)
            {
                Point Befor = GetCenter(pictureBox1);

                int idx = comboBox1.SelectedIndex;
                if (factors.Length > comboBox1.SelectedIndex + 1)
                    comboBox1.SelectedIndex++;

                Point after = GetCenter(pictureBox1);
                pictureBox1.Left = pictureBox1.Left - (after.X - Befor.X);
                pictureBox1.Top = pictureBox1.Top - (after.Y - Befor.Y);
            }
            else
            {
                int idx = comboBox1.SelectedIndex;
                if (factors.Length > comboBox1.SelectedIndex + 1)
                    comboBox1.SelectedIndex++;
            }
        }

        void ZoomOut()
        {
            if (checkBox1.Checked)
            {
                Point Befor = GetCenter(pictureBox1);

                int idx = comboBox1.SelectedIndex;
                if (0 <= comboBox1.SelectedIndex - 1)
                    comboBox1.SelectedIndex--;

                Point after = GetCenter(pictureBox1);
                pictureBox1.Left = pictureBox1.Left + (Befor.X - after.X);
                pictureBox1.Top = pictureBox1.Top + (Befor.Y - after.Y);
            }
            else
            {
                int idx = comboBox1.SelectedIndex;
                if (0 <= comboBox1.SelectedIndex - 1)
                    comboBox1.SelectedIndex--;
            }
        }
       
        Point GetCenter(Control c)
        {
            Point p = c.Location;
            p.X += (int)((float)c.Width / 2f);
            p.Y += (int)((float)c.Height / 2f);
            return p;
        }
    }

 

'# 4) .Net ( Vs 2010 ) > C#' 카테고리의 다른 글

WinForm] 단축키  (0) 2012.10.11
GDI+] 이미지 회전!  (0) 2012.08.13
.Net] 버튼 Pressed Event!!  (0) 2012.05.09
.NET ] 멀티 랭귀지 지원 ...  (0) 2012.03.06
ArrayList.Sort 하기...  (4) 2011.07.29

 버튼 -> 누르고 있으면 이벤트 발생 ~

 

클릭과는 다른 동작을 함.

 

 

# 차이는 다음과 같음.

 

  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


  멀티 랭귀지 지원에 대해 글을 한번 싸질러본다.

몇가지 글을 찾아보았는데... 영문에 장수도 만만치 않다.

따라해도 뭐가 빠졌는지 잘 안된다...

 따라하기를 포기하고 그냥 내방식대로 코드 노가다와 감으로 짜보니 되더라...


1. 새 프로젝트를 생성한다. ( 응용프로그램 : Form )
2. 프로젝트내에 기본으로 있는 Resources.resx 에  [이름)Name / 값)Name] 을 추가해준다. ( 영문명 )
3. 새 항목 추가로 리소스를 추가한다. 이때 이름은 Resources.ko-kr.resx 이다. ( 한글명 )
동일한 Key로 써야 하니까 [이름)Name / 값) 이름] 이라고 추가한다.
4. 폼에 버튼 하나를 놓아둔다.
5. Form 소스에서 버튼.Text 에 Name을 할당해보자.
---- 소스 --------------------------------------------------------------------------------------

 button1.Text = Demo_MultiLanguage.Properties.Resources.Name;

요렇게.... 넣으면 기본 리소스 이용으로 영문으로 "Name" 이  나온다.
Name으로 나오게 된다.

한글로 안나오는 이유를 보면..
Demo_MultiLanguage.Properties.Resources.Culture  요 값이 null 값으로

null이면 기본 리소스 값을 가져오는 듯 하다.

6. 이제 한글이 되도록 바꿔보자.
---- 소스 --------------------------------------------------------------------------------------

 Demo_MultiLanguage.Properties.Resources.Culture = new System.Globalization.CultureInfo("ko-kr");
 button1.Text = Demo_MultiLanguage.Properties.Resources.Name;

요러면... 버튼에 "이름" 이라고 표시된다.


## 중요 참고 사항 ###############################################################################

1. 새로 만든 리소스 파일명에 주의 한다.
Resources.resx
Resources.ko-kr.resx

2. 파일 위치를 잘 맞춘다.


끝!!!


--- 추가 내용 (잘못된 정보다)----------------------------------
{  // 또 실수할까봐... 남겨둔다.
all in one code framework 의 샘플들을 훑어보던 중 쇼킹..

Form아래 resx파일을 추가해두고
해당 resx에서  [이름)컨트롤명.프로퍼티 / 값) 값]  요거 하나로 끝나는걸 봤다.

코드를 넣을필요도 없네??? 멋지다.
}
>> 잘못된 정보다!!! 위!!


잘못된 정보대로 하니 안된다... 저걸로 하는게 아니고

의외로 간단하게 된다.

Form에 localizable 프로퍼티를 디자이너 에서 true 시켜놓고 디자인 작업을 하면 
자동으로 생성이 되네? -> resx에...
다음 그냥 디자이너에서 속성창에서 Text수정하면 자동으로 resx를 만들어 저장한다.

정리하면

그냥 로컬라이즈 = true 걸어놓고
언어 선택 후
디자이너에서 컨트롤 프로퍼티를 조정하면 알아서 저장된다 ㅡ.,ㅡ;;






'# 4) .Net ( Vs 2010 ) > C#' 카테고리의 다른 글

2010 WinForm ] 컨트롤 리사이징 예제...  (0) 2012.07.20
.Net] 버튼 Pressed Event!!  (0) 2012.05.09
ArrayList.Sort 하기...  (4) 2011.07.29
[IPC] Event 추가 ~~  (0) 2011.05.14
LINQ] 로또 구하기?  (1) 2011.04.25


ArrayList 에 담아 있는 데이타를 순서에 맞춰 정렬하는 부분에 대해 구현한 것임.

간단하다... 아래처럼 하면

 간단히 담는놈(ArrayList)에 담겨질놈(SortunitClass)을 담아서,
정렬할 방법을 가지고 있는 놈( SortunitClassCompare )에게 넘겨준다.



// 훈스에 올라온 질문글에 대한 답글로 단 소스임.
  public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            ArrayList ar = new ArrayList();

            ar.Add(new SortunitClass() { Index = 9, Data = "아홉" });
            ar.Add(new SortunitClass() { Index = 3, Data = "셋" });
            ar.Add(new SortunitClass() { Index = 5, Data = "다섯" });
            ar.Add(new SortunitClass() { Index = 11, Data = "열하나" });
            ar.Add(new SortunitClass() { Index = 1, Data = "하나" });

            ar.Sort(new SortunitClassCompare());
        }
    }

    public class SortunitClassCompare : IComparer, IComparer<SortunitClass>
    {
        public int Compare(SortunitClass x, SortunitClass y)
        {
            return x.Index.CompareTo(y.Index);
        }

        public int Compare(object x, object y)
        {
            return Compare((SortunitClass)x, (SortunitClass)y);
        }
    }


    public struct SortunitClass 
    {
        public int Index { get; set; }
        public string Data { get; set; }
    }

'# 4) .Net ( Vs 2010 ) > C#' 카테고리의 다른 글

.Net] 버튼 Pressed Event!!  (0) 2012.05.09
.NET ] 멀티 랭귀지 지원 ...  (0) 2012.03.06
[IPC] Event 추가 ~~  (0) 2011.05.14
LINQ] 로또 구하기?  (1) 2011.04.25
[C#]Box 그리기...  (0) 2010.11.29

회사에서의 서버 모니터링 프로그램을 만들면서

프로그램 or 서비스 등에서의 상태이벤트를 감시하는 프로그램을 만드는데 있어서...

IPC를 적용하였다. 초기 ipc를 사용하게 된 배경은 pc내에서 타 프로세스에서 모니터링 Agent로 상태를

전달하기 위해 공유객체를 이용하면 좋겠다 싶어서 였는데...

IPC 공유객체 관련해서 이벤트를 추가하는 부분은 없었다.

곧 한쪽에서 데이타를 넣었을때 -> 다른 쪽에서 이벤트를 발생시키는 로직에 대한 MSDN 은 찾을 수 가 없다.

찾다 찾다... TCPIP로 구현된것이 몇가지 있길래 분석하여 삽질을 통해 알아내고 만들었다. 

 서버 모니터링!!!  2주라...  어차피 등급은 초급이라 돈을 올려줄 순 없다면서 왜 일은 그런걸 시킬까...

어차피 만들고 있지만... 에효... 왠지 공개하기는 싫으넹..


'# 4) .Net ( Vs 2010 ) > C#' 카테고리의 다른 글

.NET ] 멀티 랭귀지 지원 ...  (0) 2012.03.06
ArrayList.Sort 하기...  (4) 2011.07.29
LINQ] 로또 구하기?  (1) 2011.04.25
[C#]Box 그리기...  (0) 2010.11.29
[C#]TabControl에서 특정 TabPage를 안보이게 감추기..  (0) 2010.11.26

한줄로 로또번호 구하기가 가능하네... Linq 역시 멋지넹... 

LINQ 역시 재미있엉...

 public partial class Form1 : Form
    {
        bool[] numbers = new bool[45];
        Random rd = new Random();
        public Form1()
        {
            InitializeComponent();
        
            var results = numbers.Select( (t, i ) => rd.Next(45) + 1 ).GroupBy( k => k ).TakeWhile((val , idx) => idx < 6 ).OrderBy( g => g.Key );
            listBox1.DataSource = results.ToArray();
            listBox1.DisplayMember = "Key";
        }
    }

'# 4) .Net ( Vs 2010 ) > C#' 카테고리의 다른 글

ArrayList.Sort 하기...  (4) 2011.07.29
[IPC] Event 추가 ~~  (0) 2011.05.14
[C#]Box 그리기...  (0) 2010.11.29
[C#]TabControl에서 특정 TabPage를 안보이게 감추기..  (0) 2010.11.26
[LINQ] 콤마 구분자 넣기?  (0) 2010.11.24

GDI+ 로 박스 그리고 그린객체 이동하기? 정도???

훈스에 올라온 질문에 답글한것임.. 


주석 없음! 



 public partial class Form1 : Form
    {
        Box b = new Box();
        public Form1()
        {
            InitializeComponent();
            b.Change += () => Invalidate();
        }
        int offset = 3;
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == Keys.Left)
            {
                b.X -= offset;
            }
            if (keyData == Keys.Right)
            {
                b.X += offset;
            }
            if (keyData == Keys.Up)
            {
                b.Y -= offset;
            }
            if (keyData == Keys.Down)
            {
                b.Y += offset;
            }

            return base.ProcessCmdKey(ref msg, keyData);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            b.Draw(e.Graphics);
        }
    }
    public class Box
    {
        public delegate void __delegateOnChange();
        Rectangle rct = new Rectangle();
        public Box()
        {
            lineColor = Color.Red;
            lineWidth = 2f;
            rct.Width = 10;
            rct.Height = 10;
        }
        public Size Size { get { return rct.Size; } set { rct.Size = value; OnChange(); } }
        public Point Location { get { return rct.Location; } set { rct.Location = value; OnChange(); } }
        public int X { get { return rct.X; } set { rct.X = value; OnChange(); } }
        public int Y { get { return rct.Y; } set { rct.Y = value; OnChange(); } }
        public int Width { get { return rct.Width; } set { rct.Width = value; OnChange(); } }
        public int Height { get { return rct.Height; } set { rct.Height = value; OnChange(); } }
        Color lineColor = Color.Red;
        public Color LineColor { get { return lineColor; } set { lineColor = value; OnChange(); } }
        float lineWidth = 2f;
        public float LineWidth { get { return lineWidth; } set { lineWidth = value; OnChange(); } }
        public event __delegateOnChange Change = null;
        public virtual void OnChange()
        {
            if (Change != null) Change();
        }
        public void Draw(Graphics g)
        {
            g.DrawRectangle(new Pen(LineColor, LineWidth), this.rct);
        }
    }

'# 4) .Net ( Vs 2010 ) > C#' 카테고리의 다른 글

[IPC] Event 추가 ~~  (0) 2011.05.14
LINQ] 로또 구하기?  (1) 2011.04.25
[C#]TabControl에서 특정 TabPage를 안보이게 감추기..  (0) 2010.11.26
[LINQ] 콤마 구분자 넣기?  (0) 2010.11.24
ChartFX 확장!  (0) 2010.10.05

 Hidden으로 지정된 페이지는 표시를 감춘다.. 

훈스에 질문이 올라왔길래 만들어봤음.. 

짧은 생각으론 그냥 패널 하나 감춰놓고 거기에 두면 되지 않을까 라는 생각에 리플 남기고 보니..

데이타들이 그룹으로 다녀야 된다면.. 숨겨둔 패널까지 데리고 다닐라면 골아프니...


   public class UcTabControl : TabControl
    {
        public TabPage HiddenPage {get; private set;}

        private int hiddenPageIndex = -1;
        public int HiddenPageIndex
        {
            get { return hiddenPageIndex; }
            set
            {
                if (0 <= value && value < this.TabPages.Count)
                {
                    if( HiddenPage != null && !this.TabPages.Contains( HiddenPage ) )
                    {
                        this.TabPages.Add(HiddenPage);
                    }
                    HiddenPage = this.TabPages[value];
                    hiddenPageIndex = value;
                }
                else
                {
                    HiddenPage = null;
                    hiddenPageIndex = -1;
                }
                Hidden();
            }
        }

        public UcTabControl()
        {
           
        }

        protected override void InitLayout()
        {
            base.InitLayout();
            Hidden();
        }

        private void Hidden()
        {
            if (!DesignMode)
            {
                if (HiddenPage != null && this.TabPages.Contains(HiddenPage))
                    this.TabPages.Remove(HiddenPage);
            }
        }
    }

'# 4) .Net ( Vs 2010 ) > C#' 카테고리의 다른 글

[IPC] Event 추가 ~~  (0) 2011.05.14
LINQ] 로또 구하기?  (1) 2011.04.25
[C#]Box 그리기...  (0) 2010.11.29
[LINQ] 콤마 구분자 넣기?  (0) 2010.11.24
ChartFX 확장!  (0) 2010.10.05


가끔 배열형태의 값을 콤마로 구분해서 문자열로 바꿔야 할때마다 foreach를 돌렸었는데...

훈스에 올라온 질문에 답글달았었는데 [후후예아]님이 좀더 깔끔하게 만드는 방법을 리플로...

아래... 빨간 1줄이 
파란 6줄... 결과는 쌤쌤.


            string data = "a,   b, c,   d  , e ,  f  " ;
            var k = data.Split(',').Except<string>( new string[]{ "a" }, this );

            string re = string.Join(",", k.ToArray());

            string result = "";
            foreach (var item in k)
            {
                result += item + ",";
            }

           
            result = result.TrimEnd(',');

'# 4) .Net ( Vs 2010 ) > C#' 카테고리의 다른 글

[IPC] Event 추가 ~~  (0) 2011.05.14
LINQ] 로또 구하기?  (1) 2011.04.25
[C#]Box 그리기...  (0) 2010.11.29
[C#]TabControl에서 특정 TabPage를 안보이게 감추기..  (0) 2010.11.26
ChartFX 확장!  (0) 2010.10.05