Results 1 to 8 of 8

Thread: Error: Value of type 'Integer' cannot be converted to

  1. #1

    Thread Starter
    Banned
    Join Date
    Oct 2009
    Posts
    315

    Error: Value of type 'Integer' cannot be converted to

    Hi guys,

    I have a problem, I cannot converted the value of Integer type, which it cannot converted to 'System.Drawing.Point' and 'System.Windows.Forms.Control'.



    Both errors is highlighting on this statement

    Code:
    Form1.ContextMenu1.Show(Form1.MousePosition.X, MousePosition.Y)

    Error I have received which the errors is highlighting on MousePosition.X and MousePosition.Y statement:
    Value of type 'Integer' cannot be converted to 'System.Drawing.Point'
    Value of type 'Integer' cannot be converted to 'System.Windows.Forms.Control'.




    Class library code:

    Code:
    Public Class NoRightClickFlashControl
        Inherits AxShockwaveFlashObjects.AxShockwaveFlash
        Private Const WM_RBUTTONDOWN As Integer = &H204
    
        Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
            Select Case m.Msg
                Case WM_RBUTTONDOWN
                    Form1.ContextMenu1.Show(Form1.MousePosition.X, MousePosition.Y)
                    m.Result = New IntPtr(1)
                    Return
            End Select
            MyBase.WndProc(m)
        End Sub
    End Class

    Form1 code:

    Code:
    Public Class Form1
        Friend WithEvents ContextMenuStrip1 As System.Windows.Forms.ContextMenuStrip = New ContextMenuStrip
        Friend WithEvents PlayToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem = New ToolStripMenuItem
        Friend WithEvents StopToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem = New ToolStripMenuItem
        Friend WithEvents ForwardToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem = New ToolStripMenuItem
        Friend WithEvents ReverseToolStripMenuItem As System.Windows.Forms.ToolStripMenuItem = New ToolStripMenuItem
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        End Sub
    End Class








    Please can you help me to solution the errors I have received on form1.contextmenu1.show statement??


    Thanks,
    Mark

  2. #2
    Hyperactive Member Philly0494's Avatar
    Join Date
    Apr 2008
    Posts
    485

    Re: Error: Value of type 'Integer' cannot be converted to

    New Point (x,y)

    instead of putting in just the integers x,y

  3. #3
    Fanatic Member
    Join Date
    Aug 2009
    Posts
    540

    Re: Error: Value of type 'Integer' cannot be converted to

    Code:
    Form1.ContextMenu1.Show(Form1.MousePosition.X, MousePosition.Y)
    Well the y position needs a form1 in front of it as well.

    I ran a quick test and I don't know why this isn't working for you, here's what i did.

    1.) Created a context menu in the designer, threw some menu items in there, and named it cmnu
    2.) generated a code stub for the forms click event
    3.) placed the code below in the click event

    vb Code:
    1. cmnu.Show(frmTrends.MousePosition.X, frmTrends.MousePosition.Y

    context menu popped up underneath my mouse every time.
    Where I'm from we only have one bit of advice for new comers: "If you hear banjos, turn and run".


    VS 2008 .NetFW 2.0

  4. #4

    Thread Starter
    Banned
    Join Date
    Oct 2009
    Posts
    315

    Re: Error: Value of type 'Integer' cannot be converted to

    Quote Originally Posted by BackWoodsCoder View Post
    Code:
    Form1.ContextMenu1.Show(Form1.MousePosition.X, MousePosition.Y)
    Well the y position needs a form1 in front of it as well.

    I ran a quick test and I don't know why this isn't working for you, here's what i did.

    1.) Created a context menu in the designer, threw some menu items in there, and named it cmnu
    2.) generated a code stub for the forms click event
    3.) placed the code below in the click event

    vb Code:
    1. cmnu.Show(frmTrends.MousePosition.X, frmTrends.MousePosition.Y

    context menu popped up underneath my mouse every time.

    Thanks, I have tried but it doesn't work for me. I still get the same errors.


    Any idea??

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Error: Value of type 'Integer' cannot be converted to

    @BWC: How did you get that to work? You are passing a pair of integers or doubles to a method that has only two overloads. The first one takes a control and a point as arguments, while the second takes a control, a point, and an alignment. What you did shouldn't have worked.

    From what I can see in the documentation, you two appear to be talking about two entirely different things, but I can't figure out what either one is talking about. I haven't worked with a context menu, but the second argument to Show is a point relative to the control that is passed as the first argument. Therefore, the call might be:

    cmnu.Show(<some control>,New Point(frmTrends.MousePosition.X, frmTrends.MousePosition.Y ))

    However, translating the X and Y from a form into a control context seems a little iffy. Furthermore, what would the control be? What is the context menu being shown for? That should be the control that should be passed in. I suspect that the mouseposition values will not be correct for the point, but they are worth a try, at least.
    My usual boring signature: Nothing

  6. #6

    Thread Starter
    Banned
    Join Date
    Oct 2009
    Posts
    315

    Re: Error: Value of type 'Integer' cannot be converted to

    It still doesn't work. Please can someone help me??

  7. #7
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: Error: Value of type 'Integer' cannot be converted to

    Read the documentation of the relevant Show method. Look closely at the types of the arguments it expects. Your values (two integers) don't match those types.

    You can't call a function and pass it the value you think it needs and always expect it to work. Functions/methods expect specific arguments, in a specific order. Sometimes, the programmer has made some extra effort to allow for multiple overloads of a method which basically do the same thing, but you need to look at the type of each argument and check if the argument you are trying to pass matches that.

    For example, a method that expects a Point structure may actually have two overloads, one taking a Point structure, and the other the x- and y-values separately.
    Code:
    Public Sub SomeMethod(ByVal x As Integer, ByVal y As Integer)
       SomeMethod(New Point(x, y))
    End Sub
    
    Public Sub SomeMethod(ByVal pt As Point)
       'do something with point here
    End Sub
    Alternatively, it could be done the other way around, with the second SomeMethod calling the first SomeMethod and specifying the points X and Y properties separately.

    Now, you can call this method in two ways: by passing a Point and by passing two integers. Visual studio knows which method you want to run by simply looking at the types and order of the arguments. If two integers are passed, it runs the first method, and if a single Point is passed, it runs the second. If something completely different is passed, then you can't compile it, because it doesn't know what to do with the arguments.

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Error: Value of type 'Integer' cannot be converted to

    Quote Originally Posted by mark108 View Post
    It still doesn't work. Please can someone help me??
    Do you mean that what I posted doesn't work? How about showing us how you implemented it. After all, I don't know what control the context menu is supposed to relate to, so I'd need to see what you put in place of that.
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width