반응형

* C# API 를 이용한 화면 캡쳐 방지 (Screen Capture Prevention) 예제...

 

Main

 

-사용한 컨트롤 : Button 1개

 

전체 소스 코드

Form1.cs

 

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

using System.Runtime.InteropServices;

namespace CSharp_화면캡쳐방지
{
    public partial class Form1 : Form
    {
        [DllImport("user32.dll")]
        private static extern uint SetWindowDisplayAffinity(IntPtr windowHandle, uint affinity);
        private const uint ui_NONE = 0;
        private const uint ui_SET = 1;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (this.button1.Text == "캡처 방지 설정하기")
            {

                SetWindowDisplayAffinity(this.Handle, ui_SET);
                this.button1.Text = "캡처 방지 해제하기";

            }
            else
            {

                SetWindowDisplayAffinity(this.Handle, ui_NONE);
                button1.Text = "캡처 방지 설정하기";

            }
        }
    }
}

 

 

*예제 결과

 

- 해지 했을 경우

- 설정 했을 경우

 

 

반응형
반응형

* VBNET Listview 데이터 조회 BeginUpdate , EndUpdate 예제

 

Main

 

 

-사용한 컨트롤: Button 2개, Listview 1개

 

전체 소스 코드

Form1.vb

 

Public Class Form1

    Dim dtStart As DateTime

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
        'Listview Search
        listView1.Items.Clear()

        dtStart = DateTime.Now

        Dim i As Integer
        For i = 0 To 30000 - 1 Step i + 1
            Dim lvi As ListViewItem = New ListViewItem()
            lvi.Text = (i + 1).ToString()
            lvi.SubItems.Add("TEST " + (i + 1).ToString())
            listView1.Items.Add(lvi)
        Next

        MessageBox.Show(After_Time(DateTime.Now, dtStart).ToString() + " 초")
    End Sub

    Private Sub button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button2.Click
        'ListView Search Begin End Update
        listView1.Items.Clear()

        dtStart = DateTime.Now

        listView1.BeginUpdate()
        Dim i As Integer
        For i = 0 To 30000 - 1 Step i + 1
            Dim lvi As ListViewItem = New ListViewItem()
            lvi.Text = (i + 1).ToString()
            lvi.SubItems.Add("TEST " + (i + 1).ToString())
            listView1.Items.Add(lvi)
        Next
        listView1.EndUpdate()

        MessageBox.Show(After_Time(DateTime.Now, dtStart).ToString() + " 초")
    End Sub

    Private Function After_Time(ByVal dtNow As DateTime, ByVal dtBefore As DateTime) As Double
        Dim ts As TimeSpan = dtNow - dtBefore
        Return ts.TotalSeconds
    End Function

End Class

 

 

*예제 결과

 

- Begin End 사용하기 전

 

- Begin End 사용 후




반응형
반응형

* C# Listview 데이터 조회 BeginUpdate , EndUpdate 예제

 

Main

 

-사용한 컨트롤: Button 2개, Listview 1개

 

전체 소스 코드

Form1.cs

 

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

namespace CSharp_Listview_begin_end
{
    public partial class Form1 : Form
    {
        DateTime dtStart;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //ListView Search
            listView1.Items.Clear();

            dtStart = DateTime.Now;

            for (int i = 0; i < 30000; i++)
            {
                ListViewItem lvi = new ListViewItem();
                lvi.Text = (i + 1).ToString();
                lvi.SubItems.Add("TEST " + (i + 1).ToString());
                listView1.Items.Add(lvi);
            }

            MessageBox.Show(After_Time(DateTime.Now, dtStart).ToString() + " 초");

        }

        private void button2_Click(object sender, EventArgs e)
        {
            //ListView Search Begin End Update
            listView1.Items.Clear();

            dtStart = DateTime.Now;

            listView1.BeginUpdate();
            for (int i = 0; i < 30000; i++)
            {
                ListViewItem lvi = new ListViewItem();
                lvi.Text = (i + 1).ToString();
                lvi.SubItems.Add("TEST " + (i + 1).ToString());
                listView1.Items.Add(lvi);
            }
            listView1.EndUpdate();

            MessageBox.Show(After_Time(DateTime.Now, dtStart).ToString() + " 초");

        }
        private double After_Time(DateTime dtNow, DateTime dtBefore) 
        { 
            TimeSpan ts = dtNow - dtBefore; 
            return ts.TotalSeconds; 
        }

    }
}

 

 

*예제 결과

 

- Begin End 사용하기 전

- Begin End 사용 후

반응형
반응형

* VBNET 움직이는 라벨 만들기 예제...

 

Main

 

 

-사용한 컨트롤 : Label 1 개, Panel 1개, Timer 1개

 

전체 소스 코드

Form1.vb

 

Public Class Form1

    Dim iLocationX As Integer = 1
    Dim iLocationY As Integer = 0
    Dim bCheck As Boolean = True

    Dim iSpeed As Integer = 5
    Dim iOffset As Integer = 10

    Public Sub New()

        ' 이 호출은 Windows Form 디자이너에 필요합니다.
        InitializeComponent()

        ' InitializeComponent() 호출 뒤에 초기화 코드를 추가하십시오.

        '라벨 Location Y 지정
        iLocationY = (panel1.Height - panel1.Location.Y) / 2
        Dim p As Point = New Point(iLocationX, iLocationY)
        label1.Location = p

    End Sub

    Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
        MyBase.OnLoad(e)
        timer1.Start()
    End Sub

    Protected Overrides Sub OnClosed(ByVal e As System.EventArgs)
        MyBase.OnClosed(e)
        timer1.Stop()
    End Sub

    Private Sub timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timer1.Tick
        '앞으로
        If bCheck Then
            Dim iMove As Integer = iLocationX + label1.Width + iOffset
            Dim iEnd As Integer = panel1.Width

            If iMove <= iEnd Then
                iLocationX += iSpeed
                Dim p As Point = New Point(iLocationX, iLocationY)
                label1.Location = p
            Else '끝지점에 도달 했으면...
                bCheck = False
            End If

        Else '뒤로
            '처음으로 다시 왔으면...
            If iLocationX <= panel1.Location.X Then
                bCheck = True

            Else
                iLocationX -= iSpeed
                Dim p As Point = New Point(iLocationX, iLocationY)
                label1.Location = p
            End If
        End If
    End Sub
End Class

 


*예제 결과

 



반응형
반응형

* C# 움직이는 라벨 만들기 예제...

 

Main

 

-사용한 컨트롤 : Label 1 개, Panel 1개, Timer 1개

 

전체 소스 코드

Form1.cs

 

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

namespace CSharp_MoveLabel
{
    public partial class Form1 : Form
    {
        int iLocationX = 1;
        int iLocationY = 0;
        bool bCheck = true;      //true 앞으로 false 뒤로

        int iSpeed = 5;
        int iOffset = 10;

        public Form1()
        {
            InitializeComponent();

            iLocationY = (panel1.Height - panel1.Location.Y) / 2;
            Point p = new Point(iLocationX, iLocationY);
            label1.Location = p;

        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            timer1.Start();

        }

        protected override void OnClosed(EventArgs e)
        {
            base.OnClosed(e);

            timer1.Stop();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            //앞으로
            if (bCheck)
            {
                int iMove = iLocationX + label1.Width + iOffset ;
                int iEnd = panel1.Width ;

                if (iMove <= iEnd)
                {
                    iLocationX += iSpeed;
                    Point p = new Point(iLocationX, iLocationY);
                    label1.Location = p;
                }
                //끝지점에 도달 했으면...
                else
                {
                    bCheck = false;
                }

            }
            //뒤로
            else
            {
                //처음으로 다시 왔으면...
                if (iLocationX <= panel1.Location.X )
                {
                    bCheck = true;
                }
                else
                {
                    iLocationX -= iSpeed;
                    Point p = new Point(iLocationX, iLocationY);
                    label1.Location = p;
                }
            }
           
        }
    }
}

 

 

*예제 결과

 

 

반응형
반응형

* VBNET Listview 에 Button, Progressbar, TextBox Control 삽입 예제...

 

Main

 

 

-사용한 컨트롤 : Button 1개, Listview 1개

 

전체 소스 코드

Form1.vb

 

Public Class Form1

    Dim ltControl As List(Of Control) = New List(Of Control)

    Sub ControlDispose()
        Dim iCount As Integer
        For iCount = 0 To ltControl.Count - 1 Step iCount + 1
            ltControl(iCount).Dispose()
        Next

        If ltControl.Count > 0 Then
            ltControl.Clear()
        End If
    End Sub


    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
        lvMain.Groups.Clear()
        lvMain.Items.Clear()

        ControlDispose()

        Dim lvi As ListViewItem = New ListViewItem()

        lvi.Text = "000"
        lvi.SubItems.Add("111")
        lvi.SubItems.Add("222")
        lvi.SubItems.Add("333")

        lvMain.Items.Add(lvi)

        '객체를 어디에 담았다가 Dispose() 해주기...
        'Control In 할 객체 만들기...
        Dim pb As ProgressBar = New ProgressBar()
        pb.Minimum = 0
        pb.Maximum = 100
        pb.Value = 50
        pb.Parent = lvMain
        '서브 아이템 얻어오기
        Dim ps As ListViewItem.ListViewSubItem = Nothing
        ps = lvMain.Items(0).SubItems(0)
        '그리기
        Dim rt As Rectangle = New Rectangle()
        rt = ps.Bounds
        pb.SetBounds(rt.X, rt.Y, 100, rt.Height)

        ltControl.Add(pb)

        Dim bt As Button = New Button()
        bt.Text = "In Button1"
        AddHandler bt.Click, AddressOf bt_Click
        bt.Parent = lvMain
        '서브 아이템 얻어오기
        Dim ps2 As ListViewItem.ListViewSubItem = Nothing
        ps2 = lvMain.Items(0).SubItems(1)
        '그리기
        Dim rt2 As Rectangle = New Rectangle()
        rt2 = ps2.Bounds
        bt.SetBounds(rt2.X, rt2.Y, rt2.Width, rt2.Height + 6)

        ltControl.Add(bt)

        Dim bt2 As Button = New Button()
        bt2.Text = "In Button2"
        AddHandler bt2.Click, AddressOf bt_Click
        bt2.Parent = lvMain
        '서브 아이템 얻어오기
        Dim ps3 As ListViewItem.ListViewSubItem = Nothing
        ps3 = lvMain.Items(0).SubItems(2)
        '그리기
        Dim rt3 As Rectangle = New Rectangle()
        rt3 = ps3.Bounds
        bt2.SetBounds(rt3.X, rt3.Y, rt3.Width, rt3.Height + 6)

        ltControl.Add(bt2)

        Dim tb As TextBox = New TextBox()
        tb.Text = "In TextBox"
        tb.Parent = lvMain
        '서브 아이템 얻어오기
        Dim ps4 As ListViewItem.ListViewSubItem = Nothing
        ps4 = lvMain.Items(0).SubItems(3)
        '그리기
        Dim rt4 As Rectangle = New Rectangle()
        rt4 = ps4.Bounds
        tb.SetBounds(rt4.X, rt4.Y, rt4.Width, rt4.Height)

        ltControl.Add(tb)

    End Sub

    Sub bt_Click(ByVal s As Object, ByVal e As EventArgs)
        Dim bt As Button = CType(s, Button)
        MessageBox.Show(bt.Text)
    End Sub


End Class

 


*예제 결과

 

 

https://kdsoft-zeros.tistory.com/210

 

[C#] [Control] Listview - Button, Progressbar, TextBox 컨트롤 삽입

* C# Listview 에 Button, Progressbar, TextBox Control 삽입 예제... -사용한 컨트롤 : Button 1개, Listview 1개 전체 소스 코드 Form1.cs using System; using System.Collections.Generic; using System.Com..

kdsoft-zeros.tistory.com

 

반응형
반응형

* C# Listview 에 Button, Progressbar, TextBox Control 삽입 예제...

 

Main

 

-사용한 컨트롤 : Button 1개, Listview 1개

 

전체 소스 코드

Form1.cs

 

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

namespace CSharp_ListView
{
    public partial class Form1 : Form
    {
        //컨트롤 해제 변수...
        List<Control> ltControl = new List<Control>();

        public Form1()
        {
            InitializeComponent();

        }

        void ControlDispose()
        {
            for (int iCount = 0; iCount < ltControl.Count; iCount++)
            {
                ltControl[iCount].Dispose();
            }

            if (ltControl.Count > 0)
            {
                ltControl.Clear();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            lvMain.Groups.Clear();
            lvMain.Items.Clear();

            ControlDispose();

            ListViewItem lvi = new ListViewItem();

            lvi.Text = "000";
            lvi.SubItems.Add("111");
            lvi.SubItems.Add("222");
            lvi.SubItems.Add("333");

            lvMain.Items.Add(lvi);

            //객체를 어디에 담았다가 Dispose() 해주기...
            //Control In 할 객체 만들기...
            ProgressBar pb = new ProgressBar();
            pb.Minimum = 0;
            pb.Maximum = 100;
            pb.Value = 50;
            pb.Parent = lvMain;
            //서브 아이템 얻어오기
            ListViewItem.ListViewSubItem ps = null;
            ps = lvMain.Items[0].SubItems[0];
            //그리기
            Rectangle rt = new Rectangle();
            rt = ps.Bounds;
            pb.SetBounds(rt.X, rt.Y, 100, rt.Height);

            ltControl.Add(pb);

            Button bt = new Button();
            bt.Text = "In Button1";
            bt.Click += new EventHandler(bt_Click);
            bt.Parent = lvMain;
            //서브 아이템 얻어오기
            ListViewItem.ListViewSubItem ps2 = null;
            ps2 = lvMain.Items[0].SubItems[1];
            //그리기
            Rectangle rt2 = new Rectangle();
            rt2 = ps2.Bounds;
            bt.SetBounds(rt2.X, rt2.Y, rt2.Width, rt2.Height+6);

            ltControl.Add(bt);

            Button bt2 = new Button();
            bt2.Text = "In Button2";
            bt2.Click += new EventHandler(bt_Click);
            bt2.Parent = lvMain;
            //서브 아이템 얻어오기
            ListViewItem.ListViewSubItem ps3 = null;
            ps3 = lvMain.Items[0].SubItems[2];
            //그리기
            Rectangle rt3 = new Rectangle();
            rt3 = ps3.Bounds;
            bt2.SetBounds(rt3.X, rt3.Y, rt3.Width, rt3.Height+6);

            ltControl.Add(bt2);

            TextBox tb = new TextBox();
            tb.Text = "In TextBox";
            tb.Parent = lvMain;
            //서브 아이템 얻어오기
            ListViewItem.ListViewSubItem ps4 = null;
            ps4 = lvMain.Items[0].SubItems[3];
            //그리기
            Rectangle rt4 = new Rectangle();
            rt4 = ps4.Bounds;
            tb.SetBounds(rt4.X, rt4.Y, rt4.Width, rt4.Height);

            ltControl.Add(tb);

        }

        void bt_Click(object s, EventArgs e)
        {
            Button bt = s as Button;
            MessageBox.Show(bt.Text);
        }

    }
}

 

 

*예제 결과

 

 

 

https://kdsoft-zeros.tistory.com/211

 

[VBNET] [Control] Listview - Button, Progressbar, TextBox 컨트롤 삽입

* VBNET Listview 에 Button, Progressbar, TextBox Control 삽입 예제... -사용한 컨트롤 : Button 1개, Listview 1개 전체 소스 코드 Form1.vb Public Class Form1 Dim ltControl As List(Of Control) = New Li..

kdsoft-zeros.tistory.com

 

반응형
반응형

* VBNET Listview 컨트롤에 그룹화 항목 만들기 예제...

 

Main

 

 

- 사용한 컨트롤 : Button 1개 , Listview 1개

  Listview 에 Columns -> col item 4개를 추가 해 줍니다.

 

전체 소스 코드

Form1.vb

 

Public Class Form1

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
        lvMain.Groups.Clear()
        lvMain.Items.Clear()

        Dim lg As ListViewGroup = New ListViewGroup("Group1")
        Dim lg2 As ListViewGroup = New ListViewGroup("Group2")
        lvMain.Groups.Add(lg)
        lvMain.Groups.Add(lg2)


        Dim lvi As ListViewItem = New ListViewItem()

        lvi.Text = "Group1 TEST"
        lvi.SubItems.Add("ddd")
        lvi.SubItems.Add("asdfaf")
        lvi.SubItems.Add("sdaffasf")


        Dim lvi2 As ListViewItem = New ListViewItem()

        lvi2.Text = "Group2 TEST"
        lvi2.SubItems.Add("ddd")
        lvi2.SubItems.Add("asdfaf")
        lvi2.SubItems.Add("sdaffasf")

        '먼저 아이템을 넣고
        lvMain.Items.Add(lvi)
        lvMain.Items.Add(lvi2)

        '그 아이템을 그룹화 함...
        lvMain.Groups(0).Items.Add(lvi)
        lvMain.Groups(1).Items.Add(lvi2)
    End Sub

End Class

 

 

*예제 결과

 

 

반응형

+ Recent posts