Programming/c# & winform2020. 11. 4. 17:51

ImageAnimator 클래스를 이용해서 비트맵과 프레임변경 핸들러를 추가하면

ImageAnimator.UpdateFrames()를 통해 다음 프레임을 원하는대로 그리는 듯

투명도 되려나?

 

using System;
using System.Drawing;
using System.Windows.Forms;
 
namespace BackgroundWorkerTest
{
    public partial class SandGlass : Form
    {
        public SandGlass()
        {
            InitializeComponent();
            this.StartPosition = FormStartPosition.CenterScreen;
        }
 
        Bitmap bit;
        protected override void OnLoad(EventArgs e)
        {
            bit = new Bitmap("sandglass.gif");
            ImageAnimator.Animate(bit, new EventHandler(this.OnFrameChanged));
            base.OnLoad(e);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            ImageAnimator.UpdateFrames();
            Graphics g = pictureBox1.CreateGraphics();
            g.DrawImage(this.bit, new Point(0, 0));
            base.OnPaint(e);
        }
        private void OnFrameChanged(object sender, EventArgs e)
        {
            this.Invalidate();
        }
    }
}

[링크 : https://blog.naver.com/goldrushing/130184365511]

[링크 : https://docs.microsoft.com/en-us/dotnet/api/system.drawing.imageanimator.animate?view=dotnet-plat-ext-3.1]

Posted by 구차니
Programming/c# & winform2020. 10. 30. 15:21

말이 이상하네 -ㅁ-

원본 이미지는 큰데 출력할 PictureBox는 작고

그 PictureBox 위에서 클릭 드래그 하면 사진이 움직이는 것을 구현하려고 한참을 고생했는데

결과물은 딸랑 두줄 -_-

 

        private void OnMouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button.HasFlag(MouseButtons.Left))
            {
                Bitmap bmp = global::testproject.Properties.Resources.septa_map;
                pictureBox2.CreateGraphics().DrawImage(bmp, new Point(e.X, e.Y));
            }
        }

[링크 : https://www.c-sharpcorner.com/.../how-to-make-image-editor-tool-in-C-Sharp-cropping-image/]

[링크 : https://docs.microsoft.com/ko-kr/dotnet/api/system.windows.forms.mousebuttons?view=netcore-3.1]

 

 

+

중간에 아무생각 없이 new Bitmap 엄청했더니 OutOfMemory 에러를 보지 않나 난리 법석이었네

Posted by 구차니
Programming/c# & winform2020. 10. 30. 12:26

접근제한자를 아무생각없이 써서 발생한 문제 -_ㅠ

 

"일관성 없는 접근성: ‘type’ 매개 변수 형식이 ‘method’ 메서드보다 접근성이 부족합니다."

내용대로 매개변수의 접근성이 method의 접근성보다 낮을 경우 발생한다.

 

 

그러니까

메소드는 public 인데

인자는 private 형일때 발생했다.

 

[링크 : https://docs.microsoft.com/ko-kr/dotnet/csharp/language-reference/compiler-messages/cs0051]

Posted by 구차니
Programming/c# & winform2020. 10. 30. 12:09

특이하게도.. 색상 지정할때는 값을 주면 되는데

기본 색상으로 하려면 new를 해주어야 한다.

 

if (lblExample.ForeColor != System.Drawing.Color.Red)
{
    lblExample.ForeColor = System.Drawing.Color.Red;
}
else
{
    lblExample.ForeColor = new System.Drawing.Color();
}

[링크 : https://stackoverflow.com/.../how-to-programmatically-set-the-forecolor-of-a-label-to-its-default]

Posted by 구차니
Programming/c# & winform2020. 10. 30. 11:47

어떻게 여러개의 값을 넣을 방법이 있을 것 같아서 찾아보는데

"항목 편집" 을 누르면 "문자열 컬렉션 편집기" 라는게 뜨고

엔터로 구분해서 입력해 주면 자동으로 Item에 추가된다.

Items나 Text에 해주어야 하는줄 알았는데 그냥 "항목 편집"을 누르면 된다.

 

반대로 다국어 지원시 문자열을 넣는걸 찾아봐야겠네..

 

 

            // 
            // comboBox_direction
            // 
            this.comboBox_direction.FormattingEnabled = true;
            this.comboBox_direction.Items.AddRange(new object[] {
            "Forward",
            "Backward",
            "Neutral"});
            this.comboBox_direction.Location = new System.Drawing.Point(65, 220);
            this.comboBox_direction.Name = "comboBox_direction";
            this.comboBox_direction.Size = new System.Drawing.Size(121, 20);
            this.comboBox_direction.TabIndex = 4;

 

 

[링크 : https://docs.microsoft.com/ko-kr/dotnet/api/system.windows.forms.combobox?view=netcore-3.1]

Posted by 구차니
Programming/c# & winform2020. 10. 29. 16:34

불가능 하진 않은 것 같은데.. 많이는 안쓰는 기능인지 잘 없네

하긴 나라도 IE 기반으로 먼가 프로그램을 동적으로 주고 받으면서 하라고 하진 않을 듯..

 

 

[링크 : https://stackoverflow.com/questions/12950413/accessing-dom-from-webbrowser]

[링크 : https://stackoverflow.com/questions/42495828/access-the-dom-using-webbrowser/42701789]

[링크 : https://docs.microsoft.com/.../how-to-access-the-managed-html-document-object-model...]

 

[링크 : https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.htmldocument?view=netcore-3.1]

Posted by 구차니
Programming/c# & winform2020. 10. 26. 14:40

Screen.AllScreens.OrderBy() 를 통해

WorkingArea.X 값을 정렬하면 되긴 한데..

Screen[0] 으로 접근 가능한 순서가 아니게 되니 어떻게 해야 하려나..

 

원론적으로는

Screen.AllScreen[0].DeviceName 에 접근해서 다 잘라내고 숫자만 빼내 -1을 해주면 될 것 같긴한데..

 

일단 현재 모니터 순서

Screen.AllScreens 에서는 아래의 순서로 출력된다.

0 - 가장 오른쪽 (1920,0)

1 - 가장 왼쪽 (-1920,0)

2 - 중앙 (0,0)

 

private void Form1_Load ( object sender, EventArgs e )
{
    var parent = new FlowLayoutPanel() { Dock = DockStyle.Fill };            
    Controls.Add(parent);

    //Order by how they are laid out to the user
    var screens = Screen.AllScreens.OrderBy(s => s.WorkingArea.X).ToArray();

    foreach (var screen in screens)
    {
        var panel = new Panel() { Width = screen.Bounds.Width / 10, Height = screen.Bounds.Height / 10 };
        panel.BackColor = screen.Primary ? Color.Blue : Color.Silver;
                                
        panel.Controls.Add(new Label() { Text = screen.DeviceName });

        parent.Controls.Add(panel);
    };
}

[링크 : https://social.msdn.microsoft.com/Forums/en-US/048586a5-e04b-40d8-a2d6-4c903fbf9b1b/...]

[링크 : https://docs.microsoft.com/ko-kr/dotnet/api/system.windows.forms.screen?view=netcore-3.1]

Posted by 구차니
Programming/c# & winform2020. 10. 26. 12:38

핵심(?)은 this.Controls.Add(ctrl);

 

[링크 : http://csharp.net-informations.com/gui/dynamic-controls-cs.htm]

[링크 : https://docs.microsoft.com/ko-kr/troubleshoot/dotnet/csharp/add-controls-to-windows-forms]

Posted by 구차니
Programming/c# & winform2020. 10. 23. 19:09

+

2020.11.13

컨트롤 추가를 투명하게 하려는 컨트롤에 해주어야 한다.

그리고 좌표는 부모(?) 컨트롤에 상대적으로 적용된다.

 

pictureBox7.Controls.Add(pictureBox8); << 이 부분이 핵심이고

pictureBox8.Location = Point(0,0); << 이 부분이 두번째 핵심이다.

public Form1()
{
    InitializeComponent();
    pictureBox7.Controls.Add(pictureBox8);
    pictureBox8.Location = new Point(0, 0);
    pictureBox8.BackColor = Color.Transparent;
}

 

[링크 : https://stackoverflow.com/questions/19910172/how-to-make-picturebox-transparent]

---

 

[링크 : https://stackoverflow.com/questions/36099017/how-to-make-two-transparent-layer-with-c]

[링크 : https://stackoverflow.com/questions/12138892/picturebox-with-transparent-background]

[링크 : https://stackoverflow.com/questions/4144371/a-picturebox-problem]

 

[링크 : https://social.msdn.microsoft.com/Forums/windows/en-US/ce17105b-2ded-4649-a1b6-c83db4bcde8a/picturebox-transparency?forum=winforms]

[링크 : https://stackoverflow.com/questions/5522337/c-sharp-picturebox-transparent-background-doesnt-seem-to-work]

Posted by 구차니
Programming/c# & winform2020. 10. 23. 16:46

form2.Owner = this;

라고 부모에서 자신을 소유자로 등록하면

하위 폼인 form2 에서 ((Form1)(this.Owner)).parent_variable; 식으로 접근이 가능해진다.

다만 이벤트 핸들러 도 어떻게 영향을 받는지

 

alt-f4를 막아놨더니 부모도 창이 안 닫히는 문제가 발생했다.

 

 

[링크 : https://idgaf.tistory.com/3]

Posted by 구차니