Programlama yapalım ve Öğrenelim. - Örnek kodlar2
  Ana Sayfa
  .NET Eğitim Notları
  Visual C# .NET Örnek Kodları
  VisualBasic.NET Örnek Kodları
  => Örnek kodlar
  => Örnek kodlar2
  J# Örnekleri
  ASP.NET Örnek Kodları
  Delphi Eğitim
  İletişim

Checkbox ve font kullanımı:

Imports System

Imports System.Drawing

Imports System.Windows.Forms

 

 

 

Public Class Form1

    Inherits System.Windows.Forms.Form

 

    Friend WithEvents chkItalic As System.Windows.Forms.CheckBox

    Friend WithEvents lblOutput As System.Windows.Forms.Label

    Friend WithEvents chkBold As System.Windows.Forms.CheckBox

 

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

 

 

        Me.lblOutput = New System.Windows.Forms.Label()

        Me.chkItalic = New System.Windows.Forms.CheckBox()

        Me.chkBold = New System.Windows.Forms.CheckBox()

        Me.SuspendLayout()

        '

        'lblOutput

        '

        Me.lblOutput.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))

        Me.lblOutput.Location = New System.Drawing.Point(48, 24)

        Me.lblOutput.Name = "lblOutput"

        Me.lblOutput.Size = New System.Drawing.Size(208, 24)

        Me.lblOutput.TabIndex = 0

        Me.lblOutput.Text = "Watch the font style change"

        '

        'chkItalic

        '

        Me.chkItalic.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))

        Me.chkItalic.Location = New System.Drawing.Point(152, 64)

        Me.chkItalic.Name = "chkItalic"

        Me.chkItalic.Size = New System.Drawing.Size(64, 24)

        Me.chkItalic.TabIndex = 2

        Me.chkItalic.Text = "Italic"

        '

        'chkBold

        '

        Me.chkBold.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))

        Me.chkBold.Location = New System.Drawing.Point(80, 64)

        Me.chkBold.Name = "chkBold"

        Me.chkBold.Size = New System.Drawing.Size(56, 24)

        Me.chkBold.TabIndex = 1

        Me.chkBold.Text = "Bold"

        '

        'FrmCheckBox

        '

        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)

        Me.ClientSize = New System.Drawing.Size(292, 117)

        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.chkItalic, Me.chkBold, Me.lblOutput})

        Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))

        Me.Name = "FrmCheckBox"

        Me.Text = "CheckBoxTest"

        Me.ResumeLayout(False)

 

    End Sub

 

 

 

    ' use Xor to toggle italic, keep other styles same

    Private Sub chkItalic_CheckedChanged _

       (ByVal sender As System.Object, ByVal e As System.EventArgs) _

       Handles chkItalic.CheckedChanged

 

        lblOutput.Font = New Font(lblOutput.Font.Name, _

           lblOutput.Font.Size, lblOutput.Font.Style _

           Xor FontStyle.Italic)

    End Sub ' chkItalic_CheckedChanged

 

    ' use Xor to toggle bold, keep other styles same

    Private Sub chkBold_CheckedChanged _

       (ByVal sender As System.Object, ByVal e As System.EventArgs) _

       Handles chkBold.CheckedChanged

 

        lblOutput.Font = New Font(lblOutput.Font.Name, _

           lblOutput.Font.Size, lblOutput.Font.Style _

           Xor FontStyle.Bold)

    End Sub

 

 

End Class

Drawbutton örneği:

Imports System

Imports System.Drawing

Imports System.Windows.Forms

 

 

 

Public Class OwnerDrawnButton

    Inherits System.Windows.Forms.Form

 

    Friend WithEvents button4 As System.Windows.Forms.Button

    Private Sub OwnerDrawnButton_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

 

 

        Me.button4 = New System.Windows.Forms.Button()

        Me.SuspendLayout()

        '

        'button4

        '

        Me.button4.Location = New System.Drawing.Point(16, 23)

        Me.button4.Name = "button4"

        Me.button4.Size = New System.Drawing.Size(200, 40)

        Me.button4.TabIndex = 2

        Me.button4.Text = "button4"

        '

        'OwnerDrawnButton

        '

        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

        Me.ClientSize = New System.Drawing.Size(232, 86)

        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.button4})

        Me.Name = "OwnerDrawnButton"

        Me.Text = "OwnerDrawnButton"

        Me.ResumeLayout(False)

 

    End Sub

 

 

 

    Private Sub button4_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles button4.Paint

        Dim _pen As Pen = New Pen(Color.Red, 2)

        e.Graphics.DrawRectangle(_pen, 5, 5, button4.Width - 10, button4.Height - 10)

 

    End Sub

 

 

End Class

Owner draw statusbar:

Imports System

Imports System.Drawing

Imports System.Windows.Forms

 

 

 

Public Class OwnerDrawnStatusBar

    Inherits System.Windows.Forms.Form

 

 

    Friend WithEvents statusBar1 As System.Windows.Forms.StatusBar

    Friend WithEvents statusBarPanel1 As System.Windows.Forms.StatusBarPanel

    Friend WithEvents statusBarPanel2 As System.Windows.Forms.StatusBarPanel

    Private Sub OwnerDrawnStatusBar_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

 

 

        Me.statusBar1 = New System.Windows.Forms.StatusBar()

        Me.statusBarPanel1 = New System.Windows.Forms.StatusBarPanel()

        Me.statusBarPanel2 = New System.Windows.Forms.StatusBarPanel()

        CType(Me.statusBarPanel1, System.ComponentModel.ISupportInitialize).BeginInit()

        CType(Me.statusBarPanel2, System.ComponentModel.ISupportInitialize).BeginInit()

        Me.SuspendLayout()

        '

        'statusBar1

        '

        Me.statusBar1.Location = New System.Drawing.Point(0, 62)

        Me.statusBar1.Name = "statusBar1"

        Me.statusBar1.Panels.AddRange(New System.Windows.Forms.StatusBarPanel() {Me.statusBarPanel1, Me.statusBarPanel2})

        Me.statusBar1.ShowPanels = True

        Me.statusBar1.Size = New System.Drawing.Size(360, 32)

        Me.statusBar1.TabIndex = 4

        Me.statusBar1.Text = "statusBar1"

        '

        'statusBarPanel1

        '

        Me.statusBarPanel1.Text = "Next Panel is OwnerDrawn -->"

        Me.statusBarPanel1.Width = 190

        '

        'statusBarPanel2

        '

        Me.statusBarPanel2.Style = System.Windows.Forms.StatusBarPanelStyle.OwnerDraw

        Me.statusBarPanel2.Text = "statusBarPanel2"

        Me.statusBarPanel2.Width = 113

        '

        'OwnerDrawnStatusBar

        '

        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

        Me.ClientSize = New System.Drawing.Size(360, 94)

        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.statusBar1})

        Me.Name = "OwnerDrawnStatusBar"

        Me.Text = "OwnerDrawnStatusBar"

        CType(Me.statusBarPanel1, System.ComponentModel.ISupportInitialize).EndInit()

        CType(Me.statusBarPanel2, System.ComponentModel.ISupportInitialize).EndInit()

        Me.ResumeLayout(False)

 

    End Sub

 

 

 

    Private Sub statusBar1_DrawItem(ByVal sender As Object, ByVal sbdevent As System.Windows.Forms.StatusBarDrawItemEventArgs) Handles statusBar1.DrawItem

        Dim b As Brush = New SolidBrush(sbdevent.ForeColor)

        Dim format As StringFormat = New StringFormat()

        format.LineAlignment = StringAlignment.Center

        format.Alignment = StringAlignment.Center

 

        sbdevent.Graphics.DrawRectangle(New Pen(sbdevent.BackColor), sbdevent.Bounds)

 

        ControlPaint.DrawButton(sbdevent.Graphics, _

            sbdevent.Bounds.Left + 5, _

            sbdevent.Bounds.Top + 5, _

            sbdevent.Bounds.Width - 10, _

            sbdevent.Bounds.Height - 10, _

            ButtonState.Normal)

 

        b.Dispose()

 

    End Sub

 

 

End Class

 

Aç kayder diyaloğu:

Imports System

Imports System.Data

Imports System.Windows.Forms

Imports System.Drawing

Imports System.Diagnostics

Imports System.Drawing.Printing

Imports System.ComponentModel

 

 

Public Class MainClass

    Shared WithEvents dlgSaveData As System.Windows.Forms.SaveFileDialog

 

    Shared Sub Main()

        dlgSaveData = New System.Windows.Forms.SaveFileDialog

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

            MessageBox.Show(dlgSaveData.FileName)

        End If

    End Sub

 

    Private Shared Sub dlgSaveData_FileOk(ByVal sender As Object, _

     ByVal e As System.ComponentModel.CancelEventArgs) Handles dlgSaveData.FileOk

 

 

        If Not dlgSaveData.FileName.EndsWith(".dat") Then

            MsgBox("File " & dlgSaveData.FileName & _

                " is not a .dat file", _

                MsgBoxStyle.Exclamation, _

                "Invalid File Type")

            e.Cancel = True

        End If

    End Sub

End Class

Save Diyaloğu-Filtrele ve kaydet:

Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Imports System.Configuration
Imports System.Resources
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.IO
Imports System.Drawing.Printing


Public Class MainClass
    Shared Sub Main()
        'Declare a SaveFileDialog object
        Dim objSaveFileDialog As New SaveFileDialog

        'Set the Save dialog properties
        With objSaveFileDialog
            .DefaultExt = "txt"
            .FileName = "Test Document"
            .Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
            .FilterIndex = 1
            .OverwritePrompt = True
            .Title = "Demo Save File Dialog"
        End With

        'Show the Save dialog and if the user clicks the Save button,
        'save the file
        If objSaveFileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
            Try
                Dim filePath As String
                'Open or Create the file
                filePath = System.IO.Path.Combine( _
                    My.Computer.FileSystem.SpecialDirectories.MyDocuments, _
                    objSaveFileDialog.FileName)
                'Replace the contents of the file
                My.Computer.FileSystem.WriteAllText(filePath, "C:a.txt", False)
            Catch fileException As Exception
                Throw fileException
            End Try
        End If

        'Clean up
        objSaveFileDialog.Dispose()
        objSaveFileDialog = Nothing
    End Sub

End Class


 
Bu web sitesi ücretsiz olarak Bedava-Sitem.com ile oluşturulmuştur. Siz de kendi web sitenizi kurmak ister misiniz?
Ücretsiz kaydol