반응형

* 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

 

반응형
반응형

* 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

 

 

*예제 결과

 

 

반응형
반응형

* C# EXE File icon 가져오기 예제...

 

Main

 

 

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

 

전체 소스 코드

Form1.vb

 

Public Class Form1

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
        'File Open
        Dim ofd As OpenFileDialog = New OpenFileDialog()

        ofd.Filter = "EXE File(*.exe) | *.exe"

        If ofd.ShowDialog() = DialogResult.OK Then

            label1.Text = ofd.FileName

        End If


    End Sub

    Private Sub button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button2.Click
        'Icon Save
        '파일이 아니라면
        If Not System.IO.File.Exists(label1.Text) Then Return

        'exe file icon get
        Dim icn As Icon = Icon.ExtractAssociatedIcon(label1.Text)
        Dim img As Image = Image.FromHbitmap(icn.ToBitmap().GetHbitmap())
        img.Save("C:\TEST.ico")
        MessageBox.Show("icon Image Save Success...")

    End Sub

End Class

 

 

*예제 결과

 

 

 




반응형
반응형

*C# App.Configuration 파일 추가 방법 및 파일 추가 후 key , value 값 읽기 예제...

 

Main

 

 

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

 

 

- App.Configuration 파일 추가

 

 

- 아래의 그림과 같이 key 값 및 value 값 작성 후 저장

 

전체 소스 코드

Form1.vb

 

- App.Configuration 을 읽기 위해 System.Configuration 을 추가 해 줍니다.



Imports System.Configuration

Public Class Form1

    Dim ltKey As List(Of String) = New List(Of String)

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

        'Key 값 추가...
        ltKey.Add("TEST")
        ltKey.Add("TEST2")

    End Sub

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

        For Each Str As String In ltKey

            Dim lvi As ListViewItem = New ListViewItem()

            lvi.Text = Str
            lvi.SubItems.Add(ConfigurationSettings.AppSettings(Str).ToString())

            listView1.Items.Add(lvi)

        Next

    End Sub

End Class

 

*예제 결과

 

 

반응형
반응형

* VBNET Regex 를 이용한 간단한 이메일 주소 체크 예제...

 

Main

 

 

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

 

전체 소스 코드

Form1.vb

 


Imports System.Text.RegularExpressions

Public Class Form1

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

        Dim bEmail As Boolean = Regex.IsMatch(textBox1.Text, "[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?")

        If bEmail Then
            label1.Text = "이메일 주소가 맞습니다."
        Else
            label1.Text = "이메일 주소가 아닙니다."
        End If

    End Sub

End Class

 

 

* 예제 결과

 

 

 

반응형
반응형

* VBNET String 을 이진수로 이진수를 String 으로 변환 예제...

 

 

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

 

전체 소스 코드

Form1.vb

 

Imports System.Text

Public Class Form1

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
        'String To 2진수
        If textBox1.Text = "" Then
            Return
        End If
        'String To 2진수
        Dim btBytes() As Byte = UnicodeEncoding.Unicode.GetBytes(textBox1.Text)
        Dim strbinary As String = String.Empty

        Dim b As Byte
        For Each b In btBytes
            ' byte를 2진수 문자열로 변경
            Dim strTmp As String = Convert.ToString(b, 2)
            strbinary += strTmp.PadLeft(8, "0"c)
        Next

        label1.Text = strbinary
    End Sub

    Private Sub button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button2.Click
        '2진수 To String
        If label1.Text = "" Then
            Return
        End If

        Dim ibytes As Integer = label1.Text.Length / 8
        Dim btOutBytes() As Byte = New Byte(ibytes) {}

        Dim i As Integer
        For i = 0 To ibytes - 1
            ' 8자리 숫자 즉 1바이트 문자열 얻기
            Dim strBin As String = label1.Text.Substring(i * 8, 8)
            ' 2진수 문자열을 숫자로 변경
            btOutBytes(i) = CType(Convert.ToInt32(strBin, 2), Byte)
        Next

        ' Unicode 인코딩으로 바이트를 문자열로
        Dim strResult As String = UnicodeEncoding.Unicode.GetString(btOutBytes)
        label2.Text = strResult.Substring(0, strResult.Length - 1)

    End Sub
End Class

 

 

* 예제 결과

 

 

반응형
반응형

* VBNET Encoding Class 를 이용한 유니코드(한글) 문자열 존재 여부 예제...

 

Main

 

 

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

 

전체 소스 코드

Form1.vb

 


Public Class Form1

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
        If textBox1.Text = "" Then
            Return
        End If

        Dim iAscii As Integer = System.Text.Encoding.ASCII.GetByteCount(textBox1.Text)
        Dim iUnicode As Integer = System.Text.Encoding.UTF8.GetByteCount(textBox1.Text)

        '같지 않으면...
        If iAscii <> iUnicode Then
            label1.Text = "Unicode 가 존재 합니다."
        Else
            label1.Text = "Unicode 가 존재 하지 않습니다."
        End If
    End Sub

End Class

 

 

*예제 결과

 

 

 

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

 

[C#] Encoding Class - 유니코드 문자열 존재 여부

* C# Encoding Class 를 이용한 유니코드(한글) 문자열 존재 여부 예제... - 사용한 컨트롤 : Button 1개, TextBox 1개, Label 1개 전체 소스 코드 Form1.cs using System; using System.Collections.Generic; us..

kdsoft-zeros.tistory.com

 

반응형
반응형

 

* VBNET API 를 이용한 Form 생성 시 효과 나타 내기

 

 

Public Class Form1
    Declare Function AnimateWindow Lib "user32" (ByVal hwnd As Integer, ByVal dwTime As Integer, ByVal dwFlags As Integer) As Boolean
    Const AW_HOR_POSITIVE = &H1 'Animates the window from left to right. This flag can be used with roll or slide animation.
    Const AW_HOR_NEGATIVE = &H2 'Animates the window from right to left. This flag can be used with roll or slide animation.
    Const AW_VER_POSITIVE = &H4 'Animates the window from top to bottom. This flag can be used with roll or slide animation.
    Const AW_VER_NEGATIVE = &H8 'Animates the window from bottom to top. This flag can be used with roll or slide animation.
    Const AW_CENTER = &H10 'Makes the window appear to collapse inward if AW_HIDE is used or expand outward if the AW_HIDE is not used.
    Const AW_HIDE = &H10000 'Hides the window. By default, the window is shown.
    Const AW_ACTIVATE = &H20000 'Activates the window.
    Const AW_SLIDE = &H40000 'Uses slide animation. By default, roll animation is used.
    Const AW_BLEND = &H80000


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Center
        Dim frm As Form2 = New Form2()
        AnimateWindow(frm.Handle.ToInt32, 1000, AW_CENTER)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        'AW_HOR_POSITIVE
        Dim frm As Form2 = New Form2()
        AnimateWindow(frm.Handle.ToInt32, 1000, AW_HOR_POSITIVE)
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        'AW_VER_POSITIVE
        Dim frm As Form2 = New Form2()
        AnimateWindow(frm.Handle.ToInt32, 1000, AW_VER_POSITIVE)
    End Sub
End Class
반응형

+ Recent posts