نمایش نتایج 1 تا 40 از 105

نام تاپیک: نکات، ایده ها و ترفندهای کوچک برنامه نویسی در vb.net

Hybrid View

پست قبلی پست قبلی   پست بعدی پست بعدی
  1. #1
    کاربر دائمی
    تاریخ عضویت
    آبان 1385
    محل زندگی
    مشهد
    سن
    40
    پست
    449

    پرینت با استفاده از PrintDocument

    این کد از کتاب کوروش مقدسی با یکم دخل و تصرف عملیات پرینت رو انجام میده و نیازی هم به افزودن کنترل به فرم نیست و کافیه فقط کد رو کپی کنید :



    PublicClass Form1
    Inherits Windows.Forms.Form
    FriendWithEvents PrintDocument1 AsNew System.Drawing.Printing.PrintDocument
    FriendWithEvents TextBox1 AsNew System.Windows.Forms.TextBox
    FriendWithEvents Button1 AsNew Windows.Forms.Button
    PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    PrintDocument1.Print()
    EndSub
    PrivateSub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
    e.Graphics.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
    Dim pfont AsNew Font("Arial", 20)
    e.Graphics.DrawString(TextBox1.Text, pfont, Brushes.AliceBlue, 0, 0)
    Dim lmargin, Rmargin, Tmargin, Bmargin AsInteger
    With PrintDocument1.DefaultPageSettings.Margins
    lmargin = .Left
    Rmargin = .Right
    Tmargin = .Top
    Bmargin = .Bottom
    EndWith
    Dim printWidth, PrintHeight AsInteger
    With PrintDocument1.DefaultPageSettings.PaperSize
    printWidth = .Width - lmargin - Rmargin
    PrintHeight = .Height - Tmargin - Bmargin
    EndWith
    Dim r As Rectangle
    r =
    New Rectangle(lmargin, Tmargin, printWidth, PrintHeight)
    e.Graphics.DrawRectangle(Pens.Black, r)
    EndSub
    PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
    TextBox1.Left = 0
    TextBox1.Width =
    Me.Width
    TextBox1.Top = 0
    Button1.Top = TextBox1.Top + TextBox1.Height + 10
    Button1.Left = 0
    Button1.Width =
    Me.Width
    Button1.Text =
    "پ©یë¢"
    Me.Controls.Add(Button1)
    Me.Controls.Add(TextBox1)
    EndSub
    End
    Class


  2. #2
    کاربر دائمی
    تاریخ عضویت
    آبان 1385
    محل زندگی
    مشهد
    سن
    40
    پست
    449

    پرینت فرم

    با این کد میتونید یک فرم رو مستقیما به پرینتر بفرستید تو 2008 کار میکنه ولی تو 2005 یا 2003 رو تست نکردم



    Public
    Class Form1
    FriendWithEvents TXTBox1 AsNew TextBox
    FriendWithEvents PrintForm1 As Microsoft.VisualBasic.PowerPacks.Printing.PrintFor m
    FriendWithEvents BTN AsNew Button
    PrivateSub btn_Click(ByVal a AsObject, ByVal b As System.EventArgs) Handles BTN.Click
    PrintForm1.Print()
    EndSub


    PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
    Me.PrintForm1 = New Microsoft.VisualBasic.PowerPacks.Printing.PrintFor m(Me.components)
    Me.PrintForm1.DocumentName = "document"


    Me.PrintForm1.Form = Me


    Me.PrintForm1.PrintAction = System.Drawing.Printing.PrintAction.PrintToPrinter
    Me.PrintForm1.PrintFileName = Nothing


    'Design New Text Box To Form


    TXTBox1.Multiline =
    True


    TXTBox1.Left = 10
    TXTBox1.Top = 10
    TXTBox1.Height =
    Me.Height - 20
    TXTBox1.Width =
    Me.Width - 20
    TXTBox1.Text =
    "This is Sample Code For Test Print Form " & vbCrLf & "Designer : -_- MHM (Ict_Boy_2005@yahoo.com)" & _
    vbCrLf &
    "Publisher WWW.BarnameNevis.ORG"


    Me.Controls.Add(TXTBox1)
    'Design new Button to form


    Me.Height += 100
    BTN.Left = 0
    BTN.Width =
    Me.Width
    BTN.Top = TXTBox1.Top + TXTBox1.Height
    Me.Controls.Add(BTN)
    BTN.Height = 100
    BTN.Text =
    "Do Print"


    EndSub
    End
    Class




  3. #3
    کاربر دائمی آواتار ghafoori
    تاریخ عضویت
    مرداد 1384
    محل زندگی
    اصفهان-نجف اباد
    پست
    1,111

    Smile افزودن کنترل در زمان اجرا

    https://barnamenevis.org/showpo...2&postcount=47


    مثال: یک تکست باکس به فرم اضافه میکند:
    کد:

    Dim myText As TextBox = New TextBox()
    myText.Location = New Point(25, 25)
    Me.Controls.Add(myText)

  4. #4
    کاربر دائمی آواتار ghafoori
    تاریخ عضویت
    مرداد 1384
    محل زندگی
    اصفهان-نجف اباد
    پست
    1,111

    Smile یافتن MAC آدرس کارت شبکه

    https://barnamenevis.org/showpo...3&postcount=49


    ابتدا System.Management رو به References پروژه بیفزایید و سپس :
    کد:


    Imports System.Management

    Private Sub GetMACAddress()

    Dim searcher As ManagementObjectSearcher
    Dim qry As String = "select * FROM Win32_NetworkAdapter"
    searcher = New ManagementObjectSearcher(qry)
    For Each wmi_HD As ManagementObject In searcher.Get()
    If Not wmi_HD("MacAddress") Is Nothing Then
    MessageBox.Show(wmi_HD("MacAddress").ToString())
    End If
    Next
    End Sub


  5. #5
    کاربر دائمی آواتار ghafoori
    تاریخ عضویت
    مرداد 1384
    محل زندگی
    اصفهان-نجف اباد
    پست
    1,111

    Smile نمایش تصاویر در Windows picture and fax viewer از طریق کدنویسی

    https://barnamenevis.org/showpo...0&postcount=50
    کد:


    ' //Open with the 'Windows picture and fax viewer':
    System.Diagnostics.Process.Start("C:\Windows\syste m32\rundll32.exe ", _
    "C:\Windows\system32\shimgvw.dll,ImageView_Fullscr een " + "filename")

    اینهم که آسونه اما شاید واسه دوستانی مفید باشه :
    کد:

    '//Open with the 'Microsoft Paint':
    System.Diagnostics.Process.Start("C:\Windows\syste m32\MSPaint.exe ", " filename")


  6. #6
    کاربر دائمی آواتار ghafoori
    تاریخ عضویت
    مرداد 1384
    محل زندگی
    اصفهان-نجف اباد
    پست
    1,111

    Smile وادار کردن لیست باکس به اسکرول تا یک آیتم مشخص

    https://barnamenevis.org/showpo...3&postcount=51

    مثال - برای آخرین آیتم :
    کد:


    '// Set the TopIndex property of the ListBox to ensure the
    '// most recently added items are visible.
    ListBox1.TopIndex = ListBox1.Items.Count - 1
    ListBox1.SelectedIndex = ListBox1.Items.Count - 1

  7. #7
    کاربر دائمی آواتار ghafoori
    تاریخ عضویت
    مرداد 1384
    محل زندگی
    اصفهان-نجف اباد
    پست
    1,111

    Smile جابجا کردن فرم با کلیک بر روی هر قسمت از آن - بدون استفاده از توابع API

    https://barnamenevis.org/showpo...5&postcount=52


    کد:


    Private dragging As Boolean
    Private pointClicked As Point

    Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
    If (e.Button = MouseButtons.Left) Then

    '// Turn drag mode on and store the point clicked.
    dragging = True
    pointClicked = New Point(e.X, e.Y)
    Else

    dragging = False
    End If
    End Sub

    Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
    If dragging Then

    Dim pointMoveTo As Point
    '// Find the current mouse position in screen coordinates.
    pointMoveTo = Me.PointToScreen(New Point(e.X, e.Y))
    '// Compensate for the position the control was clicked.
    pointMoveTo.Offset(-pointClicked.X, -pointClicked.Y)
    '// Move the form.
    Me.Location = pointMoveTo
    End If
    End Sub

    Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
    dragging = False
    End Sub

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •