473,320 Members | 1,839 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

MouseClick event

Hi there.

I am trying to make a certain symbol to appear upon every mouseclick. However, the symbol is a cross and an arrow head. This is how I tried to do it.


Expand|Select|Wrap|Line Numbers
  1. Private Sub Form1_Paint(ByVal sender As Object, ByVal e As _
  2.      System.Windows.Forms.PaintEventArgs) Handles _
  3.      MyBase.Paint
  4.  
  5.         Dim bluePen As New Pen(Color.Blue, 1.5)
  6.         Dim G As Graphics = e.Graphics
  7.  
  8.         For Each p As Point In mypts
  9.             G.DrawLine(bluePen, (p.X - 5), (p.Y - 5), (p.X + 5), (p.Y+ 5))
  10.             G.DrawLine(bluePen, (p.X + 5), (p.Y - 5), (p.X - 5), (p.Y + 5))
  11.             Dim end_path As New Drawing2D.GraphicsPath
  12.             end_path.AddLine(0, 0, -4, -4)
  13.             end_path.AddLine(0, 0, 4, -4)
  14.             Dim end_cap As New Drawing2D.CustomLineCap(Nothing, end_path)
  15.             bluePen.CustomEndCap = end_cap
  16.             G.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
  17.             G.DrawLine(bluePen, (p.X - 4), p.Y, (p.X - 12), (p.Y + 7))
  18.             end_path.Dispose()
  19.             end_cap.Dispose()
  20.         Next
  21.     End Sub
  22.  
  23.     Private Sub Form1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
  24.         Me.mypts.Add(New Point(e.X, e.Y))
  25.         Me.Invalidate()
  26.     End Sub
However, the problem is, even the lines not suppose to have the arrow heads are having the end cap after the second click onwards. Advice please.

Thanks.
Oct 2 '07 #1
6 1901
Plater
7,872 Expert 4TB
You never reset the customendcap on the bluepen object.
Oct 2 '07 #2
You never reset the customendcap on the bluepen object.
how do i reset the customendcap? i thought the .dispose would do it, wouldnt it?
Oct 4 '07 #3
Plater
7,872 Expert 4TB
You dispose the one you created, but not the one you assigned to the pen
Oct 4 '07 #4
But I thought the one I created is the one I assigned to the pen. i do not understand . Because bluePen.CustomEndCap.Dispose() is the same as end_cap.dispose(), right?
Oct 5 '07 #5
Plater
7,872 Expert 4TB
Because bluePen.CustomEndCap.Dispose() is the same as end_cap.dispose(), right?
"sometimes" But not in this situation. In this situtation you are creating a copy of that object when you assign it to the pen. You will probably need to assign the pen a default endcap of some sort (and not just dispose() of it)
Oct 5 '07 #6
Thank you very much Plater. It works! I declared a different pen, specially assigned to endcap. It works. thanks again . =)
Oct 17 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Hans | last post by:
Hi! In my windowsformapplication I have a DataGrid where the rowheader is not visible, and readOnly = true. The grid is bound to a DataView where AllowEdit, AllowNew and AllowDelete is set to...
3
by: zoneal | last post by:
I have a little question. How can I make that when I click on Button1 that my cursor go to ex. 10,750 and if the position of my cursor is 10,750, than let my mouse click. I know how I got let the...
4
by: Peter Rilling | last post by:
What is the difference between the MouseClick and Click events?
4
by: Chris Dunaway | last post by:
I added a MouseClick event to a Button control. It responds properly to the Left click of the button, but not a middle click or right click. Is it possible to get a right click and/or middle...
6
by: Kristian Frost | last post by:
Hi, I'm trying to add, as you might guess, mouseclick listeners to the shapes I am drawing using the GDI+ commands in a similar sort of way as could be done with the old VB "shapes". Problem is,...
1
by: JimBob | last post by:
Ok so i added this line of code to a dynamic PictureBox. (i dim it p) AddHandler p.MouseClick, AddressOf Hand.Canvas_Click what it would do is change the pic on the picbox but every time you click...
2
by: GS | last post by:
how can I tell if it is right mouse click from left mouseclick? I would also to test if a key like control is being held down at the same time. what I would really like to is to capture control...
7
by: daveyand | last post by:
Is there a way in javascript to trigger the clicking of the left mouse button. Basically i have a floating div that is translucent (40% opacity) this div covers the whole screen. when a user...
4
by: tbrown | last post by:
I have a listbox on my form and I set it to invisible. When a particular button on the form is pressed, I make the listbox visible and allow the user to select from it. When the selection occurs,...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.