Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. rectangle in picture box

rectangle in picture box

Scheduled Pinned Locked Moved Visual Basic
graphics
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    flamingo2
    wrote on last edited by
    #1

    am trying to draw rectangle but it is drawn just with a single click (with different lengths and widths) also it is going out of pictureBox area But i want it to start from where mouse key is pressed and end where mouse key is released. i think there is something wrong with my quardinate. Waiting for reply. Thanks [code] Dim x1, y1, x2, y2 As Integer Dim MD, MU As Point Dim mywidth As Integer Dim drawtool As String Dim drawpen As Pen Dim g As Graphics Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown MD = e.Location x1 = MD.X y1 = MD.Y End Sub Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp If e.Button = Windows.Forms.MouseButtons.Left Then MU = e.Location x2 = MD.X y2 = MD.Y DrawRectangle() End Sub Public Sub DrawRectangle() gr = PictureBox1.CreateGraphics Dim solidColorBrush As SolidBrush = New SolidBrush(Color.Red) Dim coloredPen As Pen = New Pen(solidColorBrush) coloredPen.Width = 3 coloredPen.Color = Color.Blue Dim drawArea2 As Rectangle = New Rectangle(x1, y1, x2, y2) gr.DrawRectangle(coloredPen, drawArea2) gr.Dispose() End Sub [End code]

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups