반응형

Form 사이즈 고정 방법 1

- Form 속성창에서 FormBorderStyle -> FixedSingle 로 변경

또는 소스상에서 Me.FormBorderStyle = FixedSingle

Form 사이즈 고정 방법 2

- Form 속성창에서 AutoSizeMode -> GrowAndShrink 로 변경

또는 소스상에서 Me.AutoSizeMode = GrowAndShrink 

Form 사이즈 고정 방법 3

- Form Resize 이벤트 를 만들고 Me.Size = new Size(Width, Height) 를 입력



반응형
반응형

     

64bit 운영체제
32bit 운영 체제

 

 

        If IntPtr.Size = 8 Then
            MessageBox.Show("64")
        Else
            MessageBox.Show("32")
        End If

반응형
반응형

* VBNET 폴더 락 설정 및 해제  - 권한 설정 및 해제 예제...

 테스트 환경

 - 윈도우7 64 Bit

 - Visual Studio 2008 닷넷 프레임 워크 3.5


메인화면

 

전체 소스 코드

Form1.vb

 

Public Class Form1

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
        'Folder Open
        Dim fbd As FolderBrowserDialog = New FolderBrowserDialog

        If (fbd.ShowDialog() = Windows.Forms.DialogResult.OK) Then

            label1.Text = fbd.SelectedPath

        End If

    End Sub

    Private Sub button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button3.Click
        'Folder Lock Set
        '선택된 폴더가 존재 하지 않으면...
        If (Not System.IO.Directory.Exists(label1.Text)) Then
            Return
        End If

        Try

            Dim strAdminUserName As String = Environment.UserName
            Dim ds As System.Security.AccessControl.DirectorySecurity = System.IO.Directory.GetAccessControl(label1.Text)
            Dim fsa As System.Security.AccessControl.FileSystemAccessRule = New System.Security.AccessControl.FileSystemAccessRule(strAdminUserName, _
                                                                                                                                   Security.AccessControl.FileSystemRights.FullControl, _
                                                                                                                                   Security.AccessControl.AccessControlType.Deny)
            ds.AddAccessRule(fsa)
            System.IO.Directory.SetAccessControl(label1.Text, ds)

        Catch ex As Exception
            label2.Text = ex.Message.ToString()
        End Try
        label2.Text = "Folder Lock Success..."

    End Sub

    Private Sub button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button2.Click
        'Folder Lock Cancel

        '선택된 폴더가 존재 하지 않으면...
        If (Not System.IO.Directory.Exists(label1.Text)) Then
            Return
        End If

        Try
            Dim strAdminUserName As String = Environment.UserName
            Dim ds As System.Security.AccessControl.DirectorySecurity = System.IO.Directory.GetAccessControl(label1.Text)
            Dim fsa As System.Security.AccessControl.FileSystemAccessRule = New System.Security.AccessControl.FileSystemAccessRule(strAdminUserName, _
                                                                                                                                   Security.AccessControl.FileSystemRights.FullControl, _
                                                                                                                                   Security.AccessControl.AccessControlType.Deny)


            ds.RemoveAccessRule(fsa)
            System.IO.Directory.SetAccessControl(label1.Text, ds)

        Catch ex As Exception
            label2.Text = ex.Message.ToString()
        End Try

        label2.Text = "Folder Lock Cancel..."

    End Sub

End Class

 

* 결과 화면

 

위 그림과 같이 해당 폴더 권한을 설정 하고 접근 하면 권한이 없다고 나오고 해제 하고 접근 하게 되면 해당 폴더에

접근 할 수 있게 됩니다. 



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

 

[C#] 폴더 락 설정 및 해제 (Folder Lock) - 권한 설정 및 해제

* C# 폴더 락 설정 및 해제 - 권한 설정 및 해제 예제... 테스트 환경 - 윈도우7 64 Bit - Visual Studio 2008 닷넷 프레임 워크 3.5 전체 소스 코드 Form1.cs using System; using System.Collections.Generic;..

kdsoft-zeros.tistory.com

 

반응형
반응형

* VBNET 기상청 날씨 (Weather) 정보 가져오기 예제...

 

메인화면

전체 소스 코드

Form1.vb

========================================================================

Public Class Form1

    Dim strURL As String = "http://www.kma.go.kr/weather/forecast/mid-term-xml.jsp"
    Dim strCity As String = ""

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cboCity.SelectedIndex = 10
        lblToday.Text = DateTime.Now.ToString("yyyy-MM-dd")
    End Sub

    Private Sub cboCity_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboCity.SelectedIndexChanged
        Try

            Using xr As Xml.XmlReader = Xml.XmlReader.Create(strURL)

                Dim strMsg As String = ""
                Dim ws As Xml.XmlWriterSettings = New Xml.XmlWriterSettings()
                ws.Indent = True
                Dim bCheck As Boolean = False
                Dim iCount As Integer = 0

                strCity = cboCity.Text

                While (xr.Read())

                    Select Case xr.NodeType
                        Case Xml.XmlNodeType.CDATA
                            '헤더 내용 표시
                            txtMsg.Text = xr.Value.ToString().Replace(", ")
                        Case Xml.XmlNodeType.Element
                        Case Xml.XmlNodeType.Text
                            '선택된 도시이면...
                            If (xr.Value.Equals(strCity)) Then
                                bCheck = True
                            End If

                            If (bCheck) Then
                                Dim dt As DateTime
                                Dim b As Boolean = DateTime.TryParse(xr.Value.ToString(), dt)

                                If b Then
                                    strMsg += "/"
                                End If

                                strMsg += xr.Value + ","
                                iCount += 1
                                If (iCount > 36) Then
                                    bCheck = False
                                End If

                            End If

                        Case Xml.XmlNodeType.XmlDeclaration
                        Case Xml.XmlNodeType.ProcessingInstruction
                        Case Xml.XmlNodeType.Comment
                        Case Xml.XmlNodeType.EndElement
                    End Select

                End While

                '요일별로 짜르기
                Dim strTmp() As String = strMsg.Split("/")

                '요일별 데이터로 나누기
                Dim strWh1() As String = strTmp(1).Split(",")
                label3.Text = strWh1(0)
                label5.Text = "최저: " + strWh1(2) + " ℃"
                label6.Text = "최고: " + strWh1(3) + " ℃"
                label7.Text = strWh1(1)

                Dim strWh2() As String = strTmp(2).Split(",")
                label11.Text = strWh2(0)
                label10.Text = "최저: " + strWh2(2) + " ℃"
                label9.Text = "최고: " + strWh2(3) + " ℃"
                label8.Text = strWh2(1)

                Dim strWh3() As String = strTmp(3).Split(",")
                label15.Text = strWh3(0)
                label14.Text = "최저: " + strWh3(2) + " ℃"
                label13.Text = "최고: " + strWh3(3) + " ℃"
                label12.Text = strWh3(1)

                Dim strWh4() As String = strTmp(4).Split(",")
                label27.Text = strWh4(0)
                label26.Text = "최저: " + strWh4(2) + " ℃"
                label25.Text = "최고: " + strWh4(3) + " ℃"
                label24.Text = strWh4(1)

                Dim strWh5() As String = strTmp(5).Split(",")
                label23.Text = strWh5(0)
                label22.Text = "최저: " + strWh5(2) + " ℃"
                label21.Text = "최고: " + strWh5(3) + " ℃"
                label20.Text = strWh5(1)

                Dim strWh6() As String = strTmp(6).Split(",")
                label19.Text = strWh6(0)
                label18.Text = "최저: " + strWh6(2) + " ℃"
                label17.Text = "최고: " + strWh6(3) + " ℃"
                label16.Text = strWh6(1)

            End Using

        Catch ex As Exception

        End Try
    End Sub

    
End Class

========================================================================

기상청 jsp 내용

 

콤보 박스 내용은 아래의 그림과 같이 속성에서 바로 등록 해 주었으며, ComboBox Index 가 아닌

Text 즉 도시 이름으로 체크 하기에 아이템 순서는 상관이 없습니다.

 

 

*결과 화면

 

 

반응형
반응형

* DateTime Class 를 이용한 현재 선택된 달의 마지막 날짜 및 요일 구하기 예제...

 

메인화면

 

 

전체 소스코드

Form1.vb

 

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'C# 과 같은 DateTime Class 이용
        numYear.Value = DateTime.Now.Year
        numMonth.Value = DateTime.Now.Month

        'VB6 처럼 사용
        'numYear.Value = Date.Now.Year
        'numMonth.Value = Date.Now.Month

    End Sub

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

        '날짜 타입으로 변환 하기...
        Dim dtTmp As DateTime = DateTime.Parse(numYear.Value.ToString() + "-" + numMonth.Value.ToString() + "-01")

        '현재 선택된 달 +1 하기...
        Dim dt As DateTime = dtTmp.AddMonths(1)
        '+1 된 달에서 하루 빼기...
        dt = dt.AddDays(-1)

        label4.Text = "선택된 년월: " + numYear.Value.ToString() + "-" + numMonth.Value.ToString()
        label5.Text = "마지막 일: " + dt.ToString("dd")
        label6.Text = "마지막 요일: " + GetDayOfWeek(dt)


    End Sub


    Private Function GetDayOfWeek(ByVal dt As DateTime) As String

        Dim strDay As String = ""

        Select Case dt.DayOfWeek
            Case DayOfWeek.Monday
                strDay = "월요일"
            Case DayOfWeek.Tuesday
                strDay = "화요일"
            Case DayOfWeek.Wednesday
                strDay = "수요일"
            Case DayOfWeek.Thursday
                strDay = "목요일"
            Case DayOfWeek.Friday
                strDay = "금요일"
            Case DayOfWeek.Saturday
                strDay = "토요일"
            Case DayOfWeek.Sunday
                strDay = "일요일"
        End Select

        Return strDay

    End Function

End Class

 

* 사용자 정의 함수 GetDayOfWeek => 요일 값을 문자열로 변환 하여 리턴 하는 함수

 

* 예제 결과

 

결과화면

 

반응형
반응형

* string 문자열을 정수 및 실수 형으로 변환 하기 예제...

 

메인 화면

전체 소스코드

Form1.vb

 

Public Class Form1

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
        'int 형으로 변환

        Dim iReturnValue As Integer = IsInt(textBox1.Text)

        If iReturnValue = 0 Then
            label1.Text = "int 형 변환으로 실패..."
            Return
        End If

        label1.Text = "int 형 변환 성공..."

    End Sub

    Private Sub button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button2.Click
        'Double 형으로 변환
        Dim dbReturnValue As Double = IsDouble(textBox1.Text)

        If dbReturnValue = 0 Then
            label1.Text = "Double 형 변환으로 실패..."
            Return

        End If

        label1.Text = "Double 형 변환 성공..."

    End Sub

    Private Sub button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button3.Click
        'String 값 null 체크 및 빈 값 체크
        If IsNullString(textBox1.Text) Then
            label1.Text = "string 값이 Null 또는 빈 값입니다..."
            Return
        End If

        label1.Text = "string 값이 정상적입니다..."

    End Sub

    Private Function IsInt(ByVal ob As Object) As Integer

        If ob Is Nothing Then Return 0

        Dim i As Integer
        'int 형 변환
        Dim b As Boolean = Integer.TryParse(ob.ToString(), i)

        If Not b Then Return 0

        Return i

    End Function

    Private Function IsDouble(ByVal ob As Object) As Double

        If ob Is Nothing Then Return 0

        Dim db As Double
        'double 형 변환
        Dim b As Boolean = Double.TryParse(ob.ToString(), db)

        If Not b Then Return 0

        Return db

    End Function

    Private Function IsNullString(ByVal strTmp As String) As Boolean
        Return String.IsNullOrEmpty(strTmp)
    End Function

End Class

위 그림과 같이 int.TryParse 사용으로 오류없이 자연스럽게 형 변환 하는 모습입니다.

물론 Convert.ToInt32 () 로 가능 하며, int.Parse 로도 가능 하지만 예기치 못한 string 값에

 

숫자가 아닌 다른 문자열이 들어 가게 된다면... try~ catch~ 문이 없다면 오류를 내면서 프로그램

이 비정상적으로 종료 되는 걸 볼 수 있습니다.

 

 

int 형으로 변환 실패 된 그림 예 입니다. 만약 int.Parse 와 Convert.ToInt32 로 변환 하였다면

아래의 그림과 같이 오류 메시지가 뜨게 됩니다.

 

Double 형 변환 또한 int 형 변환 설명 드렸듯이 같습니다. 

형 변환 성공
형 변환 실패

마지막으로 string.IsNullOrEmpty() 함수로 string 문자열이 빈 값 인지 또는 null 값 인지 체크 하는 예 입니다.

 




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

 

[C#] string 을 int 및 double 형으로 변환 하기, null 체크

* string 문자열을 정수 및 실수 형으로 변환 하기 예제... 전체 소스코드 Form1.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing;..

kdsoft-zeros.tistory.com

 

반응형
반응형

* VBNET 응용 프로그램 재시작 예제...

 

메인 화면

전체 소스 코드

Form1.vb

 

Imports System.Runtime.InteropServices

Public Class Form1

#Region "INI File...관련"
    <DllImport("kernel32.dll", SetLastError:=True)> _
    Private Shared Function GetPrivateProfileString(ByVal lpAppName As String, _
                                ByVal lpKeyName As String, _
                                ByVal lpDefault As String, _
                                ByVal lpReturnedString As System.Text.StringBuilder, _
                                ByVal nSize As Integer, _
                                ByVal lpFileName As String) As Integer
    End Function

    <DllImport("kernel32.dll", SetLastError:=True)> _
    Private Shared Function WritePrivateProfileString(ByVal lpAppName As String, _
                            ByVal lpKeyName As String, _
                            ByVal lpString As String, _
                            ByVal lpFileName As String) As Boolean
    End Function

    Public Shared Function SetINI(ByVal strAppName As String, _
                           ByVal strKey As String, _
                           ByVal strValue As String, _
                           ByVal strFilePath As String) As Boolean
        SetINI = WritePrivateProfileString(strAppName, strKey, strValue, strFilePath)
    End Function
    Public Shared Function GetINI(ByVal strAppName As String, _
                           ByVal strKey As String, _
                           ByVal strValue As String, _
                           ByVal strFilePath As String) As String
        Dim strbTmp As System.Text.StringBuilder = New System.Text.StringBuilder(255)

        GetPrivateProfileString(strAppName, strKey, strValue, strbTmp, strbTmp.Capacity, strFilePath)

        GetINI = strbTmp.ToString()

    End Function

    Public Shared Function Create_INIFile(ByVal strPath As String, _
                                   ByVal strFileName As String) As Boolean
        '해당 파일이 있으면 그냥 나가기...
        ' System.IO.File.Exists(strPath + "\" + strFileName) 요렇게 해도 됨.
        If Dir(strPath & "\" & strFileName) <> "" Then
            Exit Function
        End If

        '해당 폴더가 없다면 만들기...
        If Not System.IO.Directory.Exists(strPath) Then
            System.IO.Directory.CreateDirectory(strPath)
        End If

        Try
            Using sw As System.IO.StreamWriter = New System.IO.StreamWriter(strPath & "\" & strFileName, False)
                sw.WriteLine(vbCrLf)
                sw.Flush()
                sw.Close()
            End Using
        Catch ex As Exception

            Return False
        End Try

        Return True
    End Function

#End Region

    Dim strINIPath As String = Application.ExecutablePath.Substring(0, Application.ExecutablePath.LastIndexOf("\")) + "\INI"
    Dim iCount As Integer = 0

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Create_INIFile(strINIPath, "ReStart.ini")

        label2.Text = GetINI("Restart_Info", "restart", "0", strINIPath + "\ReStart.ini")
        iCount = Convert.ToInt32(label2.Text)

    End Sub

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
        '다시 시작 하기...
        iCount += 1
        SetINI("Restart_Info", "restart", iCount.ToString(), strINIPath + "\ReStart.ini")

        '프로그램 종료
        Application.Exit()

        '1초 뒤에...
        System.Threading.Thread.Sleep(1000)

        '1번째 방법...
        'Application.Restart()
        '2번째 방법...
        System.Diagnostics.Process.Start(Application.ExecutablePath)
    End Sub


End Class

 

 

* 예제 결과

 

 

 

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

 

[VBNET] INIFile Create & Read & Write Example

* INI 파일 예제 Form1.vb Imports System.Runtime.InteropServices Imports System.IO Imports System.Text Public Class Form1 '빌드되는 폴더 경로 가져오기... Dim strCheckFolder As String = Application.E..

kdsoft-zeros.tistory.com

 

 

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

 

[C#] 응용 프로그램 재시작 예제

* C# 프로그램 재시작 예제... 전체 소스 코드 Form1.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using S..

kdsoft-zeros.tistory.com

 

반응형
반응형

* VBNET 다른 응용 프로그램 실행 및 종료 예제...

 

메인 화면

전체 소스 코드

Form1.vb

 

Public Class Form1

    Dim pcEXE As System.Diagnostics.Process


    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
        '파일 열기...
        Dim ofd As OpenFileDialog = New OpenFileDialog()

        'EXE 파일만 열기...
        ofd.Filter = "EXE File (*.exe) | *.exe"

        If (ofd.ShowDialog() = Windows.Forms.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
        '응용 프로그램 실행 시키기...
        '해당 파일이 존재 하지 않으면...
        If Not System.IO.File.Exists(label1.Text) Then
            Return
        End If

        '다른 응용 프로그램 실행 시키기...
        pcEXE = System.Diagnostics.Process.Start(label1.Text)

    End Sub

    Private Sub button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button3.Click
        '응용 프로그램 죽이기...
        If pcEXE Is Nothing Then Return
        '죽이기...
        pcEXE.Kill()
    End Sub

End Class

 

* 예제 결과

 

다른 응용 프로그램 실행 결과 화면

 

 

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

 

[C#] 다른 응용 프로그램 실행 및 종료

* C# 다른 응용 프로그램 실행 및 종료 예제... 전체 소스 코드 Form1.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using Syst..

kdsoft-zeros.tistory.com

 

반응형

+ Recent posts