How to change type of UserControl to ContextMenuStrip?


How to change System.Windows.Forms.UserControl to System.Windows.Forms.ContextMenuStrip?

Thanks in advance
Who is Participating?
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
A UserControl is not a ContextMenuStrip, and therefore it cannot be cast as so.  This makes no sense...unless you give us more details to explain otherwise.

That would be like trying to cast an Apple to an Orange.  They're both fruit, but it's just not going to work!
Not sure exactly what you mean, but you can convert an object to a contextmenustrip like so...

Dim cms As System.Windows.Forms.ContextMenuStrip = CType(MyUserControl, System.Windows.Forms.ContextMenuStrip)

Open in new window

hc_guptaAuthor Commented:
My user control name is UserControlCMS1 and on using above line i.e.

Dim cms As System.Windows.Forms.ContextMenuStrip = CType(UserControlCMS1, System.Windows.Forms.ContextMenuStrip)

I'm getting an error :

" Value of type UserControlCMS can not be converted to 'System.Windows.ContextMenuStrip' "
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.