반응형

* C# 노트북 배터리 정보 예제...

 

Main

 

- 사용한 컨트롤 : Button 2개, TextBox 2개, Label 3개, 프로그래스바 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_노트북전원상태
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

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

            timer1.Interval = 1000; //1초 마다...

        }

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

            timer1.Stop();
        }

        
        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Start();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            timer1.Stop();
        }


        private void timer1_Tick(object sender, EventArgs e)
        {
            PowerStatus  psStatus = SystemInformation.PowerStatus;

            //충전 상태
            txtChargeStatus.Text = psStatus.BatteryChargeStatus.ToString();

            //전원 상태
            txtPoerStatus.Text = psStatus.PowerLineStatus.ToString();

            //충전 비율
            if (psStatus.BatteryLifePercent != 255)
            {
                pbCharge.Value = (int)(psStatus.BatteryLifePercent * 100);
            }
            else
            {
                pbCharge.Value = 0;
            }

            //잔여 사용 시간
            if (psStatus.BatteryLifeRemaining != -1)
            {
                textBox1.Text = TimeSpan.FromSeconds(psStatus.BatteryLifeRemaining).ToString();
            }
            else
            {
                textBox1.Text = "-------";
            }
            //완충시 사용 시간
            if (psStatus.BatteryFullLifetime != -1)
            {
                textBox2.Text = psStatus.BatteryFullLifetime.ToString();
            }
            else
            {
                textBox2.Text = "-------";
            }


        }
    }
}

 

 

*예제 결과

 

반응형
반응형

* VBNET WMI 를 이용한 그래픽 카드 정보 예제...

- WMI 를 사용하기 위해 참조 -> System.Management dll 을 추가 -> 소스 코드 Imports System.Management

 

Main

 

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

 

전체 소스 코드

Form1.vb

 

Imports System.Management

Public Class Form1

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
        '조회...
        Using mos As ManagementObjectSearcher = New ManagementObjectSearcher("Select * From Win32_DisplayConfiguration")
            '그래픽 카드 정보 얻기...
            For Each moj As ManagementObject In mos.Get()
                label1.Text = moj("Description").ToString()
            Next

        End Using

    End Sub
End Class

 

* 예제 결과

 

 

버튼 클릭 시 위와 같이 그래픽카드 정보를 얻어 올 수 있습니다.

아래 마이크로소프트 문서를 참조 하시면 Win32_DisplayConfiguration 테이블에 필드들이 무엇이 있는지 알 수 있습니다.

docs.microsoft.com/en-us/previous-versions/aa394137(v=vs.85)

 

Win32_DisplayConfiguration class (Windows)

Win32_DisplayConfiguration class 09/17/2015 3 minutes to read In this article --> [The Win32_DisplayConfiguration WMI class is no longer available for use as of Windows Server 2008. Instead, use the properties in the Win32_VideoController, Win32_DesktopMo

docs.microsoft.com

 

반응형
반응형

* C# WMI 를 이용한 그래픽 카드 정보 예제...

- WMI 를 사용하기 위해 참조 -> System.Management dll 을 추가 -> 소스 코드 using System.Management

 

Main

 

- 사용한 컨트롤 : Button 1개, Label 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.Management;

namespace CSharp_WMI_그래픽카드정보
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //조회...
            using (ManagementObjectSearcher mos = new ManagementObjectSearcher("Select * From Win32_DisplayConfiguration"))
            {
                //그래픽 카드 정보 얻기...
                foreach (ManagementObject moj in mos.Get())
                {
                    label1.Text = moj["Description"].ToString();
                }
            }
        }
    }
}

 

* 예제 결과

 

 

버튼 클릭 시 위와 같이 그래픽카드 정보를 얻어 올 수 있습니다.

아래 마이크로소프트 문서를 참조 하시면 Win32_DisplayConfiguration 테이블에 필드들이 무엇이 있는지 알 수 있습니다.

docs.microsoft.com/en-us/previous-versions/aa394137(v=vs.85)

 

Win32_DisplayConfiguration class (Windows)

Win32_DisplayConfiguration class 09/17/2015 3 minutes to read In this article --> [The Win32_DisplayConfiguration WMI class is no longer available for use as of Windows Server 2008. Instead, use the properties in the Win32_VideoController, Win32_DesktopMo

docs.microsoft.com

 

반응형
반응형

* VBNET richTextBox 내용 - 문자열 검색

 

메인화면

 

- 사용한 컨트롤: Panel 3개, Label 1개, TextBox 1개, Button 1개, richTextBox 1개

 

전체 소스 코드

Form1.vb

 

Public Class Form1

    Dim iFindStartIndex As Integer = 0

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
        '찾는 문자열 길이
        Dim iFindLength As Integer = textBox1.Text.Length
        iFindStartIndex = FindMyText(textBox1.Text, iFindStartIndex, richTextBox1.Text.Length)
        If iFindStartIndex = -1 Then
            iFindStartIndex = 0
            Return
        End If

        '찾은 문자열 선택해서 붉은색으로 바꾸기
        richTextBox1.SelectionColor = Color.Red
        richTextBox1.Select(iFindStartIndex, iFindLength)

        '다음 찾기를 위해 찾은 문자열 위치 저장
        iFindStartIndex += iFindLength
    End Sub

    Private Function FindMyText(ByVal strSearchText As String, _
                                ByVal iSearchStart As Integer, _
                                ByVal iSearchEnd As Integer) As Integer

        ' Initialize the return value to false by default.
        Dim ReturnValue As Integer = -1

        ' Ensure that a search string and a valid starting point are specified.
        If strSearchText.Length > 0 And iSearchStart >= 0 Then
            ' Ensure that a valid ending value is provided.
            If iSearchEnd > iSearchStart Or iSearchEnd = -1 Then
                ' Obtain the location of the search string in richTextBox1.
                Dim indexToText As Integer = richTextBox1.Find(strSearchText, iSearchStart, iSearchStart, RichTextBoxFinds.MatchCase)
                ' Determine whether the text was found in richTextBox1.
                If indexToText >= 0 Then
                    ' Return the index to the specified search text.
                    ReturnValue = indexToText
                End If
            End If
        End If

        Return ReturnValue

    End Function

End Class

마이크로 소프트 msdn 참조로 richTextBox 내용에 원하는 문자열 검색 구현

 

* 예제 결과

 

 

richTextBox1.SelectionColor = Color.Red; 

richTextBox1.Select(iFindStartIndex, iFindLength);

예제 결과 보듯이 찾은 문자열을 붉은색으로 바꿔 표시 됩니다.


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

 

[C#] [Control] richTextBox - 문자열 검색

* C# richTextBox 내용 - 문자열 검색 - 사용한 컨트롤: Panel 3개, Label 1개, TextBox 1개, Button 1개, richTextBox 1개 전체 소스 코드 Form1.cs using System; using System.Collections.Generic; using Sys..

kdsoft-zeros.tistory.com

 

반응형
반응형

* C# richTextBox 내용 - 문자열 검색

 

메인화면

 

- 사용한 컨트롤: Panel 3개, Label 1개, TextBox 1개, Button 1개, richTextBox 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_TextBoxSearch
{
    public partial class Form1 : Form
    {
        int iFindStartIndex = 0;

        public Form1()
        {
            InitializeComponent();
        }

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


            richTextBox1.Text = @"private void button1_Click(object sender, EventArgs e)
                                    {
                                        //찾는 문자열 길이
                                        int iFindStartIndex = 0;
                                        int iFindLength = textBox1.Text.Length;
                                        iFindStartIndex = FindMyText(textBox1.Text, iFindStartIndex, richTextBox1.Text.Length);
                                        if (iFindStartIndex == -1)
                                        {
                                            iFindStartIndex = 0;
                                            return;
                                        }
                                        
                                        richTextBox1.SelectionColor = Color.Red;
                                        richTextBox1.Select(iFindStartIndex, iFindLength);
                                        iFindStartIndex += iFindLength;
                                    }

                                    private int FindMyText(string searchText, int searchStart, int searchEnd)
                                    {
                                        // Initialize the return value to false by default.
                                        int returnValue = -1;

                                        // Ensure that a search string and a valid starting point are specified.
                                        if (searchText.Length > 0 && searchStart >= 0)
                                        {
                                            // Ensure that a valid ending value is provided.
                                            if (searchEnd > searchStart || searchEnd == -1)
                                            {
                                                // Obtain the location of the search string in richTextBox1.
                                                int indexToText = richTextBox1.Find(searchText, searchStart, searchEnd, RichTextBoxFinds.MatchCase);
                                                // Determine whether the text was found in richTextBox1.
                                                if (indexToText >= 0)
                                                {
                                                    // Return the index to the specified search text.
                                                    returnValue = indexToText;
                                                }
                                            }
                                        }

                                        return returnValue;
                                    }";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //찾는 문자열 길이
            int iFindLength = textBox1.Text.Length;
            iFindStartIndex = FindMyText(textBox1.Text, iFindStartIndex, richTextBox1.Text.Length);
            if (iFindStartIndex == -1)
            {
                iFindStartIndex = 0;
                return;
            }
            
            //찾은 문자열 선택해서 붉은색으로 바꾸기
            richTextBox1.SelectionColor = Color.Red;
            richTextBox1.Select(iFindStartIndex, iFindLength);

            //다음 찾기를 위해 찾은 문자열 위치 저장
            iFindStartIndex += iFindLength;
        }

        private int FindMyText(string searchText, int searchStart, int searchEnd)
        {
            // Initialize the return value to false by default.
            int returnValue = -1;

            // Ensure that a search string and a valid starting point are specified.
            if (searchText.Length > 0 && searchStart >= 0)
            {
                // Ensure that a valid ending value is provided.
                if (searchEnd > searchStart || searchEnd == -1)
                {
                    // Obtain the location of the search string in richTextBox1.
                    int indexToText = richTextBox1.Find(searchText, searchStart, searchEnd, RichTextBoxFinds.MatchCase);
                    // Determine whether the text was found in richTextBox1.
                    if (indexToText >= 0)
                    {
                        // Return the index to the specified search text.
                        returnValue = indexToText;
                    }
                }
            }

            return returnValue;
        }
    }
}

 

 

마이크로 소프트 msdn 참조로 richTextBox 내용에 원하는 문자열 검색 구현

 

* 예제 결과

 

 

richTextBox1.SelectionColor = Color.Red; 

richTextBox1.Select(iFindStartIndex, iFindLength);

예제 결과 보듯이 찾은 문자열을 붉은색으로 바꿔 표시 됩니다.

 

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

 

[VBNET] [Control] richTextBox - 문자열 검색

* VBNET richTextBox 내용 - 문자열 검색 메인화면 - 사용한 컨트롤: Panel 3개, Label 1개, TextBox 1개, Button 1개, richTextBox 1개 전체 소스 코드 Form1.vb Public Class Form1 Dim iFindStartIndex As Int..

kdsoft-zeros.tistory.com

 

반응형
반응형

* VBNET Listview 조회 데이터 CSV 파일로 저장 하기 예제...

 

Main

 

 

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

 

전체 소스 코드

Form1.vb

 

Public Class Form1

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

        Dim iCount As Integer
        For iCount = 0 To 10 - 1 Step iCount + 1
            Dim lvi As ListViewItem = New ListViewItem()
            lvi.Text = (iCount + 1).ToString()
            lvi.SubItems.Add("Col1")
            lvi.SubItems.Add("Col2")
            lvi.SubItems.Add("Col3")
            lvi.SubItems.Add("Col4")

            listView1.Items.Add(lvi)

        Next

    End Sub

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
        'CSV File Save

        Dim sfd As SaveFileDialog = New SaveFileDialog()

        sfd.Filter = "CSV File(*.csv) | *.csv"

        If sfd.ShowDialog() = DialogResult.OK Then
            Dim sw As System.IO.StreamWriter = New System.IO.StreamWriter(sfd.FileName, False, System.Text.Encoding.GetEncoding(949))

            '데이터    
            Dim i As Integer
            For i = 0 To listView1.Items.Count - 1 Step i + 1
                Dim strTmp As String = ""
                strTmp += listView1.Items(i).SubItems(0).Text + "," + _
                          listView1.Items(i).SubItems(1).Text + "," + _
                          listView1.Items(i).SubItems(2).Text + "," + _
                          listView1.Items(i).SubItems(3).Text + "," + _
                          listView1.Items(i).SubItems(4).Text

                sw.Write(strTmp + "\r\n")

            Next

            sw.Flush()
            sw.Close()

            MessageBox.Show("CSV 파일로 저장이 완료 되었습니다.")

        End If


    End Sub
End Class

 


*예제 결과

 

 

 

 

 

 

반응형
반응형

* C# Listview 조회 데이터 CSV 파일로 저장 하기 예제...

 

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_CSV
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();


            for (int iCount = 0; iCount < 10; iCount++)
            {
                ListViewItem lvi = new ListViewItem();
                lvi.Text = (iCount + 1).ToString();
                lvi.SubItems.Add("Col1");
                lvi.SubItems.Add("Col2");
                lvi.SubItems.Add("Col3");
                lvi.SubItems.Add("Col4");

                listView1.Items.Add(lvi);

            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //CSV File Save

            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter = "CSV File(*.csv) | *.csv";

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                System.IO.StreamWriter sw = new System.IO.StreamWriter(sfd.FileName, false, Encoding.GetEncoding(949));

                //데이터    
                for (int i = 0; i < listView1.Items .Count; i++)
                {
                    string strTmp = "";
                    strTmp += listView1.Items[i].SubItems[0].Text + "," +
                              listView1.Items[i].SubItems[1].Text + "," +
                              listView1.Items[i].SubItems[2].Text + "," +
                              listView1.Items[i].SubItems[3].Text + "," +
                              listView1.Items[i].SubItems[4].Text;

                    sw.Write(strTmp + "\r\n");
                    
                }

                sw.Flush();
                sw.Close();

				MessageBox.Show("CSV 파일로 저장이 완료 되었습니다.");
            }

            
        }
    }
}

 

 

*예제 결과

 

 

 

반응형
반응형

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

 

Main

 

 

-사용한 컨트롤 : Button 1개

 

전체 소스 코드

Form1.vb

 

Imports System.Runtime.InteropServices

Public Class Form1

    <DllImport("user32.dll")> Private Shared Function SetWindowDisplayAffinity(ByVal hWnd As IntPtr, _
                                                                               ByVal dwAffinity As UInteger) As <MarshalAs(UnmanagedType.Bool)> Boolean
    End Function

    Private Const ui_NONE As UInteger = &H0
    Private Const ui_SET As UInteger = &H1

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

        If button1.Text = "캡처 방지 설정하기" Then

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

        Else

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

        End If

    End Sub
End Class

 

 

*예제 결과

 

- 해지 했을 경우

- 설정 했을 경우

 



반응형

+ Recent posts